diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index 7250297099a2bc0f7bee072d9f94dd1457212323..a640ff2455b3fa8cc9e9f9565e44c4b86dc69a4e 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -162,10 +162,10 @@ void loop() { } uint32_t duration = millis() - t0; - if (duration > max_loop_duration) { - max_loop_duration = duration; + if (duration > ampel.max_loop_duration) { + ampel.max_loop_duration = duration; Serial.print(F("Debug - Max loop duration : ")); - Serial.print(max_loop_duration); + Serial.print(ampel.max_loop_duration); Serial.println(F(" ms.")); } } diff --git a/ampel-firmware/util.cpp b/ampel-firmware/util.cpp index 934ba9796536d47dcd8a26fe169fb10f2a38f401..6e6d688655d5335e6228f389454c20ccc1e21f10 100644 --- a/ampel-firmware/util.cpp +++ b/ampel-firmware/util.cpp @@ -51,10 +51,8 @@ namespace ntp { } } -uint32_t max_loop_duration = 0; - Ampel::Ampel() : - sensorId("ESP" + macToID()) { + sensorId("ESP" + macToID()), max_loop_duration(0) { sensor_console::defineIntCommand("set_time", ntp::setLocalTime, " 1618829570 (Sets time to the given UNIX time)"); sensor_console::defineCommand("free", []() { Serial.print(F("Free heap space : ")); @@ -63,4 +61,4 @@ Ampel::Ampel() : }, " (Displays available heap space)"); } -const Ampel ampel; +Ampel ampel; diff --git a/ampel-firmware/util.h b/ampel-firmware/util.h index d0a8f565d9a974374cef456c4d398aef3586c469..92fae395e58bd8c3b10d95e36260c2c13f79a266 100644 --- a/ampel-firmware/util.h +++ b/ampel-firmware/util.h @@ -39,12 +39,12 @@ namespace util { class Ampel { public: const String sensorId; + uint32_t max_loop_duration; Ampel(); }; //NOTE: Only use seconds() for duration comparison, not timestamps comparison. Otherwise, problems happen when millis roll over. #define seconds() (millis() / 1000UL) -extern uint32_t max_loop_duration; -extern const Ampel ampel; +extern Ampel ampel; #endif diff --git a/ampel-firmware/web_server.cpp b/ampel-firmware/web_server.cpp index fad0bf73e0856e37b767ec4ed0cf3679982d0e54..4788b009c0a076b01712c158e7714f28f43c508b 100644 --- a/ampel-firmware/web_server.cpp +++ b/ampel-firmware/web_server.cpp @@ -239,7 +239,7 @@ namespace web_server { #endif config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", ampel.sensorId.c_str(), ampel.sensorId.c_str(), WiFi.localIP().toString().c_str(), WiFi.localIP().toString().c_str(), - get_free_heap_size(), max_loop_duration, BOARD, dd, hh, mm, ss); + get_free_heap_size(), ampel.max_loop_duration, BOARD, dd, hh, mm, ss); Serial.print(F(" - Body size : ")); http.sendContent(content);