-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouchManager.hpp
72 lines (55 loc) · 1.37 KB
/
touchManager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef TOUCH_MANAGER
#define TOUCH_MANAGER
#define SLIDE_UP 1
#define SLIDE_DOWN 2
#define SLIDE_RIGHT 3
#define SLIDE_LEFT 4
#define FLUIDITY 1
#define FLUIDITY_START 10
#define timeToWait 10
class TouchManager
{
public:
uint16_t getX();
uint16_t getY();
bool isTouch();
int16_t isSlidingHorizontally(bool force = false); // sliding right
int16_t isSlidingVertically(bool force = false); // sliding up
void resetScrollVertical();
void resetScrollHorizontal();
void update();
void calibrate();
byte stateSlider=0;
private:
bool isTouchRead();
bool validTouch();
uint16_t tx, ty;
bool stateTouch;
double lastClick = millis();
bool isPreviousTouch = 0;
unsigned long timerSlider;
uint16_t fx, fy = 0;
unsigned long timerUpdate = millis();
};
TouchManager touch;
class touchZone
{
public:
touchZone(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
{
this->x=x;
this->y=y;
this->width=width;
this->height=height;
}
bool isTouch()
{
uint16_t xx = touch.getX();
uint16_t yy = touch.getY();
return x<xx && xx<x+width && y<yy && yy<y+height;
}
private:
uint16_t x, y, width, height;
};
bool Touched(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
#endif // TOUCH_MANAGER