1
+ #include " display.h"
2
+
3
+ const int lineSpacing = 20 ; // Set the line spacing for the display
4
+ const int leftMargin = 10 ; // Set the left margin for the display
5
+ const int infoAreaTop = 0 ; // Top position of the GPS info area
6
+ const int infoAreaHeight = 100 ; // Height of the GPS info area
7
+ int lastSecond = -1 ;
8
+ int brightness = M5Cardputer.Display.getBrightness();
9
+
10
+
11
+ void displayWelcomeScreen () {
12
+ M5Cardputer.Display .setRotation (1 );
13
+
14
+ M5Cardputer.Display .drawRect (20 , 20 , 200 , 40 , TFT_LIGHTGRAY);
15
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
16
+ M5Cardputer.Display .setCursor (32 , 28 );
17
+ M5Cardputer.Display .setTextSize (3.4 );
18
+ M5Cardputer.Display .printf (" GPS to SD" );
19
+
20
+ M5Cardputer.Display .setTextSize (1.2 );
21
+ M5Cardputer.Display .setCursor (20 ,70 );
22
+ M5Cardputer.Display .setTextColor (TFT_ORANGE);
23
+ M5Cardputer.Display .printf (" Save GPS data" );
24
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
25
+ M5Cardputer.Display .printf (" to your SD card" );
26
+ M5Cardputer.Display .setCursor (26 , 85 );
27
+ M5Cardputer.Display .printf (" in a .csv file" );
28
+ M5Cardputer.Display .setTextColor (TFT_ORANGE);
29
+ M5Cardputer.Display .printf (" every minute" );
30
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
31
+ delay (1000 );
32
+ }
33
+
34
+ void displaySaveState (bool isSdSaving) {
35
+ M5Cardputer.Display .fillRect (180 , infoAreaHeight, M5Cardputer.Display .width (), M5Cardputer.Display .height (), TFT_BLACK); // Reset area
36
+
37
+ M5Cardputer.Display .drawRect (20 , 104 , 150 , 1 , TFT_DARKGRAY); // delimiter
38
+
39
+ M5Cardputer.Display .setTextSize (1 );
40
+ M5Cardputer.Display .setCursor (20 , 110 );
41
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
42
+ M5Cardputer.Display .printf (" Log on SD each min [ ok ]" );
43
+
44
+ if (isSdSaving) {
45
+ M5Cardputer.Display .drawRect (178 , 103 , 35 , 27 , TFT_GREEN);
46
+ M5Cardputer.Display .setCursor (189 , 113 );
47
+ M5Cardputer.Display .setTextColor (TFT_GREEN);
48
+ M5Cardputer.Display .printf (" ON" );
49
+ } else {
50
+ M5Cardputer.Display .drawRect (178 , 103 , 35 , 27 , TFT_RED);
51
+ M5Cardputer.Display .setCursor (187 , 113 );
52
+ M5Cardputer.Display .setTextColor (TFT_RED);
53
+ M5Cardputer.Display .printf (" OFF" );
54
+ }
55
+ M5Cardputer.Display .setCursor (20 , 122 );
56
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
57
+ M5Cardputer.Display .printf (" Turn off the screen [ S ]" );
58
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
59
+ }
60
+
61
+
62
+ void displaySelectionScreen (bool isSleepMode) {
63
+ M5Cardputer.Display .clear ();
64
+ M5Cardputer.Display .setTextSize (1.5 );
65
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
66
+ M5Cardputer.Display .setCursor (70 , 10 );
67
+ M5Cardputer.Display .printf (" Select Mode:" );
68
+ M5Cardputer.Display .setTextSize (3 );
69
+
70
+ // Draw Normal Mode Button
71
+ if (isSleepMode == false ) {
72
+ M5Cardputer.Display .fillRect (20 , 30 , 200 , 40 , TFT_LIGHTGRAY);
73
+ M5Cardputer.Display .drawRect (20 , 30 , 200 , 40 , TFT_BLACK);
74
+ M5Cardputer.Display .setTextColor (TFT_BLACK);
75
+ } else {
76
+ M5Cardputer.Display .fillRect (20 , 30 , 200 , 40 , TFT_BLACK);
77
+ M5Cardputer.Display .drawRect (20 , 30 , 200 , 40 , TFT_LIGHTGRAY);
78
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
79
+ }
80
+ M5Cardputer.Display .setCursor (70 , 40 );
81
+ M5Cardputer.Display .printf (" Normal" );
82
+
83
+ // Draw Sleep Mode Button
84
+ if (isSleepMode == true ) {
85
+ M5Cardputer.Display .fillRect (20 , 80 , 200 , 40 , TFT_LIGHTGRAY);
86
+ M5Cardputer.Display .drawRect (20 , 80 , 200 , 40 , TFT_BLACK);
87
+ M5Cardputer.Display .setTextColor (TFT_BLACK);
88
+ } else {
89
+ M5Cardputer.Display .fillRect (20 , 80 , 200 , 40 , TFT_BLACK);
90
+ M5Cardputer.Display .drawRect (20 , 80 , 200 , 40 , TFT_LIGHTGRAY);
91
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
92
+ }
93
+ M5Cardputer.Display .setCursor (77 , 90 );
94
+ M5Cardputer.Display .printf (" Sleep" );
95
+ }
96
+
97
+
98
+ void displayNormalScreen (TinyGPSPlus &gps) {
99
+ int currentLine = 0 ;
100
+ int margin = 20 ;
101
+ int spacing = 17 ;
102
+
103
+ int currentSecond = gps.time .second ();
104
+
105
+ // Vérifier si 3 secondes se sont écoulées depuis la dernière exécution
106
+ if ((currentSecond < lastSecond && (currentSecond + 60 - lastSecond) < 3 ) ||
107
+ (currentSecond >= lastSecond && (currentSecond - lastSecond) < 3 )) {
108
+
109
+ if (lastSecond != -1 ) // if -1, it's the first render
110
+ return ;
111
+ }
112
+
113
+ lastSecond = currentSecond;
114
+
115
+ M5Cardputer.Display .fillRect (0 , infoAreaTop, M5Cardputer.Display .width (), infoAreaHeight, TFT_BLACK); // Clear the info area
116
+ M5Cardputer.Display .setTextSize (2 );
117
+
118
+ M5Cardputer.Display .setCursor (margin, spacing * currentLine++);
119
+ M5Cardputer.Display .printf (" Lat: %.8f" , gps.location .lat ()); // Print the latitude to the LCD
120
+
121
+ M5Cardputer.Display .setCursor (margin, spacing * currentLine++);
122
+ M5Cardputer.Display .printf (" Long: %.8f" , gps.location .lng ()); // Print the longitude to the LCD
123
+
124
+ M5Cardputer.Display .setCursor (margin, spacing * currentLine++);
125
+ M5Cardputer.Display .printf (" Speed: %.2f km/h" , gps.speed .kmph ()); // Print the speed to the LCD
126
+
127
+ M5Cardputer.Display .setCursor (margin, spacing * currentLine++);
128
+ M5Cardputer.Display .printf (" Satellites: %d" , gps.satellites .value ()); // Print the number of satellites to the LCD
129
+
130
+ M5Cardputer.Display .setCursor (margin, spacing * currentLine++);
131
+ M5Cardputer.Display .printf (" Date: %02d/%02d/%02d" , gps.date .day (), gps.date .month (), gps.date .year ()); // Print the date to the LCD
132
+
133
+ int hour = gps.time .hour () - 4 ; // Adjust the hour for the time zone
134
+ if (hour < 0 )
135
+ hour += 24 ; // If the hour is negative, add 24
136
+
137
+ M5Cardputer.Display .setCursor (margin, spacing * currentLine++);
138
+ M5Cardputer.Display .printf (" Time: %02d:%02d:%02d" , hour, gps.time .minute (), gps.time .second ()); // Print the time to the LCD
139
+ }
140
+
141
+
142
+ void displaySleepScreen () {
143
+ M5Cardputer.Display .drawRect (15 , 15 , 210 , 40 , TFT_LIGHTGRAY);
144
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
145
+ M5Cardputer.Display .setCursor (23 , 23 );
146
+ M5Cardputer.Display .setTextSize (3.4 );
147
+ M5Cardputer.Display .printf (" Sleep Mode" );
148
+
149
+ M5Cardputer.Display .setTextSize (1.5 );
150
+ M5Cardputer.Display .setCursor (42 , 70 );
151
+ M5Cardputer.Display .printf (" Press" );
152
+
153
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
154
+ M5Cardputer.Display .fillRect (91 , 68 , 27 , 15 , TFT_DARKGRAY);
155
+ M5Cardputer.Display .printf (" OK " );
156
+
157
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
158
+ M5Cardputer.Display .printf (" to start" );
159
+
160
+ M5Cardputer.Display .setTextSize (1 );
161
+ M5Cardputer.Display .setCursor (26 , 92 );
162
+ M5Cardputer.Display .printf (" Save position on SD every 1 min" );
163
+
164
+ M5Cardputer.Display .fillRect (10 , 108 , 220 , 15 , TFT_RED);
165
+ M5Cardputer.Display .setCursor (15 , 112 );
166
+ M5Cardputer.Display .printf (" The Cardputer will appear to be off" );
167
+ }
168
+
169
+
170
+ void displayStartSleepScreen (bool gpsState) {
171
+ M5Cardputer.Display .clear ();
172
+ M5Cardputer.Display .drawRect (1 , 1 , 239 , 134 , TFT_RED); // Red frame all over the screen
173
+ M5Cardputer.Display .setTextSize (1 );
174
+
175
+ if (!gpsState) {
176
+ displayNoGps ();
177
+ M5Cardputer.Display .setTextSize (1 );
178
+ M5Cardputer.Display .setCursor (30 , 77 );
179
+ M5Cardputer.Display .println (" We can't proceed without a GPS" );
180
+ M5Cardputer.Display .setCursor (32 , 92 );
181
+ M5Cardputer.Display .println (" Please plug it in to continue" );
182
+ return ;
183
+ }
184
+
185
+ M5Cardputer.Display .setCursor (27 , 60 );
186
+ M5Cardputer.Display .println (" Cardputer will enter sleep mode" );
187
+ M5Cardputer.Display .setCursor (21 , 73 );
188
+ M5Cardputer.Display .println (" Logging the position every minute" );
189
+ delay (1000 );
190
+
191
+ M5Cardputer.Display .setTextSize (3 );
192
+ M5Cardputer.Display .setCursor (73 , 90 );
193
+ for (int i = 0 ; i < 5 ; i++) {
194
+ M5Cardputer.Display .printf (" ." );
195
+ delay (1000 );
196
+ }
197
+ delay (3000 );
198
+ displayClear ();
199
+ M5Cardputer.Display .sleep (); // Turn off the display
200
+ delay (1000 );
201
+ }
202
+
203
+
204
+ void displayDecrementBrightness () {
205
+ brightness -= 30 ;
206
+ if (brightness < 0 ) brightness = 0 ;
207
+ M5Cardputer.Display .setBrightness (brightness);
208
+ }
209
+
210
+
211
+ void displayIncrementBrightness () {
212
+ brightness += 30 ;
213
+ if (brightness > 255 ) brightness = 255 ;
214
+ M5Cardputer.Display .setBrightness (brightness);
215
+ }
216
+
217
+
218
+ void displayGpsState (bool state) {
219
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
220
+ M5Cardputer.Display .setTextSize (1.1 );
221
+ M5Cardputer.Display .setCursor (153 , 105 );
222
+ M5Cardputer.Display .printf (" GPS : " );
223
+
224
+ if (state) {
225
+ M5Cardputer.Display .setTextColor (TFT_GREEN);
226
+ M5Cardputer.Display .printf (" OK" );
227
+ } else {
228
+ M5Cardputer.Display .setTextColor (TFT_RED);
229
+ M5Cardputer.Display .printf (" NO" );
230
+ }
231
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
232
+ }
233
+
234
+
235
+ void displaySdCardState (bool state) {
236
+ M5Cardputer.Display .fillRect (35 , 104 , 220 , 30 , TFT_BLACK);
237
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
238
+ M5Cardputer.Display .setTextSize (1.1 );
239
+ M5Cardputer.Display .setCursor (36 , 105 );
240
+ M5Cardputer.Display .printf (" SD Card : " );
241
+
242
+ if (state) {
243
+ M5Cardputer.Display .setTextColor (TFT_GREEN);
244
+ M5Cardputer.Display .printf (" MOUNTED" );
245
+ } else {
246
+ M5Cardputer.Display .setTextColor (TFT_RED);
247
+ M5Cardputer.Display .printf (" IS NOT MOUNTED" );
248
+ }
249
+
250
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
251
+ }
252
+
253
+
254
+ void displayClear () {
255
+ M5Cardputer.Display .clear ();
256
+ }
257
+
258
+ void displayNoGps () {
259
+ M5Cardputer.Display .setTextSize (3 );
260
+ M5Cardputer.Display .setTextColor (TFT_RED);
261
+ M5Cardputer.Display .setCursor (65 , 45 );
262
+ M5Cardputer.Display .printf (" NO GPS" );
263
+ M5Cardputer.Display .setTextColor (TFT_LIGHTGRAY);
264
+ }
0 commit comments