23#ifndef SIM_RACING_LIB_H
24#define SIM_RACING_LIB_H
71 DeviceConnection(uint8_t pin,
bool invert =
false,
unsigned long detectTime = 250);
109 bool readPin()
const;
113 unsigned long stablePeriod;
117 unsigned long lastChange;
127 static const int Max = 1023;
228 const uint8_t Pin = NOT_A_PIN;
291 virtual void begin();
388 TwoPedals(uint8_t gasPin, uint8_t brakePin, uint8_t detectPin = NOT_A_PIN);
399 static const uint8_t NumPedals = 2;
417 ThreePedals(uint8_t gasPin, uint8_t brakePin, uint8_t clutchPin, uint8_t detectPin = NOT_A_PIN);
429 static const uint8_t NumPedals = 3;
453 Shifter(int8_t min, int8_t max);
545 AnalogShifter(uint8_t pinX, uint8_t pinY, uint8_t pinRev = NOT_A_PIN, uint8_t detectPin = NOT_A_PIN);
552 virtual void begin();
618 float engagePoint = CalEngagementPoint,
float releasePoint = CalReleasePoint,
float edgeOffset = CalEdgeOffset);
637 static const float CalEngagementPoint;
644 static const float CalReleasePoint;
651 static const float CalEdgeOffset;
665 AnalogInput analogAxis[2];
666 const uint8_t PinReverse;
667 DeviceConnection detector;
684 Handbrake(uint8_t pinAx, uint8_t detectPin = NOT_A_PIN);
689 virtual void begin();
709 long getPosition(
long rMin = 0,
long rMax = 100)
const;
751 LogitechPedals(uint8_t gasPin, uint8_t brakePin, uint8_t clutchPin, uint8_t detectPin = NOT_A_PIN);
778 LogitechShifter(uint8_t pinX, uint8_t pinY, uint8_t pinRev = NOT_A_PIN, uint8_t detectPin = NOT_A_PIN);
782#if defined(__AVR_ATmega32U4__) || defined(SIM_RACING_DOXYGEN)
799 #define SHIFTER_SHIELD_V1_PINS A1, A0, 14, A2
817 #define PEDAL_SHIELD_V1_PINS A2, A1, A0, 10
Axis
Enumeration for analog axis names, mapped to integers.
Interface with shifters using two potentiometers for gear position.
void setCalibration(GearPosition neutral, GearPosition g1, GearPosition g2, GearPosition g3, GearPosition g4, GearPosition g5, GearPosition g6, float engagePoint=CalEngagementPoint, float releasePoint=CalReleasePoint, float edgeOffset=CalEdgeOffset)
Calibrate the gear shifter for more accurate shifting.
void serialCalibration(Stream &iface=Serial)
Runs an interactive calibration tool using the serial interface.
bool getReverseButton() const
Checks the current state of the "reverse" button at the bottom of the shift column.
int getPositionRaw(Axis ax) const
Retrieves the buffered position for the analog axis.
virtual bool update()
Polls the hardware to update the current gear state.
bool isConnected() const
Check if the device is physically connected to the board.
virtual void begin()
Initializes the hardware pins for reading the gear states.
long getPosition(Axis ax, long rMin=AnalogInput::Min, long rMax=AnalogInput::Max) const
Retrieves the buffered position for the analog axis, rescaled to a nominal range using the calibratio...
Used for tracking whether a device is connected to a specific pin and stable.
void poll()
Checks if the pin detects a connection.
void setStablePeriod(unsigned long t)
Allows the user to change the stable period of the detector.
ConnectionState getState() const
Retrieves the current ConnectionState from the instance.
ConnectionState
The state of the connection, whether it is connected, disconnected, and everywhere in-between.
@ Unplug
Device was just removed (connection ends)
@ PlugIn
Device was just plugged in (connection starts), unstable.
@ Disconnected
No connection present.
@ Connected
Connection present and stable.
bool isConnected() const
Check if the device is physically connected to the board.
Interface with analog handbrakes that use hall effect sensors.
virtual void begin()
Initializes the pin for reading from the handbrake.
long getPosition(long rMin=0, long rMax=100) const
Retrieves the buffered position for the handbrake axis, rescaled to a nominal range using the calibra...
void setCalibration(AnalogInput::Calibration newCal)
Calibrate the axis' min/max values for rescaling.
int getPositionRaw() const
Retrieves the buffered position for the handbrake, ignoring the calibration data.
bool positionChanged() const
Checks whether the handbrake's position has changed since the last update.
virtual bool update()
Polls the handbrake to update its position.
bool isConnected() const
Check if the device is physically connected to the board.
void serialCalibration(Stream &iface=Serial)
Runs an interactive calibration tool using the serial interface.
Interface with the Logitech Driving Force GT pedals (Gas + Brake)
Interface with the Logitech pedals (Gas, Brake, and Clutch)
Interface with the Logitech Driving Force shifter.
Base class for all pedals instances.
SimRacing::Pedal PedalID
Scoped alias for SimRacing::Pedal.
bool isConnected() const
Check if the device is physically connected to the board.
void serialCalibration(Stream &iface=Serial)
Runs an interactive calibration tool using the serial interface.
void setCalibration(PedalID pedal, AnalogInput::Calibration cal)
Calibrate a pedal's min/max values for rescaling.
static String getPedalName(PedalID pedal)
Utility function to get the string name for each pedal.
bool hasPedal(PedalID pedal) const
Checks if a given pedal is present in the class.
bool positionChanged() const
Checks whether the current pedal positions have changed since the last update.
int getPositionRaw(PedalID pedal) const
Retrieves the buffered position for the pedal, ignoring the calibration data.
virtual bool update()
Perform a poll of the hardware to refresh the class state.
virtual void begin()
Initialize the hardware (if necessary)
long getPosition(PedalID pedal, long rMin=0, long rMax=100) const
Retrieves the buffered position for the pedal, rescaled to a nominal range using the calibration valu...
int getNumPedals() const
Retrieves the number of pedals handled by the class.
Abstract class for all peripherals.
virtual bool isConnected() const
Check if the device is physically connected to the board.
virtual bool update()=0
Perform a poll of the hardware to refresh the class state.
virtual void begin()
Initialize the hardware (if necessary)
Base class for all shifter instances.
String getGearString() const
Returns a String that represents the current gear.
int8_t getGearMin()
Retrieves the minimum possible gear index.
const int8_t MaxGear
the highest selectable gear
int8_t getGear() const
Returns the currently selected gear.
char getGearChar() const
Returns a character that represents the current gear.
int8_t getGearMax()
Retrieves the maximum possible gear index.
bool changed
whether the gear has changed since the previous update
int8_t currentGear
index of the current gear
const int8_t MinGear
the lowest selectable gear
bool gearChanged() const
Checks whether the current gear has changed since the last update.
Pedal implementation for devices with gas, brake, and clutch.
void setCalibration(AnalogInput::Calibration gasCal, AnalogInput::Calibration brakeCal, AnalogInput::Calibration clutchCal)
Sets the calibration data (min/max) for the pedals.
Pedal implementation for devices with only gas and brake.
void setCalibration(AnalogInput::Calibration gasCal, AnalogInput::Calibration brakeCal)
Sets the calibration data (min/max) for the pedals.
Simple struct to store X/Y coordinates for the calibration function.
int y
Y coordinate of the gear position from the ADC.
int x
X coordinate of the gear position from the ADC.