Arduino Sim Racing Library v1.1.3
SimRacing::AnalogShifter Class Reference

Interface with shifters using two potentiometers for gear position. More...

#include <SimRacing.h>

Inheritance diagram for SimRacing::AnalogShifter:
SimRacing::Shifter SimRacing::Peripheral SimRacing::LogitechShifter

Classes

struct  GearPosition
 Simple struct to store X/Y coordinates for the calibration function. More...
 

Public Member Functions

 AnalogShifter (uint8_t pinX, uint8_t pinY, uint8_t pinRev=NOT_A_PIN, uint8_t detectPin=NOT_A_PIN)
 
virtual void begin ()
 
virtual bool update ()
 
long getPosition (Axis ax, long rMin=AnalogInput::Min, long rMax=AnalogInput::Max) const
 
int getPositionRaw (Axis ax) const
 
bool getReverseButton () const
 
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)
 
void serialCalibration (Stream &iface=Serial)
 
bool isConnected () const
 
int8_t getGear () const
 
char getGearChar () const
 
String getGearString () const
 
bool gearChanged () const
 
int8_t getGearMin ()
 
int8_t getGearMax ()
 

Static Public Member Functions

static char getGearChar (int gear)
 
static String getGearString (int gear)
 

Protected Attributes

const int8_t MinGear
 the lowest selectable gear More...
 
const int8_t MaxGear
 the highest selectable gear More...
 
int8_t currentGear
 index of the current gear More...
 
bool changed
 whether the gear has changed since the previous update More...
 

Detailed Description

Interface with shifters using two potentiometers for gear position.

Definition at line 535 of file SimRacing.h.

Constructor & Destructor Documentation

◆ AnalogShifter()

SimRacing::AnalogShifter::AnalogShifter ( uint8_t  pinX,
uint8_t  pinY,
uint8_t  pinRev = NOT_A_PIN,
uint8_t  detectPin = NOT_A_PIN 
)

Class constructor

Parameters
pinXthe analog input pin for the X axis
pinYthe analog input pin for the Y axis
pinRevthe digital input pin for the 'reverse' button
detectPinthe digital pin for device detection (high is detected)

Definition at line 660 of file SimRacing.cpp.

Member Function Documentation

◆ begin()

void SimRacing::AnalogShifter::begin ( )
virtual

Initializes the hardware pins for reading the gear states.

Should be called in setup() before reading from the shifter.

Reimplemented from SimRacing::Peripheral.

Examples
ShiftJoystick.ino, and ShiftPrint.ino.

Definition at line 674 of file SimRacing.cpp.

◆ gearChanged()

bool SimRacing::Shifter::gearChanged ( ) const
inlineinherited

Checks whether the current gear has changed since the last update.

Returns
'true' if gear has changed, 'false' otherwise
Examples
ShiftJoystick.ino, and ShiftPrint.ino.

Definition at line 507 of file SimRacing.h.

◆ getGear()

int8_t SimRacing::Shifter::getGear ( ) const
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.).

Returns
current gear index
Examples
ShiftJoystick.ino, and ShiftPrint.ino.

Definition at line 463 of file SimRacing.h.

◆ getGearChar() [1/2]

char SimRacing::Shifter::getGearChar ( ) const
inherited

Returns a character that represents the current gear.

Returns
letter representing the current gear
See also
getGearChar(int)

Definition at line 607 of file SimRacing.cpp.

◆ getGearChar() [2/2]

char SimRacing::Shifter::getGearChar ( int  gear)
staticinherited

Returns a character that represents the given gear.

'r' for reverse, 'n' for neutral, or the number of the current gear.

Parameters
gearthe gear index to get the representation for
Returns
letter representing the current gear

Definition at line 589 of file SimRacing.cpp.

◆ getGearMax()

int8_t SimRacing::Shifter::getGearMax ( )
inlineinherited

Retrieves the maximum possible gear index.

Returns
the highest gear index

Definition at line 521 of file SimRacing.h.

