|
|
@ -28,6 +28,7 @@ typedef struct { |
|
|
|
|
|
|
|
bool current_status; // Holds the current (physical) status of the relay
|
|
|
|
bool target_status; // Holds the target status
|
|
|
|
unsigned char lock; // Holds the value of target status, that cannot be changed afterwards. (0 for false, 1 for true, 2 to disable)
|
|
|
|
unsigned long fw_start; // Flood window start time
|
|
|
|
unsigned char fw_count; // Number of changes within the current flood window
|
|
|
|
unsigned long change_time; // Scheduled time to change
|
|
|
@ -174,6 +175,23 @@ void _relayProcess(bool mode) { |
|
|
|
// Only process the relays we have to change to the requested mode
|
|
|
|
if (target != mode) continue; |
|
|
|
|
|
|
|
// Only process the relays that can be changed
|
|
|
|
switch (_relays[id].lock) { |
|
|
|
case RELAY_LOCK_ON: |
|
|
|
case RELAY_LOCK_OFF: |
|
|
|
{ |
|
|
|
bool lock = _relays[id].lock == 1; |
|
|
|
if (lock != _relays[id].target_status) { |
|
|
|
_relays[id].target_status = lock; |
|
|
|
continue; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case RELAY_LOCK_DISABLED: |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// Only process if the change_time has arrived
|
|
|
|
if (current_time < _relays[id].change_time) continue; |
|
|
|
|
|
|
@ -521,6 +539,7 @@ void _relayBoot() { |
|
|
|
auto mask = std::bitset<RELAY_SAVE_MASK_MAX>(stored_mask); |
|
|
|
|
|
|
|
// Walk the relays
|
|
|
|
unsigned char lock; |
|
|
|
bool status; |
|
|
|
for (unsigned char i=0; i<relayCount(); ++i) { |
|
|
|
|
|
|
@ -528,6 +547,7 @@ void _relayBoot() { |
|
|
|
DEBUG_MSG_P(PSTR("[RELAY] Relay #%u boot mode %u\n"), i, boot_mode); |
|
|
|
|
|
|
|
status = false; |
|
|
|
lock = RELAY_LOCK_DISABLED; |
|
|
|
switch (boot_mode) { |
|
|
|
case RELAY_BOOT_SAME: |
|
|
|
if (i < 8) { |
|
|
@ -541,6 +561,13 @@ void _relayBoot() { |
|
|
|
trigger_save = true; |
|
|
|
} |
|
|
|
break; |
|
|
|
case RELAY_BOOT_LOCKED_ON: |
|
|
|
status = true; |
|
|
|
lock = RELAY_LOCK_ON; |
|
|
|
break; |
|
|
|
case RELAY_BOOT_LOCKED_OFF: |
|
|
|
lock = RELAY_LOCK_OFF; |
|
|
|
break; |
|
|
|
case RELAY_BOOT_ON: |
|
|
|
status = true; |
|
|
|
break; |
|
|
@ -556,7 +583,10 @@ void _relayBoot() { |
|
|
|
#else
|
|
|
|
_relays[i].change_time = millis(); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
_relays[i].lock = lock; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Save if there is any relay in the RELAY_BOOT_TOGGLE mode
|
|
|
|
if (trigger_save) { |
|
|
@ -599,9 +629,15 @@ bool _relayWebSocketOnKeyCheck(const char * key, JsonVariant& value) { |
|
|
|
} |
|
|
|
|
|
|
|
void _relayWebSocketUpdate(JsonObject& root) { |
|
|
|
JsonArray& relay = root.createNestedArray("relayStatus"); |
|
|
|
JsonObject& state = root.createNestedObject("relayState"); |
|
|
|
state["size"] = relayCount(); |
|
|
|
|
|
|
|
JsonArray& status = state.createNestedArray("status"); |
|
|
|
JsonArray& lock = state.createNestedArray("lock"); |
|
|
|
|
|
|
|
for (unsigned char i=0; i<relayCount(); i++) { |
|
|
|
relay.add<uint8_t>(_relays[i].target_status); |
|
|
|
status.add<uint8_t>(_relays[i].target_status); |
|
|
|
lock.add(_relays[i].lock); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|