![]() |
MD_UISwitch Library
1.2
Library for different types of User Interface switches
|
#include <MD_UISwitch.h>
Classes | |
struct | uiAnalogKeys_t |
Public Member Functions | |
Class constructor and destructor. | |
MD_UISwitch_Analog (uint8_t pin, uiAnalogKeys_t *kt, uint8_t ktSize) | |
~MD_UISwitch_Analog () | |
Methods for core object control. | |
virtual void | begin (void) |
virtual keyResult_t | read (void) |
![]() | |
MD_UISwitch (void) | |
~MD_UISwitch () | |
virtual uint8_t | getKey (void) |
void | setDebounceTime (uint16_t t) |
void | setDoublePressTime (uint16_t t) |
void | setLongPressTime (uint16_t t) |
void | setRepeatTime (uint16_t t) |
void | enableDoublePress (boolean f) |
void | enableLongPress (boolean f) |
void | enableRepeat (boolean f) |
void | enableRepeatResult (boolean f) |
Protected Attributes | |
uint8_t | _pin |
pin number | |
uiAnalogKeys_t * | _kt |
analog key values table | |
uint8_t | _ktSize |
number of elements in analog keys table | |
int16_t | _lastKeyIdx |
index of the last key read | |
![]() | |
state_t | _state |
the FSM current state | |
uint32_t | _timeActive |
the millis() time it was last activated | |
uint8_t | _enableFlags |
functions enabled/disabled | |
uint16_t | _timeDebounce |
debounce time in milliseconds | |
uint16_t | _timeDoublePress |
double press detection time in milliseconds | |
uint16_t | _timeLongPress |
long press time in milliseconds | |
int16_t | _timeRepeat |
repeat time delay in milliseconds | |
uint8_t | _lastKey |
persists the last key value until a new one is detected | |
int16_t | _lastKeyIdx |
internal index of the last key read | |
Additional Inherited Members | |
![]() | |
enum | keyResult_t { KEY_NULL, KEY_PRESS, KEY_DPRESS, KEY_LONGPRESS, KEY_RPTPRESS } |
![]() | |
enum | state_t { S_IDLE, S_DEBOUNCE1, S_DEBOUNCE2, S_PRESS, S_DPRESS, S_LPRESS, S_REPEAT, S_WAIT } |
![]() | |
keyResult_t | processFSM (bool bState, bool reset=0) |
Extension class MD_UISwitch_Analog.
Implements resistor ladder switches on analog input. This type of switch are typically found on 1602 LCD module shields.
All the switches are wired to one analog input, genarraly with resistor values as shown in the circuit below. The switch pressed is determined from the analog value read from the port. This may vary depending on the implementation of the resistor, so a translation table is implemented to allow the remapping of the analog value to a key number.
The translation table must be determined separately and passed as a parameter to the class constructor - the utility application Test_Analog_Keys in the examples folder can be used for this purpose. The class does not copy this table to its own memory, so it must remain in scope for the life of the object.
MD_UISwitch_Analog::MD_UISwitch_Analog | ( | uint8_t | pin, |
uiAnalogKeys_t * | kt, | ||
uint8_t | ktSize | ||
) |
Class Constructor.
Instantiate a new instance of the class. The parameters passed are used to the hardware interface to the switch.
The key definitions table is not copiued by the class, so user code must ensure that the table remains in scope for the life of the object created.
pin | the analog pin to which the switches are connected. |
kt | pointer to a table of analog value key definitions |
ktSize | number of elements in the kt table |
MD_UISwitch_Analog::~MD_UISwitch_Analog | ( | ) |
Class Destructor.
Release allocated memory and does the necessary to clean up once the queue is no longer required.
|
virtual |
Initialize the object.
Initialise the object data. This needs to be called during setup() to initialise new data for the class that cannot be done during the object creation.
Reimplemented from MD_UISwitch.
|
virtual |
Return the state of the switch
Return one of the keypress types depending on what has been detected. The timing for each keypress starts when the first transition of the switch from inactive to active state and is recognised by a finite state machine whose operation is directed by the timer and option values specified.
Reimplemented from MD_UISwitch.