MD_UISwitch Library 2.2
Library for different types of User Interface switches
MD_UISwitch_User Class Reference

#include <MD_UISwitch.h>

Inheritance diagram for MD_UISwitch_User:
Collaboration diagram for MD_UISwitch_User:

Public Types

typedef bool(* cbUserData) (uint8_t id)
 
- Public Types inherited from MD_UISwitch
enum  keyResult_t {
  KEY_NULL , KEY_DOWN , KEY_UP , KEY_PRESS ,
  KEY_DPRESS , KEY_LONGPRESS , KEY_RPTPRESS
}
 

Public Member Functions

Class constructor and destructor.
 MD_UISwitch_User (uint8_t id, cbUserData cb)
 
 MD_UISwitch_User (uint8_t *ids, uint8_t idCount, cbUserData cb)
 
 ~MD_UISwitch_User ()
 
Methods for core object control.
virtual void begin (void)
 
virtual keyResult_t read (void)
 
- Public Member Functions inherited from MD_UISwitch
 MD_UISwitch (void)
 
 ~MD_UISwitch ()
 
virtual uint8_t getKey (void)
 
void setPressTime (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 _idSimple
 number for simple id
 
uint8_t * _ids
 pointer to data for one or more ids
 
uint8_t _idCount
 number of ids defined
 
cbUserData _cb
 callback to obtain user digital data
 
- Protected Attributes inherited from MD_UISwitch
state_fsm _state
 the FSM current state
 
keyResult_t _kPush
 storage for pushed key in FSM
 
uint32_t _timeActive
 the millis() time switch was last activated
 
uint8_t _enableFlags
 functions enabled/disabled
 
uint8_t _RC = 0
 RC integrator value.
 
bool _prevStatus
 previous 'active' status for edge detection
 
state_db _RCstate
 current RC debouning state
 
uint16_t _timePress
 press time in milliseconds
 
uint16_t _timeDoublePress
 double press detection time in milliseconds
 
uint16_t _timeLongPress
 long press time in milliseconds
 
uint16_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

- Protected Types inherited from MD_UISwitch
enum  state_fsm {
  S_IDLE , S_PRESS , S_PRESS2A , S_PRESS2B ,
  S_PRESSL , S_REPEAT , S_WAIT
}
 
enum  state_db { S_WAIT_START , S_DEBOUNCE , S_WAIT_RELEASE }
 
- Protected Member Functions inherited from MD_UISwitch
keyResult_t processFSM (bool swState, bool reset=false)
 
bool debounce (bool curStatus, bool reset=false)
 
- Static Protected Attributes inherited from MD_UISwitch
static const uint16_t KEY_PRESS_TIME = 150
 Default key press time in milliseconds.
 
static const uint16_t KEY_DPRESS_TIME = 250
 Default double press time between presses in milliseconds.
 
static const uint16_t KEY_LONGPRESS_TIME = 600
 Default long press detection time in milliseconds.
 
static const uint16_t KEY_REPEAT_TIME = 300
 Default time between repeats in in milliseconds.
 
static const uint8_t KEY_ACTIVE_STATE = LOW
 Default key is active low - transition high to low detection.
 
static const uint8_t REPEAT_RESULT_ENABLE = 3
 Internal status bit to return KS_REPEAT instead of KS_PRESS.
 
static const uint8_t DPRESS_ENABLE = 2
 Internal status bit to enable double press.
 
static const uint8_t LONGPRESS_ENABLE = 1
 Internal status bit to enable long press.
 
static const uint8_t REPEAT_ENABLE = 0
 Internal status bit to enable repeat key.
 

Detailed Description

Extension class MD_UISwitch_User.

Implements interface for user defined digital values. This provides the application flexibility to implement switches through I/O extenders and still maintain the same UISwitch interface.

When the current digital value is required a user defined callback function will be invoked to return the current active state of the digital I/O identified by specific id. This works very similar to the MD_UISwitch_Digital class but without direct I/O access.

Member Typedef Documentation

◆ cbUserData

typedef bool(* MD_UISwitch_User::cbUserData) (uint8_t id)

User data function prototype

The user data is returned from a callback function. The function must return the current value (true if the switch is active, false otherwise) of the digital identified by id.

Constructor & Destructor Documentation

◆ MD_UISwitch_User() [1/2]

MD_UISwitch_User::MD_UISwitch_User ( uint8_t  id,
cbUserData  cb 
)

Class Constructor - single id.

Instantiate a new instance of the class. The parameters passed are used to define the interface to the switch.

This form of the constructor is for a single digital id (ie, one switch).

Parameters
idthe switch identifier for this switch
cbthe callback to obtain the digital data state

◆ MD_UISwitch_User() [2/2]

MD_UISwitch_User::MD_UISwitch_User ( uint8_t *  ids,
uint8_t  idCount,
cbUserData  cb 
)

Class Constructor - array of id.

Instantiate a new instance of the class. The parameters passed are used to the interface hardware to the switch.

This form of the constructor is for an array of digital ids. The data is not copied from the user code, so the array elements need to remain in scope and constant for the life of the object.

Parameters
idspointer to array of switch identifiers for these switches
idCountthe number of id in the ids[] array
cbthe callback to obtain the digital data state

◆ ~MD_UISwitch_User()

MD_UISwitch_User::~MD_UISwitch_User ( )

Class Destructor.

Release allocated memory and does the necessary to clean up once the queue is no longer required.

Member Function Documentation

◆ begin()

void MD_UISwitch_User::begin ( void  )
virtual

Initialize the object.

Initialize the object data. This needs to be called during setup() to initialize new data for the class that cannot be done during the object creation.

Implements MD_UISwitch.

◆ read()

MD_UISwitch::keyResult_t MD_UISwitch_User::read ( void  )
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 recognized by a finite state machine whose operation is directed by the timer and option values specified.

Returns
one of the keyResult_t enumerated values

Implements MD_UISwitch.


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