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
31
class
MockTouchScreenInput
:
public
InputInterface
{
32
public
:
33
MOCK_METHOD
(
void
,
begin
, (), (
override
));
34
35
void
check
()
override
{
36
InputAction
action =
_calculateInputAction
(
_touchX
,
_touchY
,
_screenWidth
,
_screenHeight
);
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
57
void
setIsCalibrating
(
bool
isCalibrating
) {
_isCalibrating
=
isCalibrating
; }
58
59
void
setNeedsDisplay
(
int
displayId) {
_needsDisplay
= displayId; }
60
61
private
:
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
CallbackInterface.h
InputAction
InputAction
Input action to be returned from the user interface to control screens and displays.
Definition
InputActions.h:22
PRESS_NONE
@ PRESS_NONE
Definition
InputActions.h:23
InputInterface.h
CallbackInterface::onInputAction
virtual void onInputAction(InputAction action)=0
Method to implement to respond to an input action.
InputInterface
Class to abstract away all physical input implementatio to enable multiple input types Default return...
Definition
InputInterface.h:28
InputInterface::begin
virtual void begin()=0
Perform any initial once off setup or configuration here and call only once.
InputInterface::_isCalibrating
bool _isCalibrating
Flag if the input interface is undergoing calibration - needed for touch screens.
Definition
InputInterface.h:79
InputInterface::_needsDisplay
int _needsDisplay
Display ID if this input interface requires a display instance - needed for TFT_eSPI as it shares the...
Definition
InputInterface.h:82
InputInterface::_callback
CallbackInterface * _callback
Pointer to the instance for callbacks Must implement updateScreen() and onInputAction() methods.
Definition
InputInterface.h:75
InputInterface::_calculateInputAction
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
InputInterface::isCalibrating
bool isCalibrating()
Test if this InputInterface is undergoing calibration as required by touch screens.
Definition
InputInterface.cpp:24
InputInterface::_debounceOrHeld
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
MockTouchScreenInput
Mock touch screen input class using debounce and hold methods and calculating touch position to deter...
Definition
MockTouchScreenInput.h:31
MockTouchScreenInput::_screenWidth
int _screenWidth
Definition
MockTouchScreenInput.h:62
MockTouchScreenInput::setNeedsDisplay
void setNeedsDisplay(int displayId)
Definition
MockTouchScreenInput.h:59
MockTouchScreenInput::setScreenResolution
void setScreenResolution(int width, int height)
Definition
MockTouchScreenInput.h:45
MockTouchScreenInput::setDebounceHold
void setDebounceHold(bool debounceHold)
Definition
MockTouchScreenInput.h:55
MockTouchScreenInput::MOCK_METHOD
MOCK_METHOD(void, begin,(),(override))
MockTouchScreenInput::_screenHeight
int _screenHeight
Definition
MockTouchScreenInput.h:63
MockTouchScreenInput::setTouch
void setTouch(int touchX, int touchY)
Definition
MockTouchScreenInput.h:50
MockTouchScreenInput::setIsCalibrating
void setIsCalibrating(bool isCalibrating)
Definition
MockTouchScreenInput.h:57
MockTouchScreenInput::_debounceHold
bool _debounceHold
Definition
MockTouchScreenInput.h:66
MockTouchScreenInput::_touchX
int _touchX
Definition
MockTouchScreenInput.h:64
MockTouchScreenInput::_touchY
int _touchY
Definition
MockTouchScreenInput.h:65
MockTouchScreenInput::check
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
test
mocks
MockTouchScreenInput.h
Generated by
1.9.8