diff --git a/code/espurna/api.ino b/code/espurna/api.ino index 4271486f..e19a6e04 100644 --- a/code/espurna/api.ino +++ b/code/espurna/api.ino @@ -13,6 +13,8 @@ Copyright (C) 2016-2019 by Xose Pérez #include #include +#include "system.h" + typedef struct { char * key; api_get_callback_f getFn = NULL; diff --git a/code/espurna/button.ino b/code/espurna/button.ino index e23413a1..7716d2f7 100644 --- a/code/espurna/button.ino +++ b/code/espurna/button.ino @@ -15,6 +15,7 @@ Copyright (C) 2016-2019 by Xose Pérez #include #include +#include "system.h" #include "relay.h" #include "light.h" diff --git a/code/espurna/config/prototypes.h b/code/espurna/config/prototypes.h index 8b55670c..0a6a332d 100644 --- a/code/espurna/config/prototypes.h +++ b/code/espurna/config/prototypes.h @@ -38,10 +38,6 @@ extern "C" { #define TCP_MSS (1460) #endif -uint32_t systemResetReason(); -uint8_t systemStabilityCounter(); -void systemStabilityCounter(uint8_t); - // ----------------------------------------------------------------------------- // PROGMEM // ----------------------------------------------------------------------------- diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index c5587383..143d3e4e 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -22,14 +22,17 @@ along with this program. If not, see . #include "config/all.h" #include +#include "system.h" #include "utils.h" #include "relay.h" #include "broker.h" #include "tuya.h" #include "libs/HeapStats.h" -std::vector _loop_callbacks; -std::vector _reload_callbacks; +using void_callback_f = void (*)(); + +std::vector _loop_callbacks; +std::vector _reload_callbacks; bool _reload_config = false; unsigned long _loop_delay = 0; @@ -38,11 +41,11 @@ unsigned long _loop_delay = 0; // GENERAL CALLBACKS // ----------------------------------------------------------------------------- -void espurnaRegisterLoop(void (*callback)()) { +void espurnaRegisterLoop(void_callback_f callback) { _loop_callbacks.push_back(callback); } -void espurnaRegisterReload(void (*callback)()) { +void espurnaRegisterReload(void_callback_f callback) { _reload_callbacks.push_back(callback); } diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index 37183b3f..d81f765c 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -18,6 +18,7 @@ Updated secure client support by Niek van der Maas < mail at niekvandermaas dot #include #include +#include "system.h" #include "libs/SecureClientHelpers.h" #if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT diff --git a/code/espurna/ota_arduinoota.ino b/code/espurna/ota_arduinoota.ino index 95011df1..f4e2807e 100644 --- a/code/espurna/ota_arduinoota.ino +++ b/code/espurna/ota_arduinoota.ino @@ -8,6 +8,8 @@ Copyright (C) 2016-2019 by Xose Pérez #if OTA_ARDUINOOTA_SUPPORT +#include "system.h" + // TODO: allocate ArduinoOTAClass on-demand, stop using global instance void _arduinoOtaConfigure() { diff --git a/code/espurna/ota_asynctcp.ino b/code/espurna/ota_asynctcp.ino index a03fa2cb..0e61fe27 100644 --- a/code/espurna/ota_asynctcp.ino +++ b/code/espurna/ota_asynctcp.ino @@ -15,6 +15,8 @@ Copyright (C) 2016-2019 by Xose Pérez #if TERMINAL_SUPPORT || OTA_MQTT_SUPPORT #include + +#include "system.h" #include "libs/URL.h" std::unique_ptr _ota_client = nullptr; diff --git a/code/espurna/ota_httpupdate.ino b/code/espurna/ota_httpupdate.ino index b80113c0..30155f22 100644 --- a/code/espurna/ota_httpupdate.ino +++ b/code/espurna/ota_httpupdate.ino @@ -18,6 +18,7 @@ Copyright (C) 2019 by Maxim Prokhorov #include #include +#include "system.h" #include "libs/URL.h" #include "libs/TypeChecks.h" #include "libs/SecureClientHelpers.h" diff --git a/code/espurna/system.h b/code/espurna/system.h new file mode 100644 index 00000000..c28e840a --- /dev/null +++ b/code/espurna/system.h @@ -0,0 +1,25 @@ +/* + +SYSTEM MODULE + +Copyright (C) 2019 by Xose Pérez + +*/ + +#pragma once + +#include + +uint32_t systemResetReason(); +uint8_t systemStabilityCounter(); +void systemStabilityCounter(uint8_t count); + +void systemCheck(bool stable); +bool systemCheck(); + +uint32_t systemResetReason(); +unsigned char customResetReason(); +void customResetReason(unsigned char reason); + +void deferredReset(unsigned long delay, unsigned char reason); +bool checkNeedsReset(); diff --git a/code/espurna/system.ino b/code/espurna/system.ino index 2f90e5b3..20e88621 100644 --- a/code/espurna/system.ino +++ b/code/espurna/system.ino @@ -9,6 +9,8 @@ Copyright (C) 2019 by Xose Pérez #include #include +#include "system.h" + // ----------------------------------------------------------------------------- bool _system_send_heartbeat = false; @@ -35,10 +37,10 @@ uint8_t systemStabilityCounter() { return data.parts.stability_counter; } -void systemStabilityCounter(uint8_t counter) { +void systemStabilityCounter(uint8_t count) { system_rtcmem_t data; data.value = Rtcmem->sys; - data.parts.stability_counter = counter; + data.parts.stability_counter = count; Rtcmem->sys = data.value; } diff --git a/code/espurna/terminal.ino b/code/espurna/terminal.ino index bc460169..f8853495 100644 --- a/code/espurna/terminal.ino +++ b/code/espurna/terminal.ino @@ -8,6 +8,7 @@ Copyright (C) 2016-2019 by Xose Pérez #if TERMINAL_SUPPORT +#include "system.h" #include "utils.h" #include "libs/EmbedisWrap.h" #include "libs/StreamInjector.h" diff --git a/code/espurna/web.ino b/code/espurna/web.ino index 4fbd0ccc..092755d0 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -8,6 +8,7 @@ Copyright (C) 2016-2019 by Xose Pérez #if WEB_SUPPORT +#include "system.h" #include "utils.h" #include diff --git a/code/espurna/ws.ino b/code/espurna/ws.ino index 51087464..7b5c89fe 100644 --- a/code/espurna/ws.ino +++ b/code/espurna/ws.ino @@ -13,6 +13,8 @@ Copyright (C) 2016-2019 by Xose Pérez #include #include #include + +#include "system.h" #include "libs/WebSocketIncommingBuffer.h" AsyncWebSocket _ws("/ws");