From 1e88ff90f9db4730a233a71181627a481ba85144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Fri, 29 Dec 2017 09:25:57 +0100 Subject: [PATCH] Fixed relays status on reboot --- code/espurna/relay.ino | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 69c08de5..afe9041d 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -335,26 +335,30 @@ void _relayBoot() { DEBUG_MSG_P(PSTR("[RELAY] Retrieving mask: %d\n"), mask); // Walk the relays + bool status = false; for (unsigned int i=0; i<_relays.size(); i++) { - _relays[i].current_status = false; - _relays[i].target_status = false; unsigned char boot_mode = getSetting("relayBoot", i, RELAY_BOOT_MODE).toInt(); + DEBUG_MSG_P(PSTR("[RELAY] Relay #%d boot mode %d\n"), i, boot_mode); switch (boot_mode) { - case RELAY_BOOT_OFF: - relayStatus(i, false); - break; - case RELAY_BOOT_ON: - relayStatus(i, true); - break; case RELAY_BOOT_SAME: - relayStatus(i, (mask & bit) == bit); + status = ((mask & bit) == bit); break; case RELAY_BOOT_TOOGLE: - relayStatus(i, (mask & bit) != bit); + status = ((mask & bit) != bit); mask ^= bit; trigger_save = true; break; + case RELAY_BOOT_ON: + status = true; + break; + case RELAY_BOOT_OFF: + default: + status = false; + break; } + _relays[i].current_status = !status; + _relays[i].target_status = status; + _relays[i].change_time = millis(); bit <<= 1; }