From a9630b9d053036960ac03d2de74c97fb4f7a400d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 2 Oct 2020 17:32:45 +0200 Subject: [PATCH] Change pulsetime to allow use for all relays Change pulsetime to allow use for all relays with 8 interleaved so ``Pulsetime1`` is valid for Relay1, Relay9, Relay17 etc. (#9279) --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 1 + tasmota/support_tasmota.ino | 23 ++++++++++++----------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index b8bb36cef..be79a720a 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -66,5 +66,6 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota - Change new IR Raw compact format (#9444) - Change MAX31865 driver to support up to 6 thermocouples selected by ``MX31865 CS`` instead of ``SSPI CS`` (#9103) - Change A4988 optional microstep pin selection +- Change pulsetime to allow use for all relays with 8 interleaved so ``Pulsetime1`` is valid for Relay1, Relay9, Relay17 etc. (#9279) - Add optional support for Mitsubishi Electric HVAC by David Gwynne (#9237) - Add optional support for Orno WE517-Modbus energy meter by Maxime Vincent (#9353) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 5d8b7ed5f..cc2ecb29c 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -9,6 +9,7 @@ - Change new IR Raw compact format (#9444) - Change MAX31865 driver to support up to 6 thermocouples selected by ``MX31865 CS`` instead of ``SSPI CS`` (#9103) - Change A4988 optional microstep pin selection +- Change pulsetime to allow use for all relays with 8 interleaved so ``Pulsetime1`` is valid for Relay1, Relay9, Relay17 etc. (#9279) - Add optional support for Mitsubishi Electric HVAC by David Gwynne (#9237) - Add optional support for Orno WE517-Modbus energy meter by Maxime Vincent (#9353) diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 62ba70a33..219f2e039 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -333,8 +333,8 @@ void SetPowerOnState(void) bitWrite(power, i, digitalRead(Pin(GPIO_REL1, i)) ^ bitRead(rel_inverted, i)); } } - if ((i < MAX_PULSETIMERS) && (bitRead(power, i) || (POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate))) { - SetPulseTimer(i, Settings.pulse_timer[i]); + if (bitRead(power, i) || (POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate)) { + SetPulseTimer(i % MAX_PULSETIMERS, Settings.pulse_timer[i % MAX_PULSETIMERS]); } } blink_powersave = power; @@ -531,9 +531,8 @@ void ExecuteCommandPower(uint32_t device, uint32_t state, uint32_t source) } active_device = device; - if (device <= MAX_PULSETIMERS) { - SetPulseTimer(device -1, 0); - } + SetPulseTimer((device -1) % MAX_PULSETIMERS, 0); + power_t mask = 1 << (device -1); // Device to control if (state <= POWER_TOGGLE) { if ((blink_mask & mask)) { @@ -589,9 +588,9 @@ void ExecuteCommandPower(uint32_t device, uint32_t state, uint32_t source) if (publish_power && Settings.flag3.hass_tele_on_power) { // SetOption59 - Send tele/%topic%/STATE in addition to stat/%topic%/RESULT MqttPublishTeleState(); } - if (device <= MAX_PULSETIMERS) { // Restart PulseTime if powered On - SetPulseTimer(device -1, (((POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? ~power : power) & mask) ? Settings.pulse_timer[device -1] : 0); - } + + // Restart PulseTime if powered On + SetPulseTimer((device -1) % MAX_PULSETIMERS, (((POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? ~power : power) & mask) ? Settings.pulse_timer[(device -1) % MAX_PULSETIMERS] : 0); } else if (POWER_BLINK == state) { if (!(blink_mask & mask)) { @@ -887,7 +886,9 @@ void Every100mSeconds(void) if (pulse_timer[i] != 0L) { // Timer active? if (TimeReached(pulse_timer[i])) { // Timer finished? pulse_timer[i] = 0L; // Turn off this timer - ExecuteCommandPower(i +1, (POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? POWER_ON : POWER_OFF, SRC_PULSETIMER); + for (uint32_t j = 0; j < devices_present; j = j +MAX_PULSETIMERS) { + ExecuteCommandPower(i + j +1, (POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? POWER_ON : POWER_OFF, SRC_PULSETIMER); + } } } } @@ -1067,8 +1068,8 @@ void Every250mSeconds(void) if (save_data_counter <= 0) { if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart power_t mask = POWER_MASK; - for (uint32_t i = 0; i < MAX_PULSETIMERS; i++) { - if ((Settings.pulse_timer[i] > 0) && (Settings.pulse_timer[i] < 30)) { // 3 seconds + for (uint32_t i = 0; i < devices_present; i++) { + if ((Settings.pulse_timer[i % MAX_PULSETIMERS] > 0) && (Settings.pulse_timer[i % MAX_PULSETIMERS] < 30)) { // 3 seconds mask &= ~(1 << i); } }