Arduino Sim Racing Library v1.1.5
|
Interface with shifters using two potentiometers for gear position. More...
#include <SimRacing.h>
Classes | |
struct | GearPosition |
Simple struct to store X/Y coordinates for the calibration function. More... | |
Public Member Functions | |
AnalogShifter (PinNum pinX, PinNum pinY, PinNum pinRev=UnusedPin, PinNum pinDetect=UnusedPin) | |
Class constructor. | |
virtual void | begin () |
Initializes the hardware pins for reading the gear states. | |
virtual bool | update () |
Polls the hardware to update the current gear state. | |
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. | |
bool | isConnected () const |
Check if the device is physically connected to the board. | |
int8_t | 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. | |
int8_t | getGearMin () |
Retrieves the minimum possible gear index. | |
int8_t | getGearMax () |
Retrieves the maximum possible gear index. | |
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 Attributes | |
const int8_t | MinGear |
the lowest selectable gear | |
const int8_t | MaxGear |
the highest selectable gear | |
int8_t | currentGear |
index of the current gear | |
bool | changed |
whether the gear has changed since the previous update | |
Interface with shifters using two potentiometers for gear position.
Definition at line 547 of file SimRacing.h.
SimRacing::AnalogShifter::AnalogShifter | ( | PinNum | pinX, |
PinNum | pinY, | ||
PinNum | pinRev = UnusedPin, | ||
PinNum | pinDetect = UnusedPin ) |
Class constructor.
pinX | the analog input pin for the X axis |
pinY | the analog input pin for the Y axis |
pinRev | the digital input pin for the 'reverse' button |
pinDetect | the digital pin for device detection (high is detected) |
Definition at line 677 of file SimRacing.cpp.
|
virtual |
Initializes the hardware pins for reading the gear states.
Should be called in setup()
before reading from the shifter.
Reimplemented from SimRacing::Peripheral.
Definition at line 691 of file SimRacing.cpp.
|
inlineinherited |
Checks whether the current gear has changed since the last update.
Definition at line 519 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 475 of file SimRacing.h.
|
inherited |
Returns a character that represents the current gear.
Definition at line 624 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 606 of file SimRacing.cpp.
|
inlineinherited |
Retrieves the maximum possible gear index.
Definition at line 533 of file SimRacing.h.
|
inlineinherited |
Retrieves the minimum possible gear index.
Definition at line 526 of file SimRacing.h.
|
inherited |
Returns a String that represents the current gear.
Definition at line 665 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 628 of file SimRacing.cpp.
long SimRacing::AnalogShifter::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.
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 786 of file SimRacing.cpp.
int SimRacing::AnalogShifter::getPositionRaw | ( | Axis | ax | ) | const |
Retrieves the buffered position for the analog axis.
ax | the axis to get the position of |
Definition at line 791 of file SimRacing.cpp.
bool SimRacing::AnalogShifter::getReverseButton | ( | ) | const |
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 796 of file SimRacing.cpp.
|
inlinevirtual |
Check if the device is physically connected to the board.
That means it is both present and detected long enough to be considered 'stable'.
Reimplemented from SimRacing::Peripheral.
Definition at line 641 of file SimRacing.h.
void SimRacing::AnalogShifter::serialCalibration | ( | Stream & | iface = Serial | ) |
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 886 of file SimRacing.cpp.
void SimRacing::AnalogShifter::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.
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 805 of file SimRacing.cpp.
|
virtual |
Polls the hardware to update the current gear state.
Implements SimRacing::Peripheral.
Definition at line 698 of file SimRacing.cpp.
|
protectedinherited |
whether the gear has changed since the previous update
Definition at line 540 of file SimRacing.h.
|
protectedinherited |
index of the current gear
Definition at line 539 of file SimRacing.h.
|
protectedinherited |
the highest selectable gear
Definition at line 537 of file SimRacing.h.
|
protectedinherited |
the lowest selectable gear
Definition at line 536 of file SimRacing.h.