Explorar o código

Check if ntp is syncing

jancoow %!s(int64=9) %!d(string=hai) anos
pai
achega
0eee7062d7
Modificáronse 3 ficheiros con 13 adicións e 1 borrados
  1. 3 0
      displayHandler.c
  2. 7 1
      ntp.c
  3. 3 0
      ntp.h

+ 3 - 0
displayHandler.c

@@ -8,6 +8,7 @@
 
 #include "display.h"
 #include "displayHandler.h"
+#include "ntp.h"
 #include "rtc.h"
 
 #define MONTH_OFFSET 1
@@ -34,6 +35,8 @@ void displayDate(int line_number){
     char str[13];
     sprintf(str, "   %02d-%02d-%04d", time->tm_mday, time->tm_mon+MONTH_OFFSET, time->tm_year+YEAR_OFFSET);
 
+    if(NtpIsSyncing())
+        str[1] = 'S';
     if (line_number > -1 && line_number < 2){
         (*write_display_ptr[line_number])(str, 13);
     }

+ 7 - 1
ntp.c

@@ -23,6 +23,7 @@
 #define TIME_ZONE 1
 #define LOG_MODULE  LOG_NTP_MODULE
 
+bool isSyncing;
 time_t ntp_time = 0;
 tm *ntp_datetime;
 uint32_t timeserver = 0;
@@ -33,8 +34,13 @@ void NtpInit() {
     GetTime();
 }
 
+bool NtpIsSyncing(){
+    return isSyncing;
+}
+
 void GetTime(){
     /* Ophalen van pool.ntp.org */
+    isSyncing = true;
     puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
     timeserver = inet_addr("213.154.229.24");
 
@@ -55,5 +61,5 @@ void GetTime(){
 
     X12RtcSetClock(ntp_datetime);
 
-
+    isSyncing = false;
 }

+ 3 - 0
ntp.h

@@ -5,6 +5,9 @@
 #ifndef _Network_H
 #define _Network_H
 
+typedef enum {false, true} bool;
+
+extern bool NtpIsSyncing(void);
 extern void NtpInit(void);
 extern void GetTime(void);
 #endif /* _Network_H */