From 6497238f4b39cff9530ea536e72941a056437020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Fri, 19 Jan 2018 10:38:38 +0100 Subject: [PATCH] Option to disable heartbeat. Added 3rd party hooks --- code/espurna/config/general.h | 4 ++++ code/espurna/espurna.ino | 22 +++++++++++++++++----- code/espurna/mqtt.ino | 4 +++- code/espurna/utils.ino | 4 ++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index e90759a8..1fec3c48 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -150,6 +150,10 @@ // HEARTBEAT //------------------------------------------------------------------------------ +#ifndef HEARTBEAT_ENABLED +#define HEARTBEAT_ENABLED 1 +#endif + #define HEARTBEAT_INTERVAL 300000 // Interval between heartbeat messages (in ms) #define UPTIME_OVERFLOW 4294967295 // Uptime overflow value diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index ee60ca4d..21d167f8 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -56,11 +56,13 @@ void hardwareSetup() { void hardwareLoop() { // Heartbeat - static unsigned long last = 0; - if ((last == 0) || (millis() - last > HEARTBEAT_INTERVAL)) { - last = millis(); - heartbeat(); - } + #if HEARTBEAT_ENABLED + static unsigned long last = 0; + if ((last == 0) || (millis() - last > HEARTBEAT_INTERVAL)) { + last = millis(); + heartbeat(); + } + #endif // HEARTBEAT_ENABLED } @@ -177,6 +179,11 @@ void setup() { schSetup(); #endif + // 3rd party code hook + #if USE_EXTRA + extraSetup(); + #endif + // Prepare configuration for version 2.0 migrate(); @@ -241,6 +248,11 @@ void loop() { mdnsClientLoop(); #endif + // 3rd party code hook + #if USE_EXTRA + extraLoop(); + #endif + // Power saving delay delay(_loopDelay); diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index 7f33fbb3..7ffbaa0c 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -346,7 +346,9 @@ void _mqttCallback(unsigned int type, const char * topic, const char * payload) mqttSubscribe(MQTT_TOPIC_ACTION); // Send heartbeat messages - heartbeat(); + #if HEARTBEAT_ENABLED + heartbeat(); + #endif } diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index 9fa1a545..bcfb8137 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -94,6 +94,8 @@ unsigned long getUptime() { } +#if HEARTBEAT_ENABLED + void heartbeat() { unsigned long uptime_seconds = getUptime(); @@ -201,6 +203,8 @@ void heartbeat() { } +#endif /// HEARTBEAT_ENABLED + unsigned int sectors(size_t size) { return (int) (size + SPI_FLASH_SEC_SIZE - 1) / SPI_FLASH_SEC_SIZE; }