Arduino Sim Racing Library v1.1.4
Loading...
Searching...
No Matches
SimRacing::DeviceConnection Class Reference

Used for tracking whether a device is connected to a specific pin and stable. More...

#include <SimRacing.h>

Public Types

enum  ConnectionState { Disconnected , PlugIn , Connected , Unplug }
 The state of the connection, whether it is connected, disconnected, and everywhere in-between. More...
 

Public Member Functions

 DeviceConnection (uint8_t pin, bool invert=false, unsigned long detectTime=250)
 Class constructor.
 
void poll ()
 Checks if the pin detects a connection.
 
ConnectionState getState () const
 Retrieves the current ConnectionState from the instance.
 
bool isConnected () const
 Check if the device is physically connected to the board.
 
void setStablePeriod (unsigned long t)
 Allows the user to change the stable period of the detector.
 

Detailed Description

Used for tracking whether a device is connected to a specific pin and stable.

Definition at line 47 of file SimRacing.h.

Member Enumeration Documentation

◆ ConnectionState

The state of the connection, whether it is connected, disconnected, and everywhere in-between.

This is the type returned by the main 'getState()' method.

See also
getState()
Enumerator
Disconnected 

No connection present.

PlugIn 

Device was just plugged in (connection starts), unstable.

Connected 

Connection present and stable.

Unplug 

Device was just removed (connection ends)

Definition at line 56 of file SimRacing.h.

Constructor & Destructor Documentation

◆ DeviceConnection()

SimRacing::DeviceConnection::DeviceConnection ( uint8_t  pin,
bool  invert = false,
unsigned long  detectTime = 250 
)

Class constructor.

Parameters
pinthe pin number being read. Can be 'NOT_A_PIN' to disable.
invertwhether the input is inverted, so 'LOW' is detected instead of 'HIGH'
detectTimethe amount of time, in ms, the input must be stable for before it's interpreted as 'detected'

Definition at line 164 of file SimRacing.cpp.

Member Function Documentation

◆ getState()

DeviceConnection::ConnectionState SimRacing::DeviceConnection::getState ( ) const

Retrieves the current ConnectionState from the instance.

This allows functions to check the same connection state multiple times without having to re-poll.

Definition at line 228 of file SimRacing.cpp.

◆ isConnected()

bool SimRacing::DeviceConnection::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 232 of file SimRacing.cpp.

◆ poll()

void SimRacing::DeviceConnection::poll ( )

Checks if the pin detects a connection.

This polls the input and checks for whether it has been connected sufficiently long enough to be deemed "stable".

Definition at line 192 of file SimRacing.cpp.

◆ setStablePeriod()

void SimRacing::DeviceConnection::setStablePeriod ( unsigned long  t)

Allows the user to change the stable period of the detector.

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

Definition at line 236 of file SimRacing.cpp.


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