Arduino Sim Racing Library v1.1.5
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 457 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 602 of file SimRacing.cpp.

Member Function Documentation

◆ begin()

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

Initialize the hardware (if necessary)

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

Definition at line 254 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 519 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 475 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 624 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 606 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 533 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 526 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 665 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 628 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::AnalogShifter, SimRacing::Handbrake, and SimRacing::Pedals.

Definition at line 264 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::AnalogShifter, SimRacing::Handbrake, and SimRacing::Pedals.

Member Data Documentation

◆ changed

bool SimRacing::Shifter::changed
protected

whether the gear has changed since the previous update

Definition at line 540 of file SimRacing.h.

◆ currentGear

int8_t SimRacing::Shifter::currentGear
protected

index of the current gear

Definition at line 539 of file SimRacing.h.

◆ MaxGear

const int8_t SimRacing::Shifter::MaxGear
protected

the highest selectable gear

Definition at line 537 of file SimRacing.h.

◆ MinGear

const int8_t SimRacing::Shifter::MinGear
protected

the lowest selectable gear

Definition at line 536 of file SimRacing.h.


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