Arduino Sim Racing Library v2.0.0
Loading...
Searching...
No Matches
SimRacing::LogitechShifter Class Reference

Interface with the Logitech Driving Force shifter. More...

#include <SimRacing.h>

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

Public Types

using Gear = int8_t
 Type alias for gear numbers.
 

Public Member Functions

 LogitechShifter (PinNum pinX, PinNum pinY, PinNum pinRev=UnusedPin, PinNum pinDetect=UnusedPin)
 Class constructor.
 
virtual void begin ()
 Initializes the hardware pins for reading the gear states.
 
long 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.
 
int getPositionRaw (Axis ax) const
 Retrieves the buffered position for the analog axis.
 
bool getReverseButton () const
 Checks the current state of the "reverse" button at the bottom of the shift column.
 
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)
 Calibrate the gear shifter for more accurate shifting.
 
void serialCalibration (Stream &iface=Serial)
 Runs an interactive calibration tool using the serial interface.
 
Gear 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.
 
Gear getGearMin ()
 Retrieves the minimum possible gear index.
 
Gear getGearMax ()
 Retrieves the maximum possible gear index.
 
bool update ()
 Perform a poll of the hardware to refresh the class state.
 
bool isConnected () const
 Check if the device is physically connected to the board.
 
void setStablePeriod (unsigned long t)
 Set how long the detection pin must be stable for before the device is considered to be 'connected'.
 

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 Member Functions

virtual bool updateState (bool connected)
 Perform an internal poll of the hardware to refresh the class state.
 
void setGear (Gear gear)
 Changes the currently set gear, internally.
 
void setDetectPtr (DeviceConnection *d)
 Sets the pointer to the detector object.
 

Detailed Description

Interface with the Logitech Driving Force shifter.

See also
https://www.logitechg.com/en-us/products/driving/driving-force-shifter.941-000119.html
Examples
LogitechShifter_Joystick.ino, and LogitechShifter_Print.ino.

Definition at line 883 of file SimRacing.h.

Member Typedef Documentation

◆ Gear

using SimRacing::Shifter::Gear = int8_t
inherited

Type alias for gear numbers.

Definition at line 510 of file SimRacing.h.

Constructor & Destructor Documentation

◆ LogitechShifter()

SimRacing::LogitechShifter::LogitechShifter ( PinNum pinX,
PinNum pinY,
PinNum pinRev = UnusedPin,
PinNum pinDetect = UnusedPin )

Class constructor.

Parameters
pinXthe analog input pin for the X axis, DE-9 pin 4
pinYthe analog input pin for the Y axis, DE-9 pin 8
pinRevthe digital input pin for the 'reverse' button, DE-9 pin 2
pinDetectthe digital pin for device detection, DE-9 pin 7. Requires a pull-down resistor.
Note
In order to get the 'reverse' signal from the shifter, the chip select pin (DE-9 pin 3) needs to be pulled up to VCC.

Definition at line 1134 of file SimRacing.cpp.

Member Function Documentation

◆ begin()

void SimRacing::AnalogShifter::begin ( )
virtualinherited

Initializes the hardware pins for reading the gear states.

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

Reimplemented from SimRacing::Peripheral.

Reimplemented in SimRacing::LogitechShifterG25, and SimRacing::LogitechShifterG27.

Examples
LogitechShifterG25_Joystick.ino, LogitechShifterG25_Print.ino, LogitechShifterG27_Joystick.ino, LogitechShifterG27_Print.ino, LogitechShifter_Joystick.ino, and LogitechShifter_Print.ino.

Definition at line 829 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
LogitechShifter_Joystick.ino, and LogitechShifter_Print.ino.

Definition at line 572 of file SimRacing.h.

◆ getGear()

Gear 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
LogitechShifterG25_Joystick.ino, LogitechShifterG27_Joystick.ino, LogitechShifter_Joystick.ino, and LogitechShifter_Print.ino.

Definition at line 528 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 763 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
Examples
LogitechShifterG25_Print.ino, and LogitechShifterG27_Print.ino.

Definition at line 745 of file SimRacing.cpp.

◆ getGearMax()

