|
@@ -20,7 +20,6 @@
|
20
|
20
|
|
21
|
21
|
#include <Arduino.h>
|
22
|
22
|
#include <WiFi.h>
|
23
|
|
-#include <time.h>
|
24
|
23
|
|
25
|
24
|
#include "config.h"
|
26
|
25
|
#include "DebugLog.h"
|
|
@@ -72,7 +71,6 @@
|
72
|
71
|
#define FULL_BRIGHT_MS (1000 * 30)
|
73
|
72
|
#define NO_BRIGHT_MS (1000 * 2)
|
74
|
73
|
|
75
|
|
-#define NTP_SERVER "pool.ntp.org"
|
76
|
74
|
#define STANDBY_REDRAW_MS 500
|
77
|
75
|
|
78
|
76
|
#define CALIB_1_X 42
|
|
@@ -80,11 +78,6 @@
|
80
|
78
|
#define CALIB_2_X LCD_WIDTH - 1 - CALIB_1_X
|
81
|
79
|
#define CALIB_2_Y LCD_HEIGHT - 1 - CALIB_1_Y
|
82
|
80
|
|
83
|
|
-// TODO auto-detect?!
|
84
|
|
-#warning hard-coded timezone and daylight savings offset
|
85
|
|
-#define gmtOffset_sec (60 * 60)
|
86
|
|
-#define daylightOffset_sec (60 * 60)
|
87
|
|
-
|
88
|
81
|
#if (LCD_MIN_BRIGHTNESS <= STANDBY_BRIGHTNESS)
|
89
|
82
|
#error STANDBY_BRIGHTNESS needs to be bigger than LCD_MIN_BRIGHTNESS
|
90
|
83
|
#endif
|
|
@@ -259,38 +252,12 @@ static void draw_standby(void) {
|
259
|
252
|
tft.drawString(ESP_PLATFORM_NAME " " NAME_OF_FEATURE " V" ESP_ENV_VERSION, LCD_WIDTH / 2, 0, 2);
|
260
|
253
|
tft.drawString("by xythobuz.de", LCD_WIDTH / 2, 16, 2);
|
261
|
254
|
|
|
255
|
+ String date = "?";
|
|
256
|
+ String time = "?";
|
262
|
257
|
struct tm timeinfo;
|
263
|
|
- String date, time;
|
264
|
|
- String weekday[7] = { "So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa." };
|
265
|
|
- if(getLocalTime(&timeinfo)) {
|
266
|
|
- date += weekday[timeinfo.tm_wday % 7];
|
267
|
|
- date += " ";
|
268
|
|
- if (timeinfo.tm_mday < 10) {
|
269
|
|
- date += "0";
|
270
|
|
- }
|
271
|
|
- date += String(timeinfo.tm_mday);
|
272
|
|
- date += ".";
|
273
|
|
- if ((timeinfo.tm_mon + 1) < 10) {
|
274
|
|
- date += "0";
|
275
|
|
- }
|
276
|
|
- date += String(timeinfo.tm_mon + 1);
|
277
|
|
- date += ".";
|
278
|
|
- date += String(timeinfo.tm_year + 1900);
|
279
|
|
-
|
280
|
|
- if (timeinfo.tm_hour < 10) {
|
281
|
|
- time += "0";
|
282
|
|
- }
|
283
|
|
- time += String(timeinfo.tm_hour);
|
284
|
|
- time += ":";
|
285
|
|
- if (timeinfo.tm_min < 10) {
|
286
|
|
- time += "0";
|
287
|
|
- }
|
288
|
|
- time += String(timeinfo.tm_min);
|
289
|
|
- time += ":";
|
290
|
|
- if (timeinfo.tm_sec < 10) {
|
291
|
|
- time += "0";
|
292
|
|
- }
|
293
|
|
- time += String(timeinfo.tm_sec);
|
|
258
|
+ if (getLocalTime(&timeinfo)) {
|
|
259
|
+ date = time_to_date_str(timeinfo);
|
|
260
|
+ time = time_to_time_str(timeinfo);
|
294
|
261
|
}
|
295
|
262
|
|
296
|
263
|
tft.setTextDatum(MC_DATUM); // middle center
|
|
@@ -474,9 +441,6 @@ void ui_progress(enum ui_state state) {
|
474
|
441
|
} break;
|
475
|
442
|
|
476
|
443
|
case UI_READY: {
|
477
|
|
- // get time via NTP
|
478
|
|
- configTime(gmtOffset_sec, daylightOffset_sec, NTP_SERVER);
|
479
|
|
-
|
480
|
444
|
ui_page = UI_START;
|
481
|
445
|
ui_draw_menu();
|
482
|
446
|
} break;
|
|
@@ -648,3 +612,45 @@ void ui_run(void) {
|
648
|
612
|
}
|
649
|
613
|
|
650
|
614
|
#endif // FEATURE_UI
|
|
615
|
+
|
|
616
|
+#ifdef FEATURE_NTP
|
|
617
|
+
|
|
618
|
+String time_to_date_str(struct tm timeinfo) {
|
|
619
|
+ static String weekday[7] = { "So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa." };
|
|
620
|
+ String date;
|
|
621
|
+ date += weekday[timeinfo.tm_wday % 7];
|
|
622
|
+ date += " ";
|
|
623
|
+ if (timeinfo.tm_mday < 10) {
|
|
624
|
+ date += "0";
|
|
625
|
+ }
|
|
626
|
+ date += String(timeinfo.tm_mday);
|
|
627
|
+ date += ".";
|
|
628
|
+ if ((timeinfo.tm_mon + 1) < 10) {
|
|
629
|
+ date += "0";
|
|
630
|
+ }
|
|
631
|
+ date += String(timeinfo.tm_mon + 1);
|
|
632
|
+ date += ".";
|
|
633
|
+ date += String(timeinfo.tm_year + 1900);
|
|
634
|
+ return date;
|
|
635
|
+}
|
|
636
|
+
|
|
637
|
+String time_to_time_str(struct tm timeinfo) {
|
|
638
|
+ String time;
|
|
639
|
+ if (timeinfo.tm_hour < 10) {
|
|
640
|
+ time += "0";
|
|
641
|
+ }
|
|
642
|
+ time += String(timeinfo.tm_hour);
|
|
643
|
+ time += ":";
|
|
644
|
+ if (timeinfo.tm_min < 10) {
|
|
645
|
+ time += "0";
|
|
646
|
+ }
|
|
647
|
+ time += String(timeinfo.tm_min);
|
|
648
|
+ time += ":";
|
|
649
|
+ if (timeinfo.tm_sec < 10) {
|
|
650
|
+ time += "0";
|
|
651
|
+ }
|
|
652
|
+ time += String(timeinfo.tm_sec);
|
|
653
|
+ return time;
|
|
654
|
+}
|
|
655
|
+
|
|
656
|
+#endif // FEATURE_NTP
|