Skip to content

Commit

Permalink
relay: properly handle zero interlock time
Browse files Browse the repository at this point in the history
schedule when >0, execute immediately otherwise
  • Loading branch information
mcspr committed Jan 17, 2023
1 parent e2c8dd7 commit 11c8978
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions code/espurna/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1664,33 +1664,34 @@ void _relaySyncRelaysDelay(size_t first, size_t second) {
});
}

void _relaySyncUnlock() {
bool unlock = true;
bool all_off = true;
for (const auto& relay : _relays) {
unlock = unlock && (relay.current_status == relay.target_status);
if (!unlock) break;
all_off = all_off && !relay.current_status;
}

if (unlock) {
static const auto action = []() {
_relayUnlockAll();
void _relaySyncUnlockAction() {
_relayUnlockAll();
#if WEB_SUPPORT
_relayScheduleWsReport();
_relayScheduleWsReport();
#endif
};
}


void _relaySyncUnlock() {
bool interlock { false };

for (const auto& relay : _relays) {
if (relay.current_status != relay.target_status) {
return;
}

if (all_off) {
_relay_sync_timer.schedule(_relay_delay_interlock, action);
} else {
action();
if (relay.current_status) {
interlock = true;
}
}
}

void _relaySync() {
_relay_sync_timer.process();
if (interlock && (_relay_delay_interlock.count() > 0)) {
_relay_sync_timer.schedule(
_relay_delay_interlock, _relaySyncUnlockAction);
} else {
_relay_sync_timer.stop();
_relaySyncUnlockAction();
}
}

void _relaySyncTryUnlock() {
Expand All @@ -1708,6 +1709,10 @@ void _relaySyncTryUnlock() {
}
}

void _relaySync() {
_relay_sync_timer.process();
}

} // namespace

// -----------------------------------------------------------------------------
Expand Down

0 comments on commit 11c8978

Please sign in to comment.