EX-Display
EX-Display
Loading...
Searching...
No Matches
InputInterface Class Referenceabstract

Class to abstract away all physical input implementatio to enable multiple input types Default return should be PRESS_NONE. More...

#include <InputInterface.h>

Inheritance diagram for InputInterface:
[legend]
Collaboration diagram for InputInterface:
[legend]

Public Member Functions

virtual void begin ()=0
 Perform any initial once off setup or configuration here and call only once.
 
virtual void check ()=0
 Call this method at least once per main loop to monitor for input actions Any actions should call the callback set in the _callback attribute.
 
void setCallback (CallbackInterface *callback)
 Set the instance for callbacks when users trigger an input action.
 
void setLogger (Logger *logger)
 Set the logger instance to use for diagnostic logging.
 
bool isCalibrating ()
 Test if this InputInterface is undergoing calibration as required by touch screens.
 
int needsDisplay ()
 Test if this InputInterface requires a display instance - needed for TFT_eSPI as it shares the instance.
 
void setDisplay (DisplayInterface *display)
 Set the DisplayInterface for this input if required.
 
void setDebounceDelay (unsigned long delay)
 Set the debounce delay.
 
void setHoldThreshold (unsigned long threshold)
 Set the threshold for detecting an input is held.
 
void forceCalibration ()
 Force a touch screen into calibration mode, even if existing calibration is valid.
 
virtual ~InputInterface ()=default
 Destructor for an InputInterface.
 

Protected Member Functions

InputAction _debounceOrHeld (InputAction currentAction)
 Call this from the derived class' check() method to debounce and detect if the input is a hold vs. press.
 
InputAction _calculateInputAction (int touchX, int touchY, int displayWidth, int displayHeight)
 This method is designed to take an input from a touch screen display and determine which "button" has been touched according to the coordinates of the touch. This assumes the touch screen has been calibrated correctly.
 

Protected Attributes

CallbackInterface_callback = nullptr
 Pointer to the instance for callbacks Must implement updateScreen() and onInputAction() methods.
 
Logger_logger = nullptr
 Pointer to the Logger instance for derived classes to use.
 
bool _isCalibrating = false
 Flag if the input interface is undergoing calibration - needed for touch screens.
 
int _needsDisplay = -1
 Display ID if this input interface requires a display instance - needed for TFT_eSPI as it shares the instance.
 
DisplayInterface_display = nullptr
 Pointer to the DisplayInterface if this input requires it.
 
unsigned long _lastDebounceTime = 0
 Time of the last debounce.
 
unsigned long _debounceDelay = 50
 Inputs must remain constant for this amount of time to be valid.
 
unsigned long _holdThreshold = 500
 Inputs constant for longer than this threshold change from PRESS to HOLD.
 
InputAction _lastAction = InputAction::PRESS_NONE
 Set initial InputAction for comparisons in determining debounce or hold.
 
bool _isHolding = false
 Flag to help determining if input is held.
 
bool _forceCalibration = false
 Flag to force calibration for touch screens if it's required.
 

Detailed Description

Class to abstract away all physical input implementatio to enable multiple input types Default return should be PRESS_NONE.

Constructor & Destructor Documentation

◆ ~InputInterface()

virtual InputInterface::~InputInterface ( )
virtualdefault

Destructor for an InputInterface.

Member Function Documentation

◆ _calculateInputAction()

InputAction InputInterface::_calculateInputAction ( int  touchX,
int  touchY,
int  displayWidth,
int  displayHeight 
)
protected

This method is designed to take an input from a touch screen display and determine which "button" has been touched according to the coordinates of the touch. This assumes the touch screen has been calibrated correctly.

The display is divided as such:

  • The entire left third of the display is the left button
  • The entire right third of the display is the right button
  • The top third of the resulting centre of the display is the up button
  • The bottom third of the resulting centre of the display is the down button
  • The centre third of both width and height is the centre button
    Parameters
    touchXThe X coordinate of the touch
    touchYThe Y coordinate of the touch
    displayWidthDisplay width in pixels
    displayHeightDisplay height in pixels
    Returns
    A valid InputAction PRESS type
