Arduino Sim Racing Library v1.1.5
Loading...
Searching...
No Matches
SimRacing::AnalogInput Class Reference

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.
 

Detailed Description

Handle I/O for analog (ADC) inputs.

Definition at line 136 of file SimRacing.h.

Constructor & Destructor Documentation

◆ AnalogInput()

SimRacing::AnalogInput::AnalogInput ( PinNum pin)

Class constructor.

Parameters
pinthe I/O pin for this input (Arduino numbering)

Definition at line 278 of file SimRacing.cpp.

Member Function Documentation

◆ getMax()

int SimRacing::AnalogInput::getMax ( ) const
inline

Retrieves the calibrated maximum position.

Returns
the maximum position for the axis, per the calibration

Definition at line 188 of file SimRacing.h.

◆ getMin()

int SimRacing::AnalogInput::getMin ( ) const
inline

Retrieves the calibrated minimum position.

Returns
the minimum position for the axis, per the calibration

Definition at line 181 of file SimRacing.h.

◆ getPosition()

long SimRacing::AnalogInput::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.

By default this is rescaled to a 10-bit value, matching the range used by the AVR analog to digital converter (ADC).

Parameters
rMinthe minimum output value for the rescaling function
rMaxthe maximum output value for the rescaling function
Returns
the axis position, buffered and rescaled

Definition at line 319 of file SimRacing.cpp.

◆ getPositionRaw()

int SimRacing::AnalogInput::getPositionRaw ( ) const

Retrieves the buffered position for the analog axis.

Returns
the axis position, buffered

Definition at line 324 of file SimRacing.cpp.

◆ isInverted()

bool SimRacing::AnalogInput::isInverted ( ) const

Check whether the axis is inverted or not.

Returns
'true' if the axis is inverted, 'false' otherwise

Definition at line 328 of file SimRacing.cpp.

◆ read()

bool SimRacing::AnalogInput::read ( )
virtual

Updates the current value of the axis by polling the ADC.

Returns
'true' if the value changed, 'false' otherwise

Definition at line 286 of file SimRacing.cpp.

◆ setCalibration()

void SimRacing::AnalogInput::setCalibration ( AnalogInput::Calibration newCal)

Calibrate the axis' min/max values for rescaling.

Parameters
newCalthe calibration data struct to pass

Definition at line 344 of file SimRacing.cpp.

◆ setInverted()

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).

Parameters
invertwhether the axis is inverted

Definition at line 336 of file SimRacing.cpp.

◆ setPosition()

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.

Parameters
newPosthe new position value to set

Definition at line 332 of file SimRacing.cpp.

Member Data Documentation

◆ Max

const int SimRacing::AnalogInput::Max = 1023
static

Maximum value of the analog to digital (ADC) converter. 10-bit by default.

Definition at line 139 of file SimRacing.h.

◆ Min

const int SimRacing::AnalogInput::Min = 0
static

Minimum value of the analog to digital (ADC) converter.

Definition at line 138 of file SimRacing.h.


The documentation for this class was generated from the following files: