diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index 4b8b8e02..3ea90016 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -288,6 +288,26 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_ } } +void DataStore::saveRTCTime() { + uint32_t t = _clock->getCurrentTime(); + if (t < 1000000000UL) return; // don't save if time not yet synced + File file = openWrite(_fs, "/rtc_save"); + if (file) { + file.write((uint8_t *)&t, sizeof(t)); + file.close(); + } +} + +void DataStore::restoreRTCTime() { + File file = openRead(_fs, "/rtc_save"); + if (file) { + uint32_t t = 0; + file.read((uint8_t *)&t, sizeof(t)); + file.close(); + if (t > 1000000000UL) _clock->setCurrentTime(t); + } +} + void DataStore::loadContacts(DataStoreHost* host) { File file = openRead(_getContactsChannelsFS(), "/contacts3"); if (file) { diff --git a/examples/companion_radio/DataStore.h b/examples/companion_radio/DataStore.h index 58b4d5d2..1b69e190 100644 --- a/examples/companion_radio/DataStore.h +++ b/examples/companion_radio/DataStore.h @@ -49,6 +49,8 @@ public: bool removeFile(FILESYSTEM* fs, const char* filename); uint32_t getStorageUsedKb() const; uint32_t getStorageTotalKb() const; + void saveRTCTime(); + void restoreRTCTime(); private: FILESYSTEM* _getContactsChannelsFS() const { if (_fsExtra) return _fsExtra; return _fs;}; diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index aeff591c..8b51b6a9 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -165,6 +165,7 @@ protected: public: void savePrefs() { _store->savePrefs(_prefs, sensors.node_lat, sensors.node_lon); } + void saveRTCTime() { _store->saveRTCTime(); } #if ENV_INCLUDE_GPS == 1 void applyGpsPrefs() { diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 25c6c489..671d592a 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -211,6 +211,7 @@ void setup() { #error "need to define filesystem" #endif + store.restoreRTCTime(); sensors.begin(); #if ENV_INCLUDE_GPS == 1 diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index c5681079..7a95d900 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -986,6 +986,7 @@ void UITask::setCurrScreen(UIScreen* c) { hardware-agnostic pre-shutdown activity should be done here */ void UITask::shutdown(bool restart){ + the_mesh.saveRTCTime(); #ifdef PIN_BUZZER /* note: we have a choice here -