Fri, 28 Jun 2024 15:33:24 +0200
Fixed changing runtime datarecord size during switching between IDF 4.2 and 5.1. Fixed wiping the /spiffs filesystem. The directory listing from the SD card doesn't overwrite parts of the screen anymore. Solved the slow speed issue with the SD card. Try to force the SD card to operate at 20 MHz. More project settings changed to improve performance and memory usage.
0 | 1 | /** |
2 | * @file calibration.c | |
3 | * @brief TFT screen calibration. | |
4 | */ | |
5 | ||
6 | #include "config.h" | |
7 | ||
8 | ||
9 | static const char *TAG = "calibration"; | |
10 | ||
129 | 11 | extern my_config_t config; |
0 | 12 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
13 | extern uint16_t tp_xleft; ///< Testpoint X left |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
14 | extern uint16_t tp_xright; ///< Testpoint X right |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
15 | extern uint16_t tp_ytop; ///< Testpoint Y top |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
16 | extern uint16_t tp_ybottom; ///< Testpoint Y bottom |
0 | 17 | |
18 | ||
19 | // Distance of the testpoints from the corders. | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
20 | #define CAL_DISTANCE 15 ///< Testpoint size |
0 | 21 | |
22 | ||
23 | int TS_set_calibration(int xleft, int xright, int ytop, int ybottom) | |
24 | { | |
25 | if ((xleft > xright) || (ybottom > ytop)) { | |
26 | ESP_LOGE(TAG, "Touch Calibration error X=%d..%d Y=%d..%d", xleft, xright, ybottom, ytop); | |
27 | return 1; | |
28 | } | |
29 | ||
30 | tp_xleft = xleft; | |
31 | tp_xright = xright; | |
32 | tp_ytop = ytop; | |
33 | tp_ybottom = ybottom; | |
34 | ESP_LOGI(TAG, "Touch Calibration X=%d..%d Y=%d..%d", xleft, xright, ybottom, ytop); | |
35 | ||
36 | return 0; | |
37 | } | |
38 | ||
39 | ||
40 | ||
41 | void Calibration_Init(void) | |
42 | { | |
43 | _fg = TFT_ORANGE; | |
44 | TFT_setFont(DEJAVU24_FONT, NULL); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
45 | TFT_print((char *)"Scherm calibratie", CENTER, 60); |
0 | 46 | TFT_setFont(DEJAVU18_FONT, NULL); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
47 | TFT_print((char *)"Druk op de oplichtende stippen", CENTER, 90); |
0 | 48 | } |
49 | ||
50 | ||
51 | ||
52 | /* | |
53 | * Run in a blocking loop | |
54 | */ | |
55 | void Calibration_Loop(void) | |
56 | { | |
57 | int tx, ty, pass, cx[8], cy[8], xl = 0, xh = 0, yl = 0, yh = 0; | |
58 | int offset; | |
59 | ||
60 | pass = 0; | |
61 | ESP_LOGI(TAG, "Touchscreen calibration"); | |
62 | ||
63 | while (1) { | |
64 | switch (pass) { | |
65 | case 0: | |
66 | case 4: TFT_fillCircle(320 - CAL_DISTANCE, 240 - CAL_DISTANCE, 5, TFT_BLACK); | |
67 | TFT_fillCircle(CAL_DISTANCE, CAL_DISTANCE, 5, TFT_YELLOW); | |
68 | xl = 2800; | |
69 | xh = 3800; | |
70 | yl = 2800; | |
71 | yh = 3800; | |
72 | break; | |
73 | case 1: | |
74 | case 5: TFT_fillCircle(CAL_DISTANCE, CAL_DISTANCE, 5, TFT_BLACK); | |
75 | TFT_fillCircle(320 - CAL_DISTANCE, CAL_DISTANCE, 5, TFT_YELLOW); | |
76 | xl = 2800; | |
77 | xh = 3800; | |
78 | yl = 100; | |
79 | yh = 1000; | |
80 | break; | |
81 | case 2: | |
82 | case 6: TFT_fillCircle(320 - CAL_DISTANCE, CAL_DISTANCE, 5, TFT_BLACK); | |
83 | TFT_fillCircle(CAL_DISTANCE, 240 - CAL_DISTANCE, 5, TFT_YELLOW); | |
84 | xl = 100; | |
85 | xh = 1000; | |
86 | yl = 2800; | |
87 | yh = 3800; | |
88 | break; | |
89 | case 3: | |
90 | case 7: TFT_fillCircle(CAL_DISTANCE, 240 - CAL_DISTANCE, 5, TFT_BLACK); | |
91 | TFT_fillCircle(320 - CAL_DISTANCE, 240 - CAL_DISTANCE, 5, TFT_YELLOW); | |
92 | xl = 100; | |
93 | xh = 1000; | |
94 | yl = 100; | |
95 | yh = 1000; | |
96 | break; | |
97 | } | |
98 | if (TFT_read_touch(&tx, &ty, 1)) { // Raw read touch. | |
99 | printf(" Calibrarion loop %d %d %d\n", pass, tx, ty); | |
100 | if ((tx >= xl) && (tx <= xh) && (ty >= yl) && (ty <= yh)) { | |
101 | cx[pass] = tx; | |
102 | cy[pass] = ty; | |
103 | pass++; | |
104 | if (pass == 8) { | |
105 | break; | |
106 | } | |
107 | } else { | |
108 | SoundPlay(SOUND_Warn); | |
109 | } | |
110 | WaitTouchReleased(); | |
111 | } | |
112 | vTaskDelay(100 / portTICK_PERIOD_MS); | |
113 | } | |
114 | ||
115 | TFT_fillScreen(TFT_BLACK); | |
116 | TFT_setFont(DEJAVU18_FONT, NULL); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
117 | TFT_print((char *)"Scherm calibratie is klaar.", CENTER, 60); |
0 | 118 | /* |
119 | * Calculate the new calibration values. | |
120 | * The testdots were 10 pixels of the corners, | |
121 | * so take that in account. | |
122 | */ | |
123 | offset = (CAL_DISTANCE * 3800) / 240; | |
124 | config.ts_xleft = ((cx[2] + cx[3] + cx[6] + cx[7]) / 4) - offset; | |
125 | config.ts_xright = ((cx[0] + cx[1] + cx[4] + cx[5]) / 4) + offset; | |
126 | offset = (CAL_DISTANCE * 3800) / 320; | |
127 | config.ts_ytop = ((cy[0] + cy[2] + cy[4] + cy[6]) / 4) + offset; | |
128 | config.ts_ybottom = ((cy[1] + cy[3] + cy[5] + cy[7]) / 4) - offset; | |
129 | TS_set_calibration(config.ts_xleft, config.ts_xright, config.ts_ytop, config.ts_ybottom); | |
130 | write_config(); | |
131 | ||
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
132 | Buttons_Add(130, 200, 60, 40, (char *)"Ok", 0); |
0 | 133 | Buttons_Show(); |
134 | while (1) { | |
135 | vTaskDelay(20 / portTICK_PERIOD_MS); | |
136 | if (Buttons_Scan() == 0) { | |
137 | return; | |
138 | break; | |
139 | } | |
140 | } | |
141 | } | |
142 | ||
143 |