EX-Display
EX-Display
Loading...
Searching...
No Matches
MockTouchScreenInput.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 MOCKTOUCHSCREENINPUT_H
19#define MOCKTOUCHSCREENINPUT_H
20
21#include "CallbackInterface.h"
22#include "InputInterface.h"
23#include <gmock/gmock.h>
24
32public:
33 MOCK_METHOD(void, begin, (), (override));
34
35 void check() override {
37 if (_debounceHold) {
38 action = _debounceOrHeld(action);
39 }
40 if (action != InputAction::PRESS_NONE && _callback != nullptr) {
41 _callback->onInputAction(action);
42 }
43 }
44
45 void setScreenResolution(int width, int height) {
46 _screenWidth = width;
47 _screenHeight = height;
48 }
49
50 void setTouch(int touchX, int touchY) {
51 _touchX = touchX;
52 _touchY = touchY;
53 }
54
55 void setDebounceHold(bool debounceHold) { _debounceHold = debounceHold; }
56
58
59 void setNeedsDisplay(int displayId) { _needsDisplay = displayId; }
60
61private:
62 int _screenWidth = 320;
63 int _screenHeight = 240;
64 int _touchX = 0;
65 int _touchY = 0;
66 bool _debounceHold = false;
67};
68
69#endif // MOCKTOUCHSCREENINPUT_H
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
virtual void onInputAction(InputAction action)=0
Method to implement to respond to an input action.
Class to abstract away all physical input implementatio to enable multiple input types Default return...
Definition InputInterface.h:28
virtual void begin()=0
Perform any initial once off setup or configuration here and call only once.
bool _isCalibrating
Flag if the input interface is undergoing calibration - needed for touch screens.
Definition InputInterface.h:79
int _needsDisplay
Display ID if this input interface requires a display instance - needed for TFT_eSPI as it shares the...
Definition InputInterface.h:82
CallbackInterface * _callback
Pointer to the instance for callbacks Must implement updateScreen() and onInputAction() methods.
Definition InputInterface.h:75
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
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
Mock touch screen input class using debounce and hold methods and calculating touch position to deter...
Definition MockTouchScreenInput.h:31
int _screenWidth
Definition MockTouchScreenInput.h:62
void setNeedsDisplay(int displayId)
Definition MockTouchScreenInput.h:59
void setScreenResolution(int width, int height)
Definition MockTouchScreenInput.h:45
void setDebounceHold(bool debounceHold)
Definition MockTouchScreenInput.h:55
MOCK_METHOD(void, begin,(),(override))
int _screenHeight
Definition MockTouchScreenInput.h:63
void setTouch(int touchX, int touchY)
Definition MockTouchScreenInput.h:50
void setIsCalibrating(bool isCalibrating)
Definition MockTouchScreenInput.h:57
bool _debounceHold
Definition MockTouchScreenInput.h:66
int _touchX
Definition MockTouchScreenInput.h:64
int _touchY
Definition MockTouchScreenInput.h:65
void check() override
Call this method at least once per main loop to monitor for input actions Any actions should call the...
Definition MockTouchScreenInput.h:35