diff --git a/src/Watchy.cpp b/src/Watchy.cpp index 353f4ae..ca3161c 100644 --- a/src/Watchy.cpp +++ b/src/Watchy.cpp @@ -92,7 +92,7 @@ void Watchy::handleButtonPress(){ showUpdateFW(); break; case 6: - syncNTP(); + showSyncNTP(); break; default: break; @@ -174,7 +174,7 @@ void Watchy::handleButtonPress(){ showUpdateFW(); break; case 6: - syncNTP(); + showSyncNTP(); break; default: break; @@ -881,7 +881,7 @@ void Watchy::updateFWBegin(){ showMenu(menuIndex, false); } -void Watchy::syncNTP(){ +void Watchy::showSyncNTP(){ display.setFullWindow(); display.fillScreen(GxEPD_BLACK); display.setFont(&FreeMonoBold9pt7b); @@ -890,7 +890,7 @@ void Watchy::syncNTP(){ display.println("Syncing NTP... "); display.display(false); //full refresh if(connectWiFi()){ - if(RTC.syncNtpTime()){ + if(syncNTP()){ display.println("NTP Sync Success"); }else{ display.println("NTP Sync Failed"); @@ -900,7 +900,38 @@ void Watchy::syncNTP(){ } display.display(true); //full refresh delay(1000); - showMenu(menuIndex, false); + showMenu(menuIndex, false); +} + +bool Watchy::syncNTP(){ //NTP sync - call after connecting to WiFi and remember to turn it back off + configTime(GMT_OFFSET_SEC, DST_OFFSET_SEC, NTP_SERVER); + struct tm timeinfo; + if(!getLocalTime(&timeinfo)){ + return false; //NTP sync failed + } + /**************************************************** + struct tm + { + int tm_sec; // Seconds [0,60]. + int tm_min; // Minutes [0,59]. + int tm_hour; // Hour [0,23]. + int tm_mday; // Day of month [1,31]. + int tm_mon; // Month of year [0,11]. + int tm_year; // Years since 1900. + int tm_wday; // Day of week [0,6] (Sunday =0). + int tm_yday; // Day of year [0,365]. + int tm_isdst; // Daylight Savings flag. + } + ****************************************************/ + tmElements_t tm; + tm.Year = CalendarYrToTm(timeinfo.tm_year + 1900); + tm.Month = timeinfo.tm_mon + 1; //tm.Month 1 - 12 + tm.Day = timeinfo.tm_mday; + tm.Hour = timeinfo.tm_hour; + tm.Minute = timeinfo.tm_min; + tm.Second = timeinfo.tm_sec; + RTC.set(tm); + return true; } // time_t compileTime() diff --git a/src/Watchy.h b/src/Watchy.h index a12da61..62f1a6d 100644 --- a/src/Watchy.h +++ b/src/Watchy.h @@ -39,8 +39,9 @@ class Watchy { void showBuzz(); void showAccelerometer(); void showUpdateFW(); + void showSyncNTP(); + bool syncNTP(); void setTime(); - void syncNTP(); void setupWifi(); bool connectWiFi(); weatherData getWeatherData(); diff --git a/src/WatchyRTC.cpp b/src/WatchyRTC.cpp index f8dce40..721f7d8 100644 --- a/src/WatchyRTC.cpp +++ b/src/WatchyRTC.cpp @@ -115,37 +115,6 @@ void WatchyRTC::_PCFConfig(String datetime){ //String datetime is YYYY:MM:DD:HH: clearAlarm(); } -bool WatchyRTC::syncNtpTime(){ //NTP sync - call after connecting to WiFi and remember to turn it back off - configTime(GMT_OFFSET_SEC, DST_OFFSET_SEC, NTP_SERVER); - struct tm timeinfo; - if(!getLocalTime(&timeinfo)){ - return false; //NTP sync failed - } - /**************************************************** - struct tm - { - int tm_sec; // Seconds [0,60]. - int tm_min; // Minutes [0,59]. - int tm_hour; // Hour [0,23]. - int tm_mday; // Day of month [1,31]. - int tm_mon; // Month of year [0,11]. - int tm_year; // Years since 1900. - int tm_wday; // Day of week [0,6] (Sunday =0). - int tm_yday; // Day of year [0,365]. - int tm_isdst; // Daylight Savings flag. - } - ****************************************************/ - tmElements_t tm; - tm.Year = CalendarYrToTm(timeinfo.tm_year + 1900); - tm.Month = timeinfo.tm_mon + 1; //tm.Month 1 - 12 - tm.Day = timeinfo.tm_mday; - tm.Hour = timeinfo.tm_hour; - tm.Minute = timeinfo.tm_min; - tm.Second = timeinfo.tm_sec; - set(tm); - return true; -} - String WatchyRTC::_getValue(String data, char separator, int index) { int found = 0; diff --git a/src/WatchyRTC.h b/src/WatchyRTC.h index 726c842..5a96bf4 100644 --- a/src/WatchyRTC.h +++ b/src/WatchyRTC.h @@ -25,7 +25,6 @@ class WatchyRTC { void clearAlarm(); void read(tmElements_t &tm); void set(tmElements_t tm); - bool syncNtpTime(); uint8_t temperature(); private: void _DSConfig(String datetime);