23#ifndef SIM_RACING_LIB_H
24#define SIM_RACING_LIB_H
121 bool readPin()
const;
125 unsigned long stablePeriod;
129 unsigned long lastChange;
139 static const int Max = 1023;
303 virtual void begin();
411 static const uint8_t NumPedals = 2;
441 static const uint8_t NumPedals = 3;
465 Shifter(int8_t min, int8_t max);
564 virtual void begin();
630 float engagePoint = CalEngagementPoint,
float releasePoint = CalReleasePoint,
float edgeOffset = CalEdgeOffset);
649 static const float CalEngagementPoint;
656 static const float CalReleasePoint;
663 static const float CalEdgeOffset;
677 AnalogInput analogAxis[2];
679 DeviceConnection detector;
701 virtual void begin();
721 long getPosition(
long rMin = 0,
long rMax = 100)
const;
794#if defined(__AVR_ATmega32U4__) || defined(SIM_RACING_DOXYGEN)
811 #define SHIFTER_SHIELD_V1_PINS A1, A0, 14, A2
829 #define PEDAL_SHIELD_V1_PINS A2, A1, A0, 10
Axis
Enumeration for analog axis names, mapped to integers.
const PinNum UnusedPin
Dummy pin number signaling that a pin is unused and can be safely ignored.
int16_t PinNum
Type alias for pin numbers, using Arduino numbering.
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.
AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev=UnusedPin, PinNum pinDetect=UnusedPin)
Class constructor.
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.
DeviceConnection(PinNum pin, bool invert=false, unsigned long detectTime=250)
Class constructor.
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.
Handbrake(PinNum pinAx, PinNum pinDetect=UnusedPin)
Class constructor.
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)
LogitechDrivingForceGT_Pedals(PinNum pinGas, PinNum pinBrake, PinNum pinDetect=UnusedPin)
Class constructor.
Interface with the Logitech pedals (Gas, Brake, and Clutch)
LogitechPedals(PinNum pinGas, PinNum pinBrake, PinNum pinClutch, PinNum pinDetect=UnusedPin)
Class constructor.
Interface with the Logitech Driving Force shifter.
LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev=UnusedPin, PinNum pinDetect=UnusedPin)
Class constructor.
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.
Pedals(AnalogInput *dataPtr, uint8_t nPedals, PinNum detectPin)
Class constructor.
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.
Shifter(int8_t min, int8_t max)
Class constructor.
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.
ThreePedals(PinNum pinGas, PinNum pinBrake, PinNum pinClutch, PinNum pinDetect=UnusedPin)
Class constructor.
Pedal implementation for devices with only gas and brake.
TwoPedals(PinNum pinGas, PinNum pinBrake, PinNum pinDetect=UnusedPin)
Class constructor.
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.