7
7
*--------------------------------------------------------------------------------*/
8
8
typedef struct TouchConfig {
9
9
// Member variables
10
- uint16_t cal[8 ];
11
- int8_t offset[2 ];
10
+ #if defined (LOVYANGFX_HPP_) || defined (_TFT_eSPIH_)
11
+ uint16_t cal[8 ];
12
+ #elif defined (_XPT2046_Touchscreen_h_)
13
+ float cal[8 ];
14
+ #else
15
+ #error Unsupported touch screen library
16
+ #endif
17
+ int8_t offset[2 ];
12
18
13
19
// Comparison operator
14
20
bool operator >= (TouchConfig &RHS) {
@@ -28,20 +34,30 @@ typedef struct TouchConfig {
28
34
*--------------------------------------------------------------------------------*/
29
35
TouchConfig_t tch_cnf = {
30
36
#if defined (LOVYANGFX_HPP_)
37
+
38
+ // LovyanGFX
31
39
.cal = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
40
+
32
41
#elif defined (_TFT_eSPIH_)
42
+
43
+ // TFT_eSPI
33
44
.cal = { 0 , 0 , 0 , 0 , 0 , },
45
+
34
46
#else // defined (_XPT2046_Touchscreen_h_)
47
+
48
+ // XPT2046_Touchscreen
35
49
.cal = { 0 , },
50
+
36
51
#endif
52
+
37
53
.offset = { 0 , },
38
54
};
39
55
40
56
/* --------------------------------------------------------------------------------
41
57
* Event definition
42
58
*--------------------------------------------------------------------------------*/
43
- #define PERIOD_DEBOUNCE 25 // [msec]
44
- #define PERIOD_TOUCHED 50 // [msec]
59
+ #define PERIOD_DEBOUNCE 25 // [msec]
60
+ #define PERIOD_TOUCHED 50 // [msec]
45
61
#define PERIOD_TAP2 200 // [msec]
46
62
#define PERIOD_CLEAR_EVENT 100 // [msec]
47
63
@@ -51,7 +67,7 @@ typedef enum {
51
67
EVENT_FALLING = (0x02 ), // untouch --> touch
52
68
EVENT_TOUCHED = (0x04 ), // touch --> touch
53
69
EVENT_TAP2 = (0x08 ), // double tap
54
- EVENT_WATCH = (0x10 ), // execute a callback every watch cycle
70
+ EVENT_EXPAND = (0x10 ), // not a touch event, but define for convenience
55
71
56
72
// alias
57
73
EVENT_INIT = (EVENT_NONE),
@@ -63,6 +79,8 @@ typedef enum {
63
79
EVENT_CHANGE = (EVENT_FALLING | EVENT_RISING),
64
80
EVENT_SELECT = (EVENT_FALLING | EVENT_TAP2),
65
81
EVENT_ALL = (EVENT_FALLING | EVENT_RISING | EVENT_TOUCHED),
82
+ EVENT_WATCH = (EVENT_EXPAND), // watch events on a specific screen
83
+ EVENT_SHOW = (EVENT_EXPAND), // show something on a specific screen
66
84
} Event_t;
67
85
68
86
typedef struct Touch {
@@ -221,6 +239,10 @@ void touch_clear(void) {
221
239
* Calibrating the touch panel
222
240
*--------------------------------------------------------------------------------*/
223
241
void touch_calibrate (TouchConfig_t *config) {
242
+ if (!Serial) {
243
+ Serial.begin (115200 );
244
+ }
245
+
224
246
#if defined (_XPT2046_Touchscreen_h_)
225
247
226
248
#elif defined (LOVYANGFX_HPP_)
@@ -233,14 +255,12 @@ void touch_calibrate(TouchConfig_t *config) {
233
255
GFX_EXEC (setTextDatum (textdatum_t ::top_left));
234
256
GFX_EXEC (calibrateTouch (config->cal , TFT_WHITE, TFT_BLACK, std::max (lcd_width, lcd_height) >> 3 ));
235
257
236
- DBG_EXEC ({
237
- printf (" \n // LovyanGFX\n " );
238
- printf (" .cal = { " );
239
- for (uint8_t i = 0 ; i < 8 ; ++i) {
240
- printf (" %d\n " , config->cal [i]);
241
- printf (i < 7 ? " , " : " },\n " );
242
- }
243
- });
258
+ printf (" \n // LovyanGFX\n " );
259
+ printf (" .cal = { " );
260
+ for (uint8_t i = 0 ; i < 8 ; ++i) {
261
+ printf (" %d" , config->cal [i]);
262
+ printf (i < 7 ? " , " : " },\n " );
263
+ }
244
264
245
265
#elif defined (_TFT_eSPIH_)
246
266
@@ -252,14 +272,12 @@ void touch_calibrate(TouchConfig_t *config) {
252
272
GFX_EXEC (println (" Touch corners in order" ));
253
273
GFX_EXEC (calibrateTouch (config->cal , TFT_MAGENTA, TFT_BLACK, 15 ));
254
274
255
- DBG_EXEC ({
256
- printf (" \n // TFT_eSPI\n " );
257
- printf (" .cal = { " );
258
- for (uint8_t i = 0 ; i < 5 ; ++i) {
259
- printf (" %d\n " , config->cal [i]);
260
- printf (i < 4 ? " , " : " 0, },\n " );
261
- }
262
- });
275
+ printf (" \n // TFT_eSPI\n " );
276
+ printf (" .cal = { " );
277
+ for (uint8_t i = 0 ; i < 5 ; ++i) {
278
+ printf (" %d" , config->cal [i]);
279
+ printf (i < 4 ? " , " : " 0, },\n " );
280
+ }
263
281
264
282
#endif
265
283
0 commit comments