Here is the caller graph for this function:

◆ _debounceOrHeld()

InputAction InputInterface::_debounceOrHeld ( InputAction  currentAction)
protected

Call this from the derived class' check() method to debounce and detect if the input is a hold vs. press.

Parameters
currentActionThe InputAction needing to be interpreted
Returns
Determined InputAction - either debounced press, held, or none
Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin()

virtual void InputInterface::begin ( )
pure virtual

Perform any initial once off setup or configuration here and call only once.

Implemented in TFT_eSPITouch.

Here is the caller graph for this function:

◆ check()

virtual void InputInterface::check ( )
pure virtual

Call this method at least once per main loop to monitor for input actions Any actions should call the callback set in the _callback attribute.

Implemented in MockButtonInput, MockTouchScreenInput, and TFT_eSPITouch.

Here is the caller graph for this function:

◆ forceCalibration()

void InputInterface::forceCalibration ( )

Force a touch screen into calibration mode, even if existing calibration is valid.

Here is the caller graph for this function:

◆ isCalibrating()

bool InputInterface::isCalibrating ( )

Test if this InputInterface is undergoing calibration as required by touch screens.

Returns
true|false
Here is the caller graph for this function:

◆ needsDisplay()

int InputInterface::needsDisplay ( )

Test if this InputInterface requires a display instance - needed for TFT_eSPI as it shares the instance.

Returns
Display ID of the required display - -1 if not required
Here is the caller graph for this function:

◆ setCallback()

void InputInterface::setCallback ( CallbackInterface callback)

Set the instance for callbacks when users trigger an input action.

Parameters
callbackClass instance derived from the CallbackInterface class Must call the method onInputAction(InputAction);
Here is the caller graph for this function:

◆ setDebounceDelay()

void InputInterface::setDebounceDelay ( unsigned long  delay)

Set the debounce delay.

Parameters
delayDebounce delay in milliseconds (default 50ms)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDisplay()

void InputInterface::setDisplay ( DisplayInterface display)

Set the DisplayInterface for this input if required.

Parameters
displayPointer to the DisplayInterface
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHoldThreshold()

void InputInterface::setHoldThreshold ( unsigned long  threshold)

Set the threshold for detecting an input is held.

Parameters
thresholdThreshold in milliseconds (default 500ms)
Here is the caller graph for this function:

◆ setLogger()

void InputInterface::setLogger ( Logger logger)

Set the logger instance to use for diagnostic logging.

Parameters
loggerPointer to the Logger instance to use
Here is the caller graph for this function:

Member Data Documentation

◆ _callback

CallbackInterface* InputInterface::_callback = nullptr
protected

Pointer to the instance for callbacks Must implement updateScreen() and onInputAction() methods.

◆ _debounceDelay

unsigned long InputInterface::_debounceDelay = 50
protected

Inputs must remain constant for this amount of time to be valid.

◆ _display

DisplayInterface* InputInterface::_display = nullptr
protected

Pointer to the DisplayInterface if this input requires it.

◆ _forceCalibration

bool InputInterface::_forceCalibration = false
protected

Flag to force calibration for touch screens if it's required.

◆ _holdThreshold

unsigned long InputInterface::_holdThreshold = 500
protected

Inputs constant for longer than this threshold change from PRESS to HOLD.

◆ _isCalibrating

bool InputInterface::_isCalibrating = false
protected

Flag if the input interface is undergoing calibration - needed for touch screens.

◆ _isHolding

bool InputInterface::_isHolding = false
protected

Flag to help determining if input is held.

◆ _lastAction

InputAction InputInterface::_lastAction = InputAction::PRESS_NONE
protected

Set initial InputAction for comparisons in determining debounce or hold.

◆ _lastDebounceTime

unsigned long InputInterface::_lastDebounceTime = 0
protected

Time of the last debounce.

◆ _logger

Logger* InputInterface::_logger = nullptr
protected

Pointer to the Logger instance for derived classes to use.

◆ _needsDisplay

int InputInterface::_needsDisplay = -1
protected

Display ID if this input interface requires a display instance - needed for TFT_eSPI as it shares the instance.


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