Arduino Sim Racing Library v2.0.0
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 (PinNum pin, bool activeLow=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)
 Set how long the detection pin must be stable for before the device is considered to be 'connected'.
 

Detailed Description

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

Definition at line 59 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 68 of file SimRacing.h.

Constructor & Destructor Documentation

◆ DeviceConnection()

SimRacing::DeviceConnection::DeviceConnection ( PinNum pin,
bool activeLow = false,
unsigned long detectTime = 250 )

Class constructor.

Parameters
pinthe pin number being read. Can be 'UnusedPin' to disable.
activeLowwhether the device is detected on a high signal (false, default) or a low signal (true)
detectTimethe amount of time, in ms, the input must be stable for before it's interpreted as 'detected'

Definition at line 260 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 326 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 330 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 290 of file SimRacing.cpp.

◆ setStablePeriod()

void SimRacing::DeviceConnection::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 334 of file SimRacing.cpp.


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