-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTouchScreenManager.cpp
86 lines (68 loc) · 2.61 KB
/
TouchScreenManager.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Arduino.h"
#include "TouchScreenManager.h"
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
#define MINPRESSURE 10
#define MAXPRESSURE 1000
#define TFT_HEIGHT 240
#define TFT_WIDTH 320
#define TOUCH_MIN_DURATION 100 // millisecond
#define NEXT_TRACK_AREA_XM 0
#define NEXT_TRACK_AREA_XP 35
#define NEXT_TRACK_AREA_YM 0
#define NEXT_TRACK_AREA_YP 70
#define PREV_TRACK_AREA_XM 0
#define PREV_TRACK_AREA_XP 35
#define PREV_TRACK_AREA_YM 76
#define PREV_TRACK_AREA_YP 146
#define TIMER_AREA_XM 103
#define TIMER_AREA_XP 215
#define TIMER_AREA_YM 83
#define TIMER_AREA_YP 210
#define LAP_DELAY_AREA_XM 253
#define LAP_DELAY_AREA_XP 285
#define LAP_DELAY_AREA_YM 54
#define LAP_DELAY_AREA_YP 165
#define DEBUG_TOUCH false
TouchScreenManager::TouchScreenManager(TouchScreen* ts) {
this->touchScreen = ts;
lastPoint = Point(0, 0, 0);
}
TouchScreenManager::~TouchScreenManager() { }
int TouchScreenManager::getChronoOperation() {
int operation = 0;
Point p = this->touchScreen->getPoint();
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z < MINPRESSURE || p.z > MAXPRESSURE) {
if(touchStarted && (millis() - touchStartedTimestamp) > TOUCH_MIN_DURATION) {
touchStarted = false;
operation = checkChronoOperation();
}
} else {
touchStarted = true;
touchStartedTimestamp = millis();
// Scale from ~0->1000 to tft.width using the calibration #'s
lastPoint.x = map(p.x, TS_MINX, TS_MAXX, 0, TFT_WIDTH);
lastPoint.y = map(p.y, TS_MINY, TS_MAXY, 0, TFT_HEIGHT);
#if DEBUG_TOUCH
Serial.print("X = "); Serial.print(lastPoint.x);
Serial.print("\tY = "); Serial.print(lastPoint.y);
Serial.print("\tPressure = "); Serial.println(p.z);
#endif
}
return operation;
}
int TouchScreenManager::checkChronoOperation() {
// Next Track
if(lastPoint.x > NEXT_TRACK_AREA_XM && lastPoint.x < NEXT_TRACK_AREA_XP && lastPoint.y > NEXT_TRACK_AREA_YM && lastPoint.y < NEXT_TRACK_AREA_YP) { return OPERATION_NEXT_TRACK; }
// Prev Track
if(lastPoint.x > PREV_TRACK_AREA_XM && lastPoint.x < PREV_TRACK_AREA_XP && lastPoint.y > PREV_TRACK_AREA_YM && lastPoint.y < PREV_TRACK_AREA_YP) { return OPERATION_PREV_TRACK; }
// Change lapTimer state
if(lastPoint.x > TIMER_AREA_XM && lastPoint.x < TIMER_AREA_XP && lastPoint.y > TIMER_AREA_YM && lastPoint.y < TIMER_AREA_YP) { return OPERATION_CHANGE_TIMER_STATE; }
// Change lapDelay state
if(lastPoint.x > LAP_DELAY_AREA_XM && lastPoint.x < LAP_DELAY_AREA_XP && lastPoint.y > LAP_DELAY_AREA_YM && lastPoint.y < LAP_DELAY_AREA_YP) { return OPERATION_CHANGE_LAP_DELAY_STATE; }
return OPERATION_NO_OPERATION;
}