23#ifndef SIM_RACING_LIB_H
24#define SIM_RACING_LIB_H
123 bool readPin()
const;
127 unsigned long stablePeriod;
131 unsigned long lastChange;
141 static const int Max = 1023;
352 virtual void begin();
458 static const uint8_t NumPedals = 2;
489 static const uint8_t NumPedals = 3;
573 return this->currentGear != this->previousGear;
642 virtual void begin();
701 float engagePoint = CalEngagementPoint,
float releasePoint = CalReleasePoint,
float edgeOffset = CalEdgeOffset);
725 virtual bool readReverseButton();
732 static const float CalEngagementPoint;
739 static const float CalReleasePoint;
746 static const float CalEdgeOffset;
783 virtual void begin();
796 long getPosition(
long rMin = 0,
long rMax = 100)
const;
984 PinNum pinLed = UnusedPin,
985 PinNum pinDetect = UnusedPin
992 virtual void begin();
1063 static bool extractButton(
Button button, uint16_t data) {
1066 return data & (1 << (uint8_t) button);
1075 void cacheButtons(uint16_t newStates);
1083 void setPinModes(
bool enabled);
1090 uint16_t readShiftRegisters();
1093 virtual bool readReverseButton();
1108 uint16_t buttonStates;
1109 uint16_t previousButtons;
1146 virtual void begin();
1186 float engagePoint = LogitechShifterG25::CalEngagementPoint,
1187 float releasePoint = LogitechShifterG25::CalReleasePoint
1203 static const float CalEngagementPoint;
1210 static const float CalReleasePoint;
1212 bool sequentialProcess;
1213 int8_t sequentialState;
1216 struct SequentialCalibration {
1225#if defined(__AVR_ATmega32U4__) || defined(SIM_RACING_DOXYGEN)
1266 template<
class T, u
int8_t Version>
T CreateShieldObject()
Create an object for use with one of the Sim Racing Shields, designed for the SparkFun Pro Micro (32U...
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.
AnalogShifter(Gear gearMin, Gear gearMax, PinNum pinX, PinNum pinY, PinNum pinRev=UnusedPin)
Class constructor.
int getPositionRaw(Axis ax) const
Retrieves the buffered position for the analog axis.
virtual bool updateState(bool connected)
Perform an internal poll of the hardware to refresh the class state.
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)
Set how long the detection pin must be stable for before the device is considered to be 'connected'.
ConnectionState getState() const
Retrieves the current ConnectionState from the instance.
DeviceConnection(PinNum pin, bool activeLow=false, unsigned long detectTime=250)
Class constructor.
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.
Handbrake(PinNum pinAx)
Class constructor.
virtual bool updateState(bool connected)
Perform an internal poll of the hardware to refresh the class state.
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 G25 shifter.
bool getShiftDown() const
Check if the sequential shifter is shifted down.
LogitechShifterG25(PinNum pinX, PinNum pinY, PinNum pinLatch, PinNum pinClock, PinNum pinData, PinNum pinLed=UnusedPin, PinNum pinDetect=UnusedPin)
Class constructor.
void serialCalibrationSequential(Stream &iface=Serial)
Runs an interactive calibration tool using the serial interface.
virtual bool updateState(bool connected)
Perform an internal poll of the hardware to refresh the class state.
bool getShiftUp() const
Check if the sequential shifter is shifted up.
bool inSequentialMode() const
Check if the shifter is in sequential shifting mode.
void setCalibrationSequential(int neutral, int up, int down, float engagePoint=LogitechShifterG25::CalEngagementPoint, float releasePoint=LogitechShifterG25::CalReleasePoint)
Calibrate the sequential shifter for more accurate shifting.
virtual void begin()
Initializes the hardware pins for reading the gear states and the buttons.
Interface with the Logitech G27 shifter.
int getDpadAngle() const
Get the directional pad angle in degrees.
Button
Enumeration of button values.
@ BUTTON_REVERSE
Reverse button (press down on the shifter)
@ BUTTON_SEQUENTIAL
Sequential mode button (turn the dial counter-clockwise)
@ DPAD_DOWN
Down button of the directional pad.
@ BUTTON_3
3rd red button (mid right)
@ DPAD_RIGHT
Right button of the directional pad.
@ BUTTON_WEST
The left black button.
@ BUTTON_EAST
The right black button.
@ BUTTON_2
2nd red button (mid left)
@ BUTTON_UNUSED2
Unused shift register pin.
@ BUTTON_SOUTH
The bottom black button.
@ BUTTON_UNUSED1
Unused shift register pin.
@ BUTTON_NORTH
The top black button.
@ BUTTON_4
4th red button (far right)
@ BUTTON_1
1st red button (far left)
@ DPAD_UP
Top button of the directional pad.
@ DPAD_LEFT
Left button of the directional pad.
bool getPowerLED() const
Gets the commanded state of the shifter's power LED.
bool getButton(Button button) const
Retrieve the state of a single button.
bool buttonsChanged() const
Checks if any of the buttons have changed since the last update.
LogitechShifterG27(PinNum pinX, PinNum pinY, PinNum pinLatch, PinNum pinClock, PinNum pinData, PinNum pinLed=UnusedPin, PinNum pinDetect=UnusedPin)
Class constructor.
bool getButtonChanged(Button button) const
Checks whether a button has changed between updates.
virtual void begin()
Initializes the hardware pins for reading the gear states and the buttons.
virtual bool updateState(bool connected)
Perform an internal poll of the hardware to refresh the class state.
void setPowerLED(bool state)
Sets the state of the shifter's power LED.
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.
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.
Pedals(AnalogInput *dataPtr, uint8_t nPedals)
Class constructor.
static String getPedalName(PedalID pedal)
Utility function to get the string name for each pedal.
virtual bool updateState(bool connected)
Perform an internal poll of the hardware to refresh the class state.
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 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.
bool isConnected() const
Check if the device is physically connected to the board.
void setDetectPtr(DeviceConnection *d)
Sets the pointer to the detector object.
bool update()
Perform a poll of the hardware to refresh the class state.
virtual ~Peripheral()
Class destructor.
virtual bool updateState(bool connected)=0
Perform an internal poll of the hardware to refresh the class state.
virtual void begin()
Initialize the hardware (if necessary)
void setStablePeriod(unsigned long t)
Set how long the detection pin must be stable for before the device is considered to be 'connected'.
Base class for all shifter instances.
String getGearString() const
Returns a String that represents the current gear.
Gear getGearMin()
Retrieves the minimum possible gear index.
void setGear(Gear gear)
Changes the currently set gear, internally.
Gear getGearMax()
Retrieves the maximum possible gear index.
Shifter(Gear min, Gear max)
Class constructor.
int8_t Gear
Type alias for gear numbers.
char getGearChar() const
Returns a character that represents the current gear.
Gear getGear() const
Returns the currently selected gear.
bool gearChanged() const
Checks whether the current gear has changed since the last update.
Pedal implementation for devices with gas, brake, and clutch.
ThreePedals(PinNum pinGas, PinNum pinBrake, PinNum pinClutch)
Class constructor.
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.
TwoPedals(PinNum pinGas, PinNum pinBrake)
Class constructor.
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.