Browse Source

relay: compare sum of physical + dummy relays instead of just dummy (#2012)

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

* typo
master
Max Prokhorov 5 years ago
committed by GitHub
parent
commit
5c49db89af
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions
  1. +1
    -1
      code/espurna/relay.h
  2. +8
    -6
      code/espurna/relay.ino

+ 1
- 1
code/espurna/relay.h View File

@ -68,5 +68,5 @@ const String& relayPayloadToggle();
const char* relayPayload(RelayStatus status); const char* relayPayload(RelayStatus status);
void relaySetupDummy(unsigned char size, bool reconfigure = false);
void relaySetupDummy(size_t size, bool reconfigure = false);

+ 8
- 6
code/espurna/relay.ino View File

@ -82,7 +82,7 @@ struct relay_t {
std::vector<relay_t> _relays; std::vector<relay_t> _relays;
bool _relayRecursive = false; 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_window = (1000 * RELAY_FLOOD_WINDOW);
unsigned long _relay_flood_changes = RELAY_FLOOD_CHANGES; unsigned long _relay_flood_changes = RELAY_FLOOD_CHANGES;
@ -256,7 +256,7 @@ void _relayProviderStatus(unsigned char id, bool status) {
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT #if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT
// Real relays // Real relays
uint8_t physical = _relays.size() - _relayDummy;
size_t physical = _relays.size() - _relayDummy;
// Support for a mixed of dummy and real relays // Support for a mixed of dummy and real relays
// Reference: https://github.com/xoseperez/espurna/issues/1305 // Reference: https://github.com/xoseperez/espurna/issues/1305
@ -1360,13 +1360,15 @@ void _relayLoop() {
} }
// Dummy relays for virtual light switches, Sonoff Dual, Sonoff RF Bridge and Tuya // 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; _relayDummy = size;
_relays.resize(size);
_relays.resize(new_size);
if (reconfigure) { if (reconfigure) {
_relayConfigure(); _relayConfigure();


Loading…
Cancel
Save