Arduino Sim Racing Library v1.1.4
Loading...
Searching...
No Matches
SimRacing::Shifter Class Referenceabstract

Base class for all shifter instances. More...

#include <SimRacing.h>

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

Public Member Functions

 Shifter (int8_t min, int8_t max)
 Class constructor.
 
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.
 
virtual void begin ()
 Initialize the hardware (if necessary)
 
virtual bool update ()=0
 Perform a poll of the hardware to refresh the class state.
 
virtual bool isConnected () const
 Check if the device is physically connected to the board.
 

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
 

Detailed Description

Base class for all shifter instances.

Definition at line 445 of file SimRacing.h.

Constructor & Destructor Documentation

◆ Shifter()

SimRacing::Shifter::Shifter ( int8_t  min,
int8_t  max 
)

Class constructor.

Parameters
minthe lowest gear possible
maxthe highest gear possible

Definition at line 585 of file SimRacing.cpp.

Member Function Documentation

◆ begin()

virtual void SimRacing::Peripheral::begin ( )
inlinevirtualinherited

Initialize the hardware (if necessary)

Reimplemented in SimRacing::Pedals, SimRacing::AnalogShifter, and SimRacing::Handbrake.

Definition at line 242 of file SimRacing.h.

◆ gearChanged()

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

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
inline

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

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

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 ( )
inline

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 ( )
inline

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

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

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.

◆ isConnected()

virtual bool SimRacing::Peripheral::isConnected ( ) const
inlinevirtualinherited

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 in SimRacing::Pedals, SimRacing::AnalogShifter, and SimRacing::Handbrake.

Definition at line 252 of file SimRacing.h.

◆ update()

virtual bool SimRacing::Peripheral::update ( )
pure virtualinherited

Perform a poll of the hardware to refresh the class state.

Returns
'true' if device state changed, 'false' otherwise

Implemented in SimRacing::Pedals, SimRacing::AnalogShifter, and SimRacing::Handbrake.

Member Data Documentation

◆ changed

bool SimRacing::Shifter::changed
protected

whether the gear has changed since the previous update

Definition at line 528 of file SimRacing.h.

◆ currentGear

int8_t SimRacing::Shifter::currentGear
protected

index of the current gear

Definition at line 527 of file SimRacing.h.

◆ MaxGear

const int8_t SimRacing::Shifter::MaxGear
protected

the highest selectable gear

Definition at line 525 of file SimRacing.h.

◆ MinGear

const int8_t SimRacing::Shifter::MinGear
protected

the lowest selectable gear

Definition at line 524 of file SimRacing.h.


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