From 31195ba3b62ff886313d0369baf4b6ab1a07187b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Fri, 22 Feb 2019 09:57:30 +0100 Subject: [PATCH] Removing loop delay if WIFI is not set to sleep, reducing it to 1ms otherwise (#1541) --- code/espurna/config/general.h | 2 +- code/espurna/system.ino | 16 ++++++++++++---- code/espurna/utils.ino | 4 +++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 9c1ef409..8c74394c 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -21,7 +21,7 @@ #endif #ifndef LOOP_DELAY_TIME -#define LOOP_DELAY_TIME 10 // Delay for this millis in the main loop [0-250] +#define LOOP_DELAY_TIME 1 // Delay for this millis in the main loop [0-250] (see https://github.com/xoseperez/espurna/issues/1541) #endif //------------------------------------------------------------------------------ diff --git a/code/espurna/system.ino b/code/espurna/system.ino index 791ba99c..33bbf267 100644 --- a/code/espurna/system.ino +++ b/code/espurna/system.ino @@ -10,7 +10,10 @@ Copyright (C) 2018 by Xose PĂ©rez // ----------------------------------------------------------------------------- +#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP unsigned long _loop_delay = 0; +#endif + bool _system_send_heartbeat = false; unsigned char _heartbeat_mode = HEARTBEAT_MODE; unsigned long _heartbeat_interval = HEARTBEAT_INTERVAL; @@ -72,10 +75,11 @@ bool systemGetHeartbeat() { return _system_send_heartbeat; } +#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP unsigned long systemLoopDelay() { return _loop_delay; } - +#endif unsigned long systemLoadAverage() { return _load_average; @@ -157,7 +161,9 @@ void systemLoop() { // Power saving delay // ------------------------------------------------------------------------- - delay(_loop_delay); + #if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP + delay(_loop_delay); + #endif } @@ -196,8 +202,10 @@ void systemSetup() { _systemSetupSpecificHardware(); // Cache loop delay value to speed things (recommended max 250ms) - _loop_delay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str()); - _loop_delay = constrain(_loop_delay, 0, 300); + #if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP + _loop_delay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str()); + _loop_delay = constrain(_loop_delay, 0, 300); + #endif // Register Loop espurnaRegisterLoop(systemLoop); diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index 23c6ea03..888f3963 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -469,7 +469,9 @@ void info() { #if ADC_MODE_VALUE == ADC_VCC DEBUG_MSG_P(PSTR("[MAIN] Power: %u mV\n"), ESP.getVcc()); #endif - DEBUG_MSG_P(PSTR("[MAIN] Power saving delay value: %lu ms\n"), systemLoopDelay()); + #if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP + DEBUG_MSG_P(PSTR("[MAIN] Power saving delay value: %lu ms\n"), systemLoopDelay()); + #endif // -------------------------------------------------------------------------