Arduino Sim Racing Library v1.1.5
|
Handle I/O for analog (ADC) inputs. More...
#include <SimRacing.h>
Classes | |
struct | Calibration |
Simple struct containing min/max values for axis calibration. More... | |
Public Member Functions | |
AnalogInput (PinNum pin) | |
Class constructor. | |
virtual bool | read () |
Updates the current value of the axis by polling the ADC. | |
long | getPosition (long rMin=Min, long rMax=Max) const |
Retrieves the buffered position for the analog axis, rescaled to a nominal range using the calibration values. | |
int | getPositionRaw () const |
Retrieves the buffered position for the analog axis. | |
int | getMin () const |
Retrieves the calibrated minimum position. | |
int | getMax () const |
Retrieves the calibrated maximum position. | |
bool | isInverted () const |
Check whether the axis is inverted or not. | |
void | setPosition (int newPos) |
Override the current position with a custom value. | |
void | setInverted (bool invert=true) |
Set the 'inverted' state of the axis. | |
void | setCalibration (Calibration newCal) |
Calibrate the axis' min/max values for rescaling. | |
Static Public Attributes | |
static const int | Min = 0 |
Minimum value of the analog to digital (ADC) converter. | |
static const int | Max = 1023 |
Maximum value of the analog to digital (ADC) converter. 10-bit by default. | |
Handle I/O for analog (ADC) inputs.
Definition at line 136 of file SimRacing.h.
SimRacing::AnalogInput::AnalogInput | ( | PinNum | pin | ) |
Class constructor.
pin | the I/O pin for this input (Arduino numbering) |
Definition at line 278 of file SimRacing.cpp.
|
inline |
Retrieves the calibrated maximum position.
Definition at line 188 of file SimRacing.h.
|
inline |
Retrieves the calibrated minimum position.
Definition at line 181 of file SimRacing.h.
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 |
Definition at line 319 of file SimRacing.cpp.
int SimRacing::AnalogInput::getPositionRaw | ( | ) | const |
Retrieves the buffered position for the analog axis.
Definition at line 324 of file SimRacing.cpp.
bool SimRacing::AnalogInput::isInverted | ( | ) | const |
Check whether the axis is inverted or not.
Definition at line 328 of file SimRacing.cpp.
|
virtual |
Updates the current value of the axis by polling the ADC.
Definition at line 286 of file SimRacing.cpp.
void SimRacing::AnalogInput::setCalibration | ( | AnalogInput::Calibration | newCal | ) |
Calibrate the axis' min/max values for rescaling.
newCal | the calibration data struct to pass |
Definition at line 344 of file SimRacing.cpp.
void SimRacing::AnalogInput::setInverted | ( | bool | invert = true | ) |
Set the 'inverted' state of the axis.
This will return a flipped number when getPosition() is called (e.g. the axis at its maximum will return a minimum value).
invert | whether the axis is inverted |
Definition at line 336 of file SimRacing.cpp.
void SimRacing::AnalogInput::setPosition | ( | int | newPos | ) |
Override the current position with a custom value.
This is useful for whenever a device has disconnected and we want to set a new 'default' value for position requests.
newPos | the new position value to set |
Definition at line 332 of file SimRacing.cpp.
|
static |
Maximum value of the analog to digital (ADC) converter. 10-bit by default.
Definition at line 139 of file SimRacing.h.
|
static |
Minimum value of the analog to digital (ADC) converter.
Definition at line 138 of file SimRacing.h.