Arduino Sim Racing Library v2.0.0
All Classes Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
SimRacing::Handbrake Class Reference

Interface with analog handbrakes that use hall effect sensors. More...

#include <SimRacing.h>

Inheritance diagram for SimRacing::Handbrake:
SimRacing::Peripheral

Public Member Functions

 Handbrake (PinNum pinAx)
 Class constructor.
 
virtual void begin ()
 Initializes the pin for reading from the handbrake.
 
long getPosition (long rMin=0, long rMax=100) const
 Retrieves the buffered position for the handbrake axis, rescaled to a nominal range using the calibration values.
 
int getPositionRaw () const
 Retrieves the buffered position for the handbrake, ignoring the calibration data.
 
bool positionChanged () const
 Checks whether the handbrake's position has changed since the last update.
 
void setCalibration (AnalogInput::Calibration newCal)
 Calibrate the axis' min/max values for rescaling.
 
void serialCalibration (Stream &iface=Serial)
 Runs an interactive calibration tool using the serial interface.
 
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'.
 

Protected Member Functions

virtual bool updateState (bool connected)
 Perform an internal poll of the hardware to refresh the class state.
 
void setDetectPtr (DeviceConnection *d)
 Sets the pointer to the detector object.
 

Detailed Description

Interface with analog handbrakes that use hall effect sensors.

Examples
HandbrakeJoystick.ino, and HandbrakePrint.ino.

Definition at line 771 of file SimRacing.h.

Constructor & Destructor Documentation

◆ Handbrake()

SimRacing::Handbrake::Handbrake ( PinNum pinAx)

Class constructor.

Parameters
pinAxanalog pin number for the handbrake axis

Definition at line 1669 of file SimRacing.cpp.

Member Function Documentation

◆ begin()

void SimRacing::Handbrake::begin ( )
virtual

Initializes the pin for reading from the handbrake.

Reimplemented from SimRacing::Peripheral.

Examples
HandbrakeJoystick.ino, and HandbrakePrint.ino.

Definition at line 1675 of file SimRacing.cpp.

◆ getPosition()

long SimRacing::Handbrake::getPosition ( long rMin = 0,
long rMax = 100 ) const

Retrieves the buffered position for the handbrake axis, rescaled to a nominal range using the calibration values.

By default this is rescaled to an integer percentage (0 - 100)

Parameters
rMinthe minimum output value
rMaxthe maximum output value
Returns
the handbrake position, buffered and rescaled
Examples
HandbrakeJoystick.ino, and HandbrakePrint.ino.

Definition at line 1701 of file SimRacing.cpp.

◆ getPositionRaw()

int SimRacing::Handbrake::getPositionRaw ( ) const

Retrieves the buffered position for the handbrake, ignoring the calibration data.

Returns
the handbrake position, buffered

Definition at line 1705 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.

◆ positionChanged()

bool SimRacing::Handbrake::positionChanged ( ) const
inline

Checks whether the handbrake's position has changed since the last update.

Returns
'true' if the position has changed, 'false' otherwise
Examples
HandbrakeJoystick.ino.

Definition at line 811 of file SimRacing.h.

◆ serialCalibration()

void SimRacing::Handbrake::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
HandbrakePrint.ino.

Definition at line 1714 of file SimRacing.cpp.

◆ setCalibration()

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

Calibrate the axis' min/max values for rescaling.

Parameters
newCalthe calibration data struct to pass

Definition at line 1709 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.

◆ 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::Handbrake::updateState ( bool connected)
protectedvirtual

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.

Definition at line 1679 of file SimRacing.cpp.


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