◆ getGearMin()

int8_t SimRacing::Shifter::getGearMin ( )
inlineinherited

Retrieves the minimum possible gear index.

Returns
the lowest gear index

Definition at line 514 of file SimRacing.h.

◆ getGearString() [1/2]

String SimRacing::Shifter::getGearString ( ) const
inherited

Returns a String that represents the current gear.

Returns
String representing the current gear
See also
getGearString(int)

Definition at line 648 of file SimRacing.cpp.

◆ getGearString() [2/2]

String SimRacing::Shifter::getGearString ( int  gear)
staticinherited

Returns a String that represents the given gear.

"reverse" for reverse, "neutral" for neutral, and then "1st", "2nd", "3rd", and so on.

Parameters
gearthe gear index to get the representation for
Returns
String representing the current gear
Examples
ShiftPrint.ino.

Definition at line 611 of file SimRacing.cpp.

◆ getPosition()

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

Parameters
rMinthe minimum output value for the rescaling function
rMaxthe maximum output value for the rescaling function
Returns
the axis position, buffered and rescaled
Parameters
axthe axis to get the position of
Examples
ShiftJoystick.ino.

Definition at line 767 of file SimRacing.cpp.

◆ getPositionRaw()

int SimRacing::AnalogShifter::getPositionRaw ( Axis  ax) const

Retrieves the buffered position for the analog axis.

Returns
the axis position, buffered
Parameters
axthe axis to get the position of
Examples
ShiftPrint.ino.

Definition at line 772 of file SimRacing.cpp.

◆ getReverseButton()

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.

Returns
current state of the "reverse" button
Examples
ShiftJoystick.ino.

Definition at line 777 of file SimRacing.cpp.

◆ isConnected()

bool SimRacing::AnalogShifter::isConnected ( ) const
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'.

Returns
'true' if the device is connected, 'false' otherwise

Reimplemented from SimRacing::Peripheral.

Definition at line 629 of file SimRacing.h.

◆ serialCalibration()

void SimRacing::AnalogShifter::serialCalibration ( Stream &  iface = Serial)

Runs an interactive calibration tool using the serial interface.

Parameters
ifacethe serial interface to send and receive prompts. Defaults to Serial (CDC USB on most boards).
Examples
ShiftPrint.ino.

Definition at line 867 of file SimRacing.cpp.

◆ setCalibration()

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.

Parameters
neutralthe X/Y position of the shifter in neutral
g1the X/Y position of the shifter in 1st gear
g2the X/Y position of the shifter in 2nd gear
g3the X/Y position of the shifter in 3rd gear
g4the X/Y position of the shifter in 4th gear
g5the X/Y position of the shifter in 5th gear
g6the X/Y position of the shifter in 6th gear
engagePointdistance from neutral on Y to register a gear as being engaged (as a percentage of distance from neutral to Y max, 0-1)
releasePointdistance 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)
edgeOffsetdistance 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 786 of file SimRacing.cpp.

◆ update()

bool SimRacing::AnalogShifter::update ( )
virtual

Polls the hardware to update the current gear state.

Returns
'true' if the gear has changed, 'false' otherwise

Implements SimRacing::Peripheral.

Examples
ShiftJoystick.ino, and ShiftPrint.ino.

Definition at line 679 of file SimRacing.cpp.

Member Data Documentation

◆ changed

bool SimRacing::Shifter::changed
protectedinherited

whether the gear has changed since the previous update

Definition at line 528 of file SimRacing.h.

◆ currentGear

int8_t SimRacing::Shifter::currentGear
protectedinherited

index of the current gear

Definition at line 527 of file SimRacing.h.

◆ MaxGear

const int8_t SimRacing::Shifter::MaxGear
protectedinherited

the highest selectable gear

Definition at line 525 of file SimRacing.h.

◆ MinGear

const int8_t SimRacing::Shifter::MinGear
protectedinherited

the lowest selectable gear

Definition at line 524 of file SimRacing.h.


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