Skip to content

Commit

Permalink
adapt class MESZ
Browse files Browse the repository at this point in the history
  • Loading branch information
hasenradball committed Nov 24, 2024
1 parent b39eb35 commit 0830aa9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
14 changes: 7 additions & 7 deletions examples/timeMESZ/timeMESZ.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ 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!");

Check failure on line 38 in examples/timeMESZ/timeMESZ.ino

View workflow job for this annotation

GitHub Actions / spellcheck

syncronized ==> synchronized
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", \

Check failure on line 41 in examples/timeMESZ/timeMESZ.ino

View workflow job for this annotation

GitHub Actions / spellcheck

intervall ==> interval
syncTime_ms, syncTime_ms/1000U, syncTime_ms/60000U, syncTime_ms/3600000U);

Serial.printf("\nZeit: %s", uhr.get_asctime());
}


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");

Check failure on line 50 in examples/timeMESZ/timeMESZ.ino

View workflow job for this annotation

GitHub Actions / spellcheck

syncronized ==> synchronized
MESZ::set_timeHasBeenSynchronized_false();
Serial.printf("\n Zeit: %s", uhr.get_asctime());
}
}
13 changes: 3 additions & 10 deletions lib/cMESZ/cMESZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions lib/cMESZ/cMESZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions lib/cMESZ/cMESZ.inl
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
*
* @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;
}

/**
* @brief get the value of _time_synchronized
*
* @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;
}

/**
Expand Down

0 comments on commit 0830aa9

Please sign in to comment.