EX-Display
EX-Display
Loading...
Searching...
No Matches
/home/runner/work/EX-Display/EX-Display/InputInterface.h
Go to the documentation of this file.
1/*
2 * © 2024 Peter Cole
3 *
4 * This is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * It is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this code. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef INPUTINTERFACE_H
19#define INPUTINTERFACE_H
20
21#include "CallbackInterface.h"
22#include "DisplayInterface.h"
23#include "InputActions.h"
24#include "Logger.h"
25
29public:
31 virtual void begin() = 0;
32
35 virtual void check() = 0;
36
40 void setCallback(CallbackInterface *callback);
41
44 void setLogger(Logger *logger);
45
48 bool isCalibrating();
49
52 int needsDisplay();
53
56 void setDisplay(DisplayInterface *display);
57
60 void setDebounceDelay(unsigned long delay);
61
64 void setHoldThreshold(unsigned long threshold);
65
67 void forceCalibration();
68
70 virtual ~InputInterface() = default;
71
72protected:
77 Logger *_logger = nullptr;
79 bool _isCalibrating = false;
82 int _needsDisplay = -1;
86 unsigned long _lastDebounceTime = 0;
88 unsigned long _debounceDelay = 50;
90 unsigned long _holdThreshold = 500;
94 bool _isHolding = false;
96 bool _forceCalibration = false;
97
102
116 InputAction _calculateInputAction(int touchX, int touchY, int displayWidth, int displayHeight);
117};
118
119#endif // INPUTINTERFACE_H
void delay(unsigned long ms)
Definition Arduino.h:62
InputAction
Input action to be returned from the user interface to control screens and displays.
Definition InputActions.h:22
@ PRESS_NONE
Definition InputActions.h:23
Interface class to use for callbacks.
Definition CallbackInterface.h:26
Class to abstract away all physical display implementation to enable multiple display types.
Definition DisplayInterface.h:36
Class to abstract away all physical input implementatio to enable multiple input types Default return...
Definition InputInterface.h:28
DisplayInterface * _display
Pointer to the DisplayInterface if this input requires it.
Definition InputInterface.h:84
int needsDisplay()
Test if this InputInterface requires a display instance - needed for TFT_eSPI as it shares the instan...
Definition InputInterface.cpp:26
bool _isHolding
Flag to help determining if input is held.
Definition InputInterface.h:94
virtual void begin()=0
Perform any initial once off setup or configuration here and call only once.
void setDebounceDelay(unsigned long delay)
Set the debounce delay.
Definition InputInterface.cpp:36
bool _forceCalibration
Flag to force calibration for touch screens if it's required.
Definition InputInterface.h:96
Logger * _logger
Pointer to the Logger instance for derived classes to use.
Definition InputInterface.h:77
bool _isCalibrating
Flag if the input interface is undergoing calibration - needed for touch screens.
Definition InputInterface.h:79
void forceCalibration()
Force a touch screen into calibration mode, even if existing calibration is valid.
Definition InputInterface.cpp:40
void setDisplay(DisplayInterface *display)
Set the DisplayInterface for this input if required.
Definition InputInterface.cpp:28
InputAction _lastAction
Set initial InputAction for comparisons in determining debounce or hold.
Definition InputInterface.h:92
void setHoldThreshold(unsigned long threshold)
Set the threshold for detecting an input is held.
Definition InputInterface.cpp:38
unsigned long _holdThreshold
Inputs constant for longer than this threshold change from PRESS to HOLD.
Definition InputInterface.h:90
void setCallback(CallbackInterface *callback)
Set the instance for callbacks when users trigger an input action.
Definition InputInterface.cpp:20
int _needsDisplay
Display ID if this input interface requires a display instance - needed for TFT_eSPI as it shares the...
Definition InputInterface.h:82
void setLogger(Logger *logger)
Set the logger instance to use for diagnostic logging.
Definition InputInterface.cpp:22
unsigned long _lastDebounceTime
Time of the last debounce.
Definition InputInterface.h:86
CallbackInterface * _callback
Pointer to the instance for callbacks Must implement updateScreen() and onInputAction() methods.
Definition InputInterface.h:75
unsigned long _debounceDelay
Inputs must remain constant for this amount of time to be valid.
Definition InputInterface.h:88
virtual ~InputInterface()=default
Destructor for an InputInterface.
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...
Definition InputInterface.cpp:93
bool isCalibrating()
Test if this InputInterface is undergoing calibration as required by touch screens.
Definition InputInterface.cpp:24
virtual void check()=0
Call this method at least once per main loop to monitor for input actions Any actions should call the...
InputAction _debounceOrHeld(InputAction currentAction)
Call this from the derived class' check() method to debounce and detect if the input is a hold vs....
Definition InputInterface.cpp:42
Class to enable simple logging to a Stream object with different log levels This enables embedding pe...
Definition Logger.h:35