Browse Source

Removing loop delay if WIFI is not set to sleep, reducing it to 1ms otherwise (#1541)

rules-rpn
Xose Pérez 5 years ago
parent
commit
31195ba3b6
3 changed files with 16 additions and 6 deletions
  1. +1
    -1
      code/espurna/config/general.h
  2. +12
    -4
      code/espurna/system.ino
  3. +3
    -1
      code/espurna/utils.ino

+ 1
- 1
code/espurna/config/general.h View File

@ -21,7 +21,7 @@
#endif #endif
#ifndef LOOP_DELAY_TIME #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 #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------


+ 12
- 4
code/espurna/system.ino View File

@ -10,7 +10,10 @@ Copyright (C) 2018 by Xose Pérez <xose dot perez at gmail dot com>
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP
unsigned long _loop_delay = 0; unsigned long _loop_delay = 0;
#endif
bool _system_send_heartbeat = false; bool _system_send_heartbeat = false;
unsigned char _heartbeat_mode = HEARTBEAT_MODE; unsigned char _heartbeat_mode = HEARTBEAT_MODE;
unsigned long _heartbeat_interval = HEARTBEAT_INTERVAL; unsigned long _heartbeat_interval = HEARTBEAT_INTERVAL;
@ -72,10 +75,11 @@ bool systemGetHeartbeat() {
return _system_send_heartbeat; return _system_send_heartbeat;
} }
#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP
unsigned long systemLoopDelay() { unsigned long systemLoopDelay() {
return _loop_delay; return _loop_delay;
} }
#endif
unsigned long systemLoadAverage() { unsigned long systemLoadAverage() {
return _load_average; return _load_average;
@ -157,7 +161,9 @@ void systemLoop() {
// Power saving delay // Power saving delay
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
delay(_loop_delay);
#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP
delay(_loop_delay);
#endif
} }
@ -196,8 +202,10 @@ void systemSetup() {
_systemSetupSpecificHardware(); _systemSetupSpecificHardware();
// Cache loop delay value to speed things (recommended max 250ms) // 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 // Register Loop
espurnaRegisterLoop(systemLoop); espurnaRegisterLoop(systemLoop);


+ 3
- 1
code/espurna/utils.ino View File

@ -469,7 +469,9 @@ void info() {
#if ADC_MODE_VALUE == ADC_VCC #if ADC_MODE_VALUE == ADC_VCC
DEBUG_MSG_P(PSTR("[MAIN] Power: %u mV\n"), ESP.getVcc()); DEBUG_MSG_P(PSTR("[MAIN] Power: %u mV\n"), ESP.getVcc());
#endif #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
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------


Loading…
Cancel
Save