Gear SimRacing::Shifter::getGearMax ( )
inlineinherited

Retrieves the maximum possible gear index.

Returns
the highest gear index

Definition at line 588 of file SimRacing.h.

◆ getGearMin()

Gear SimRacing::Shifter::getGearMin ( )
inlineinherited

Retrieves the minimum possible gear index.

Returns
the lowest gear index

Definition at line 581 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 804 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
LogitechShifter_Print.ino.

Definition at line 767 of file SimRacing.cpp.

◆ getPosition()

long SimRacing::AnalogShifter::getPosition ( Axis ax,
long rMin = AnalogInput::Min,
long rMax = AnalogInput::Max ) const
inherited

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
LogitechShifterG25_Joystick.ino, LogitechShifterG27_Joystick.ino, and LogitechShifter_Joystick.ino.

Definition at line 915 of file SimRacing.cpp.

◆ getPositionRaw()

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

Retrieves the buffered position for the analog axis.

Returns
the axis position, buffered
Parameters
axthe axis to get the position of
Examples
LogitechShifterG25_Print.ino, LogitechShifterG27_Print.ino, and LogitechShifter_Print.ino.

Definition at line 920 of file SimRacing.cpp.

◆ getReverseButton()

bool SimRacing::AnalogShifter::getReverseButton ( ) const
inherited

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
LogitechShifter_Joystick.ino.

Definition at line 934 of file SimRacing.cpp.

◆ isConnected()

bool SimRacing::Peripheral::isConnected ( ) const
inherited

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

Definition at line 446 of file SimRacing.cpp.

◆ serialCalibration()

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

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
LogitechShifterG25_Print.ino, LogitechShifterG27_Print.ino, and LogitechShifter_Print.ino.

Definition at line 1021 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 )
inherited

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 940 of file SimRacing.cpp.

◆ setDetectPtr()

void SimRacing::Peripheral::setDetectPtr ( DeviceConnection * d)
protectedinherited

Sets the pointer to the detector object.

The detector object is used to check if the peripheral is connected to the microcontroller. The object is polled on every update.

Although the detector instance is accessed via the Peripheral class, it is the responsibility of the dervied class to store the DeviceConnection object and manage its lifetime.

Parameters
dpointer to the detector object

Definition at line 456 of file SimRacing.cpp.

◆ setGear()

void SimRacing::Shifter::setGear ( Gear gear)
protectedinherited

Changes the currently set gear, internally.

This function sanitizes the newly selected gear with MinGear / MaxGear, and handles caching the previous value for checking if the gear has changed.

Parameters
gearthe new gear value to set

Definition at line 735 of file SimRacing.cpp.

◆ setStablePeriod()

void SimRacing::Peripheral::setStablePeriod ( unsigned long t)
inherited

Set how long the detection pin must be stable for before the device is considered to be 'connected'.

Parameters
tthe amount of time, in ms, the input must be stable for (no changes) before it's interpreted as 'detected'

Definition at line 460 of file SimRacing.cpp.

◆ update()

bool SimRacing::Peripheral::update ( )
inherited

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

Returns
'true' if device state changed, 'false' otherwise
Examples
HandbrakeJoystick.ino, HandbrakePrint.ino, LogitechShifterG25_Joystick.ino, LogitechShifterG25_Print.ino, LogitechShifterG27_Joystick.ino, LogitechShifterG27_Print.ino, LogitechShifter_Joystick.ino, LogitechShifter_Print.ino, PedalsJoystick.ino, and PedalsPrint.ino.

Definition at line 433 of file SimRacing.cpp.

◆ updateState()

bool SimRacing::AnalogShifter::updateState ( bool connected)
protectedvirtualinherited

Perform an internal poll of the hardware to refresh the class state.

This function is called from within the public update() in order to refresh the cached state of the peripheral. It needs to be defined in every derived class. This function is the only place where the cached device state should be changed.

Parameters
connectedthe state of the device connection
Returns
'true' if device state changed, 'false' otherwise

Implements SimRacing::Peripheral.

Reimplemented in SimRacing::LogitechShifterG25, and SimRacing::LogitechShifterG27.

Definition at line 836 of file SimRacing.cpp.


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