From 6ccd000280527cd8c656d7e8feff10ac5bfe136c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Fri, 25 Aug 2017 19:11:05 +0200 Subject: [PATCH] Delayed relay state saving into EEPROM --- code/espurna/config/general.h | 3 +++ code/espurna/relay.ino | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index e581d887..eeb042b8 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -196,6 +196,9 @@ PROGMEM const char* const custom_reset_string[] = { // Pulse with in milliseconds for a latched relay #define RELAY_LATCHING_PULSE 10 +// Do not save relay state after these many milliseconds +#define RELAY_SAVE_DELAY 1000 + //------------------------------------------------------------------------------ // I18N //------------------------------------------------------------------------------ diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 0bdb26d4..d2dd39ae 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -29,6 +29,7 @@ typedef struct { } relay_t; std::vector _relays; bool recursive = false; +Ticker _relaySaveTicker; #if RELAY_PROVIDER == RELAY_PROVIDER_DUAL unsigned char _dual_status = 0; @@ -528,7 +529,7 @@ void relayLoop(void) { if (!recursive) { relayPulse(id); relaySync(id); - relaySave(); + _relaySaveTicker.once_ms(RELAY_SAVE_DELAY, relaySave); #if WEB_SUPPORT relayWS(); #endif