Arduino Sim Racing Library v2.0.0
|
Base class for all pedals instances. More...
#include <SimRacing.h>
Public Types | |
using | PedalID = SimRacing::Pedal |
Scoped alias for SimRacing::Pedal. | |
Public Member Functions | |
Pedals (AnalogInput *dataPtr, uint8_t nPedals) | |
Class constructor. | |
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 values. | |
int | getPositionRaw (PedalID pedal) const |
Retrieves the buffered position for the pedal, ignoring the calibration data. | |
bool | hasPedal (PedalID pedal) const |
Checks if a given pedal is present in the class. | |
int | getNumPedals () const |
Retrieves the number of pedals handled by the class. | |
bool | positionChanged () const |
Checks whether the current pedal positions have changed since the last update. | |
void | setCalibration (PedalID pedal, AnalogInput::Calibration cal) |
Calibrate a pedal's min/max values for rescaling. | |
void | serialCalibration (Stream &iface=Serial) |
Runs an interactive calibration tool using the serial interface. | |
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 String | getPedalName (PedalID pedal) |
Utility function to get the string name for each pedal. | |
Protected Member Functions | |
virtual bool | updateState (bool connected) |
Perform an internal poll of the hardware to refresh the class state. | |
void | setDetectPtr (DeviceConnection *d) |
Sets the pointer to the detector object. | |
Base class for all pedals instances.
Definition at line 335 of file SimRacing.h.
Scoped alias for SimRacing::Pedal.
Definition at line 338 of file SimRacing.h.
SimRacing::Pedals::Pedals | ( | AnalogInput * | dataPtr, |
uint8_t | nPedals ) |
Class constructor.
dataPtr | pointer to the analog input data managed by the class, stored elsewhere |
nPedals | the number of pedals stored in said data pointer |
Definition at line 471 of file SimRacing.cpp.
|
virtual |
Initialize the hardware (if necessary)
Reimplemented from SimRacing::Peripheral.
Definition at line 478 of file SimRacing.cpp.
|
inline |
Retrieves the number of pedals handled by the class.
Definition at line 390 of file SimRacing.h.
|
static |
Utility function to get the string name for each pedal.
pedal | the pedal to get the name of |
Definition at line 527 of file SimRacing.cpp.
long SimRacing::Pedals::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 values.
By default this is rescaled to an integer percentage.
pedal | the pedal to retrieve position for |
rMin | the minimum output value for the rescaling function |
rMax | the maximum output value for the rescaling function |
Definition at line 507 of file SimRacing.cpp.
int SimRacing::Pedals::getPositionRaw | ( | PedalID | pedal | ) | const |
Retrieves the buffered position for the pedal, ignoring the calibration data.
pedal | the pedal to retrieve position for |
Definition at line 512 of file SimRacing.cpp.
bool SimRacing::Pedals::hasPedal | ( | PedalID | pedal | ) | const |
Checks if a given pedal is present in the class.
pedal | the pedal to check |
Definition at line 517 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.
|
inline |
Checks whether the current pedal positions have changed since the last update.
Definition at line 397 of file SimRacing.h.
void SimRacing::Pedals::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 547 of file SimRacing.cpp.
void SimRacing::Pedals::setCalibration | ( | PedalID | pedal, |
AnalogInput::Calibration | cal ) |
Calibrate a pedal's min/max values for rescaling.
pedal | the pedal to set the calibration of |
cal | the calibration data to set |
Definition at line 521 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.
|
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.
|
protectedvirtual |
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.
Definition at line 482 of file SimRacing.cpp.