Arduino Sim Racing Library v2.0.0
Loading...
Searching...
No Matches
SimRacing::Peripheral Class Referenceabstract

Abstract class for all peripherals. More...

#include <SimRacing.h>

Inheritance diagram for SimRacing::Peripheral:
SimRacing::Handbrake SimRacing::Pedals SimRacing::Shifter SimRacing::ThreePedals SimRacing::TwoPedals SimRacing::AnalogShifter SimRacing::LogitechPedals SimRacing::LogitechDrivingForceGT_Pedals SimRacing::LogitechShifter SimRacing::LogitechShifterG27 SimRacing::LogitechShifterG25

Public Member Functions

virtual ~Peripheral ()
 Class destructor.
 
virtual void begin ()
 Initialize the hardware (if necessary)
 
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)=0
 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

Abstract class for all peripherals.

Definition at line 251 of file SimRacing.h.

Constructor & Destructor Documentation

◆ ~Peripheral()

virtual SimRacing::Peripheral::~Peripheral ( )
inlinevirtual

Class destructor.

Definition at line 256 of file SimRacing.h.

Member Function Documentation

◆ begin()

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

Initialize the hardware (if necessary)

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

Definition at line 261 of file SimRacing.h.

◆ isConnected()

bool SimRacing::Peripheral::isConnected ( ) const

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.

◆ setDetectPtr()

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

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)

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

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

virtual bool SimRacing::Peripheral::updateState ( bool connected)
protectedpure virtual

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

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


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