Arduino Sim Racing Library v2.0.0
|
Interface with the Logitech Driving Force shifter. More...
#include <SimRacing.h>
Public Types | |
using | Gear = int8_t |
Type alias for gear numbers. | |
Public Member Functions | |
LogitechShifter (PinNum pinX, PinNum pinY, PinNum pinRev=UnusedPin, PinNum pinDetect=UnusedPin) | |
Class constructor. | |
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 calibration values. | |
int | getPositionRaw (Axis ax) const |
Retrieves the buffered position for the analog axis. | |
bool | getReverseButton () const |
Checks the current state of the "reverse" button at the bottom of the shift column. | |
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. | |
Gear | getGear () const |
Returns the currently selected gear. | |
char | getGearChar () const |
Returns a character that represents the current gear. | |
String | getGearString () const |
Returns a String that represents the current gear. | |
bool | gearChanged () const |
Checks whether the current gear has changed since the last update. | |
Gear | getGearMin () |
Retrieves the minimum possible gear index. | |
Gear | getGearMax () |
Retrieves the maximum possible gear index. | |
bool | update () |
Perform a poll of the hardware to refresh the class state. | |
bool | isConnected () const |
Check if the device is physically connected to the board. | |
void | setStablePeriod (unsigned long t) |
Set how long the detection pin must be stable for before the device is considered to be 'connected'. | |
Static Public Member Functions | |
static char | getGearChar (int gear) |
Returns a character that represents the given gear. | |
static String | getGearString (int gear) |
Returns a String that represents the given gear. | |
Protected Member Functions | |
virtual bool | updateState (bool connected) |
Perform an internal poll of the hardware to refresh the class state. | |
void | setGear (Gear gear) |
Changes the currently set gear, internally. | |
void | setDetectPtr (DeviceConnection *d) |
Sets the pointer to the detector object. | |
Interface with the Logitech Driving Force shifter.
Definition at line 883 of file SimRacing.h.
|
inherited |
Type alias for gear numbers.
Definition at line 510 of file SimRacing.h.
SimRacing::LogitechShifter::LogitechShifter | ( | PinNum | pinX, |
PinNum | pinY, | ||
PinNum | pinRev = UnusedPin, | ||
PinNum | pinDetect = UnusedPin ) |
Class constructor.
pinX | the analog input pin for the X axis, DE-9 pin 4 |
pinY | the analog input pin for the Y axis, DE-9 pin 8 |
pinRev | the digital input pin for the 'reverse' button, DE-9 pin 2 |
pinDetect | the digital pin for device detection, DE-9 pin 7. Requires a pull-down resistor. |
Definition at line 1134 of file SimRacing.cpp.
|
virtualinherited |
Initializes the hardware pins for reading the gear states.
Should be called in setup()
before reading from the shifter.
Reimplemented from SimRacing::Peripheral.
Reimplemented in SimRacing::LogitechShifterG25, and SimRacing::LogitechShifterG27.
Definition at line 829 of file SimRacing.cpp.
|
inlineinherited |
Checks whether the current gear has changed since the last update.
Definition at line 572 of file SimRacing.h.
|
inlineinherited |
Returns the currently selected gear.
Will either be reverse (-1), neutral (0), or the current gear indexed at 1 (1st gear is 1, 2nd gear is 2, etc.).
Definition at line 528 of file SimRacing.h.
|
inherited |
Returns a character that represents the current gear.
Definition at line 763 of file SimRacing.cpp.
|
staticinherited |
Returns a character that represents the given gear.
'r' for reverse, 'n' for neutral, or the number of the current gear.
gear | the gear index to get the representation for |
Definition at line 745 of file SimRacing.cpp.
|
inlineinherited |
Retrieves the maximum possible gear index.
Definition at line 588 of file SimRacing.h.
|
inlineinherited |
Retrieves the minimum possible gear index.
Definition at line 581 of file SimRacing.h.
|
inherited |
Returns a String that represents the current gear.
Definition at line 804 of file SimRacing.cpp.
|
staticinherited |
Returns a String that represents the given gear.
"reverse" for reverse, "neutral" for neutral, and then "1st", "2nd", "3rd", and so on.
gear | the gear index to get the representation for |
Definition at line 767 of file SimRacing.cpp.
|
inherited |
Retrieves the buffered position for the analog axis, rescaled to a nominal range using the calibration values.
By default this is rescaled to a 10-bit value, matching the range used by the AVR analog to digital converter (ADC).
rMin | the minimum output value for the rescaling function |
rMax | the maximum output value for the rescaling function |
ax | the axis to get the position of |
Definition at line 915 of file SimRacing.cpp.
|
inherited |
Retrieves the buffered position for the analog axis.
ax | the axis to get the position of |
Definition at line 920 of file SimRacing.cpp.
|
inherited |
Checks the current state of the "reverse" button at the bottom of the shift column.
This button is pressed (HIGH) when the shifter is in reverse gear, LOW otherwise.
Definition at line 934 of file SimRacing.cpp.
|
inherited |
Check if the device is physically connected to the board.
That means it is both present and detected long enough to be considered 'stable'.
Definition at line 446 of file SimRacing.cpp.
|
inherited |
Runs an interactive calibration tool using the serial interface.
iface | the serial interface to send and receive prompts. Defaults to Serial (CDC USB on most boards). |
Definition at line 1021 of file SimRacing.cpp.
|
inherited |
Calibrate the gear shifter for more accurate shifting.
Note that this uses a large number of GearPosition arguments rather than an array because it allows for the use of aggregate initialization.
This way users can copy a single line to set calibration, rather than declaring an array of GearPosition elements and then passing that by pointer to this function.
neutral | the X/Y position of the shifter in neutral |
g1 | the X/Y position of the shifter in 1st gear |
g2 | the X/Y position of the shifter in 2nd gear |
g3 | the X/Y position of the shifter in 3rd gear |
g4 | the X/Y position of the shifter in 4th gear |
g5 | the X/Y position of the shifter in 5th gear |
g6 | the X/Y position of the shifter in 6th gear |
engagePoint | distance from neutral on Y to register a gear as being engaged (as a percentage of distance from neutral to Y max, 0-1) |
releasePoint | distance from neutral on Y to go back into neutral from an engaged gear (as a percentage of distance from neutral to Y max, 0-1) |
edgeOffset | distance from neutral on X to select the side gears rather than the center gears (as a percentage of distance from neutral to X max, 0-1) |
Definition at line 940 of file SimRacing.cpp.
|
protectedinherited |
Sets the pointer to the detector object.
The detector object is used to check if the peripheral is connected to the microcontroller. The object is polled on every update.
Although the detector instance is accessed via the Peripheral class, it is the responsibility of the dervied class to store the DeviceConnection object and manage its lifetime.
d | pointer to the detector object |
Definition at line 456 of file SimRacing.cpp.
|
protectedinherited |
Changes the currently set gear, internally.
This function sanitizes the newly selected gear with MinGear / MaxGear, and handles caching the previous value for checking if the gear has changed.
gear | the new gear value to set |
Definition at line 735 of file SimRacing.cpp.
|
inherited |
Set how long the detection pin must be stable for before the device is considered to be 'connected'.
t | the amount of time, in ms, the input must be stable for (no changes) before it's interpreted as 'detected' |
Definition at line 460 of file SimRacing.cpp.
|
inherited |
Perform a poll of the hardware to refresh the class state.
Definition at line 433 of file SimRacing.cpp.
|
protectedvirtualinherited |
Perform an internal poll of the hardware to refresh the class state.
This function is called from within the public update() in order to refresh the cached state of the peripheral. It needs to be defined in every derived class. This function is the only place where the cached device state should be changed.
connected | the state of the device connection |
Implements SimRacing::Peripheral.
Reimplemented in SimRacing::LogitechShifterG25, and SimRacing::LogitechShifterG27.
Definition at line 836 of file SimRacing.cpp.