forked from DustinWatts/FreeTouchDeck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Touch.h
74 lines (66 loc) · 1.55 KB
/
Touch.h
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
/**
* @brief This function presents the user with 4 points to touch and saves
that data to a claibration file.
*
* @param none
*
* @return none
*
* @note If USECAPTOUCH is defined we do not need to calibrate touch
*/
void touch_calibrate()
{
uint16_t calData[5];
uint8_t calDataOK = 0;
// check if calibration file exists and size is correct
if (FILESYSTEM.exists(CALIBRATION_FILE))
{
if (REPEAT_CAL)
{
// Delete if we want to re-calibrate
FILESYSTEM.remove(CALIBRATION_FILE);
}
else
{
File f = FILESYSTEM.open(CALIBRATION_FILE, "r");
if (f)
{
if (f.readBytes((char *)calData, 14) == 14)
calDataOK = 1;
f.close();
}
}
}
if (calDataOK && !REPEAT_CAL)
{
// calibration data valid
tft.setTouch(calData);
}
else
{
// data not valid so recalibrate
tft.fillScreen(TFT_BLACK);
tft.setCursor(20, 0);
tft.setTextFont(2);
tft.setTextSize(1);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.println("Touch corners as indicated");
tft.setTextFont(1);
tft.println();
if (REPEAT_CAL)
{
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.println("Set REPEAT_CAL to false to stop this running again!");
}
tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.println("Calibration complete!");
// store data
File f = FILESYSTEM.open(CALIBRATION_FILE, "w");
if (f)
{
f.write((const unsigned char *)calData, 14);
f.close();
}
}
}