From 913ecf3f3f3099e6901f503c603599399b28289a Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 7 May 2023 04:58:49 +0200 Subject: [PATCH] fix: proper fallback for datetime display if no NMEA string has been received yet --- src/main.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 22a42ba..67429da 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -352,13 +352,18 @@ void printLocation() { void printDateTime() { char dateTime[17]; char speedCourse[17]; - snprintf(dateTime, 17, "%.2s.%.2s.%.2s %.2s:%.2sz", - rmc.date, rmc.date+2, rmc.date+4, - rmc.time, rmc.time+2); - uint16_t kph = (strtol(rmc.speed, NULL, 10) * 463) / 250; - uint16_t hdg = strtol(rmc.course, NULL, 10); - snprintf(speedCourse, 17, "% 3d km/h% 6d \xdf", - kph, hdg); + if (rmc.date[0] != 0) { + snprintf(dateTime, 17, "%.2s.%.2s.%.2s %.2s:%.2sz", + rmc.date, rmc.date+2, rmc.date+4, + rmc.time, rmc.time+2); + uint16_t kph = (strtol(rmc.speed, NULL, 10) * 463) / 250; + uint16_t hdg = strtol(rmc.course, NULL, 10); + snprintf(speedCourse, 17, "% 3d km/h% 6d \xdf", + kph, hdg); + } else { + snprintf(dateTime, 17, "??.??.?? ??:??z"); + snprintf(speedCourse, 17, "??? km/h ??? \xdf"); + } lcd.setCursor(0, 0); lcd.print(dateTime); @@ -682,6 +687,7 @@ void setup() { attachInterrupt(digitalPinToInterrupt(3), isrAbc, FALLING); lcd.init(); lcd.noDisplay(); + lcd.noBacklight(); setPressed = false; abcPressed = false; }