From 0830aa9642c8b860f7dc51ff94d016f7ee3e1f11 Mon Sep 17 00:00:00 2001 From: Hasenradball Date: Sun, 24 Nov 2024 22:43:59 +0100 Subject: [PATCH] adapt class MESZ --- examples/timeMESZ/timeMESZ.ino | 14 +++++++------- lib/cMESZ/cMESZ.cpp | 13 +++---------- lib/cMESZ/cMESZ.h | 8 ++++---- lib/cMESZ/cMESZ.inl | 12 ++++++------ 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/examples/timeMESZ/timeMESZ.ino b/examples/timeMESZ/timeMESZ.ino index 943f779..e603fdc 100644 --- a/examples/timeMESZ/timeMESZ.ino +++ b/examples/timeMESZ/timeMESZ.ino @@ -32,13 +32,13 @@ void setup() { } // wait if SNTP has synchronized internal clock - while (!MESZ::get_time_synchronized()) { + while (!MESZ::get_timeHasBeenSynchronized()) { yield(); } - Serial.println("Time successfully synchronized!\n"); - MESZ::set_time_synchronized_false(); + Serial.println("Time successfully syncronized!"); + MESZ::set_timeHasBeenSynchronized_false(); auto syncTime_ms = sntp_get_sync_interval(); - Serial.printf("the sntp sync interval is set to : %ld ms / %ld s / %ld min / %ld h", \ + Serial.printf("\tthe sntp sync intervall is set to : %ld ms / %ld s / %ld min / %ld h\n", \ syncTime_ms, syncTime_ms/1000U, syncTime_ms/60000U, syncTime_ms/3600000U); Serial.printf("\nZeit: %s", uhr.get_asctime()); @@ -46,9 +46,9 @@ void setup() { void loop() { - if (MESZ::get_time_synchronized()) { - Serial.println("Time successfully synchronized!\n"); - MESZ::set_time_synchronized_false(); + if (MESZ::get_timeHasBeenSynchronized()) { + Serial.println("Time successfully syncronized!\n"); + MESZ::set_timeHasBeenSynchronized_false(); Serial.printf("\n Zeit: %s", uhr.get_asctime()); } } diff --git a/lib/cMESZ/cMESZ.cpp b/lib/cMESZ/cMESZ.cpp index 2fbf9a7..2b4fc45 100644 --- a/lib/cMESZ/cMESZ.cpp +++ b/lib/cMESZ/cMESZ.cpp @@ -8,13 +8,13 @@ #include "cMESZ.h" #include "DBG_Print.h" -bool MESZ::_time_synchronized {false}; +bool MESZ::_timeHasBeenSynchronized {false}; /** * @brief Construct a new MESZ::MESZ object */ MESZ::MESZ() { - sntp_set_time_sync_notification_cb(MESZ::set_time_synchronized_true); + sntp_set_time_sync_notification_cb(MESZ::set_timeHasBeenSynchronized_true); clear_tm(); } @@ -69,7 +69,7 @@ bool MESZ::init(void) { DBG__PRINT("\tTimeserver1: ", _NTPServer[0]); DBG__PRINT("\tTimeserver2: ", _NTPServer[1]); DBG__PRINT("\tTimeserver3: ", _NTPServer[2]); - _time_synchronized = false; + _timeHasBeenSynchronized = false; configTzTime(_timezone, _NTPServer[0], _NTPServer[1], _NTPServer[2]); return true; } @@ -87,13 +87,6 @@ bool MESZ::UpdateTime(bool unix) { return true; } else { - // remove if it works on esp32 - // #if ESP32 - // _tv.tv_sec += 3600; - // if (isSummerTime(_tv.tv_sec)) { - // _tv.tv_sec += 3600; - // } - // #endif localtime_r(&_tv.tv_sec, &_tm); } return true; diff --git a/lib/cMESZ/cMESZ.h b/lib/cMESZ/cMESZ.h index 95816a3..7c57710 100644 --- a/lib/cMESZ/cMESZ.h +++ b/lib/cMESZ/cMESZ.h @@ -11,9 +11,9 @@ class MESZ { public: MESZ(); - static void set_time_synchronized_true(struct timeval *_tv); - static void set_time_synchronized_false(void); - static bool get_time_synchronized(void); + static void set_timeHasBeenSynchronized_true(struct timeval *_tv); + static void set_timeHasBeenSynchronized_false(void); + static bool get_timeHasBeenSynchronized(void); bool setTimeZone(const char *timezone = nullptr); bool setTimeServers(const char *timeServer1 = nullptr, const char *timeServer2 = nullptr, const char *timeServer3 = nullptr); @@ -42,7 +42,7 @@ class MESZ { struct timeval _tv {0, 0}; struct tm _tm; int _t1, _t2, _calc_year; - static bool _time_synchronized; + static bool _timeHasBeenSynchronized; void clear_tm(void) {_tm = {0, 0, 0, 0, 0, 0, 0, 0, -1};}; bool UpdateTime(bool unix = false); diff --git a/lib/cMESZ/cMESZ.inl b/lib/cMESZ/cMESZ.inl index de0cd31..cc1dcd8 100644 --- a/lib/cMESZ/cMESZ.inl +++ b/lib/cMESZ/cMESZ.inl @@ -3,16 +3,16 @@ * * @param _tv */ -inline void MESZ::set_time_synchronized_true(struct timeval *_tv) { - _time_synchronized = true; +inline void MESZ::set_timeHasBeenSynchronized_true(struct timeval *_tv) { + _timeHasBeenSynchronized = true; } /** * @brief set the variable _time_synchronized to false * */ -inline void MESZ::set_time_synchronized_false(void) { - _time_synchronized = false; +inline void MESZ::set_timeHasBeenSynchronized_false(void) { + _timeHasBeenSynchronized = false; } /** @@ -20,8 +20,8 @@ inline void MESZ::set_time_synchronized_false(void) { * * @return true if time was synched else false */ -inline bool MESZ::get_time_synchronized(void) { - return _time_synchronized; +inline bool MESZ::get_timeHasBeenSynchronized(void) { + return _timeHasBeenSynchronized; } /**