API Documentation v0.0.1
Loading...
Searching...
No Matches
SwitchMultiPosDebounce Class Reference

Provides debounce logic for multiposition switches used in DCS to prevent erroneous readings during switch transitions. More...

#include <5A7A1-SNSR_PANEL.h>

Public Member Functions

 SwitchMultiPosDebounce (const char *msg, const byte *pins, char numberOfPins, bool reverse=false, unsigned long debounceDelay=50)
 
void SetControl (const char *msg)
 
void resetThisState ()
 
void pollThisInput ()
 

Detailed Description

Provides debounce logic for multiposition switches used in DCS to prevent erroneous readings during switch transitions.

This class extends the functionality of the DCS BIOS library's SwitchMultiPos method by adding debounce logic. This ensures that while a knob is rotating, its output doesn't mistakenly bounce to an unconnected or default position between detents.

Todo
Remove the SwitchMultiPosDebounce class if the debounce feature is integrated into the DCS-BIOS Arduino library as per the pull request https://github.com/DCS-Skunkworks/dcs-bios-arduino-library/pull/56.

Definition at line 56 of file 5A7A1-SNSR_PANEL.h.

Constructor & Destructor Documentation

◆ SwitchMultiPosDebounce()

SwitchMultiPosDebounce::SwitchMultiPosDebounce ( const char * msg,
const byte * pins,
char numberOfPins,
bool reverse = false,
unsigned long debounceDelay = 50 )
inline

Constructor for initializing a debounced multiposition switch.

Parameters
msgThe DCS BIOS message identifier associated with this switch.
pinsArray of physical pin numbers connected to the switch positions.
numberOfPinsNumber of positions (pins) on the switch.
reverseSet to true to reverse the reading logic (for normally high switches).
debounceDelayDebounce time in milliseconds.

Definition at line 120 of file 5A7A1-SNSR_PANEL.h.

120 {
121 msg_ = msg;
122 pins_ = pins;
123 reverse_ = reverse;
124 numberOfPins_ = numberOfPins;
125 unsigned char i;
126 for (i = 0; i < numberOfPins; i++) {
127 if (pins[i] != DcsBios::PIN_NC)
128 pinMode(pins[i], INPUT_PULLUP);
129 }
130 lastState_ = readState();
131 debounceSteadyState_ = lastState_;
132 debounceDelay_ = debounceDelay;
133 }
unsigned long debounceDelay
The debounce delay duration in ms, increase if the output flickers.
const int * pins[15]
Array of pins to simplify the code working with the switches as joystick buttons.

References debounceDelay, and pins.

Member Function Documentation

◆ SetControl()

void SwitchMultiPosDebounce::SetControl ( const char * msg)
inline

Sets or changes the DCS BIOS message for the switch control.

Parameters
msgNew DCS BIOS message identifier for the switch.

Definition at line 139 of file 5A7A1-SNSR_PANEL.h.

139 {
140 msg_ = msg;
141 }

◆ resetThisState()

void SwitchMultiPosDebounce::resetThisState ( )
inline

Public interface to reset the state of the switch.

Definition at line 146 of file 5A7A1-SNSR_PANEL.h.

146 {
147 this->resetState();
148 }

◆ pollThisInput()

void SwitchMultiPosDebounce::pollThisInput ( )
inline

Public interface to check the input state of the switch and apply debounce logic.

Definition at line 153 of file 5A7A1-SNSR_PANEL.h.

153 {
154 this->pollInput();
155 }

Referenced by loop().


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