Skip to content

Commit

Permalink
relay: compare sum of physical + dummy relays instead of just dummy (x…
Browse files Browse the repository at this point in the history
…oseperez#2012)

* relay: compare sum of physical + dummy relays instead of just dummy

* typo
  • Loading branch information
mcspr authored Nov 26, 2019
1 parent a6c5c7e commit 5c49db8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion code/espurna/relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ const String& relayPayloadToggle();

const char* relayPayload(RelayStatus status);

void relaySetupDummy(unsigned char size, bool reconfigure = false);
void relaySetupDummy(size_t size, bool reconfigure = false);

14 changes: 8 additions & 6 deletions code/espurna/relay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct relay_t {

std::vector<relay_t> _relays;
bool _relayRecursive = false;
uint8_t _relayDummy = DUMMY_RELAY_COUNT;
size_t _relayDummy = 0;

unsigned long _relay_flood_window = (1000 * RELAY_FLOOD_WINDOW);
unsigned long _relay_flood_changes = RELAY_FLOOD_CHANGES;
Expand Down Expand Up @@ -256,7 +256,7 @@ void _relayProviderStatus(unsigned char id, bool status) {
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT

// Real relays
uint8_t physical = _relays.size() - _relayDummy;
size_t physical = _relays.size() - _relayDummy;

// Support for a mixed of dummy and real relays
// Reference: https://github.com/xoseperez/espurna/issues/1305
Expand Down Expand Up @@ -1360,13 +1360,15 @@ void _relayLoop() {
}

// Dummy relays for virtual light switches, Sonoff Dual, Sonoff RF Bridge and Tuya
void relaySetupDummy(unsigned char size, bool reconfigure) {
void relaySetupDummy(size_t size, bool reconfigure) {

size = constrain(size + _relays.size(), _relays.size(), RELAYS_MAX);
if (size == _relays.size()) return;
if (size == _relayDummy) return;

const size_t new_size = ((_relays.size() - _relayDummy) + size);
if (new_size > RELAYS_MAX) return;

_relayDummy = size;
_relays.resize(size);
_relays.resize(new_size);

if (reconfigure) {
_relayConfigure();
Expand Down

0 comments on commit 5c49db8

Please sign in to comment.