From ecd78bfd96c6693f0358f0a0636a3a3c2f1cb713 Mon Sep 17 00:00:00 2001 From: Paul C Diem Date: Sat, 13 Mar 2021 14:13:44 -0600 Subject: [PATCH] Use SO32 for power button hold time --- tasmota/xdrv_35_pwm_dimmer.ino | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/tasmota/xdrv_35_pwm_dimmer.ino b/tasmota/xdrv_35_pwm_dimmer.ino index 555ec1a67..d30e7cba1 100644 --- a/tasmota/xdrv_35_pwm_dimmer.ino +++ b/tasmota/xdrv_35_pwm_dimmer.ino @@ -755,21 +755,8 @@ bool Xdrv35(uint8_t function) // If the button is pressed, ... if (!XdrvMailbox.payload) { - // If the button was just pressed, flag the button as pressed, set the hold time and - // increment the buttons pressed count. + // If the button was just pressed, ... if (!button_pressed[button_index]) { - button_pressed[button_index] = true; - uint32_t hold_delay = 250; - if (button_index == power_button_index) { -#ifdef USE_PWM_DIMMER_REMOTE - if (!(active_remote_pwm_dimmer ? active_remote_pwm_dimmer->power_on : TasmotaGlobal.power)) hold_delay = 500; -#else // USE_PWM_DIMMER_REMOTE - if (!TasmotaGlobal.power) hold_delay = 500; -#endif // USE_PWM_DIMMER_REMOTE - } - button_hold_time[button_index] = now + hold_delay; - buttons_pressed++; - if (buttons_pressed > 1) multibutton_in_progress = true; #ifdef USE_PWM_DIMMER_REMOTE // If there are no other buttons pressed right now and remote mode is enabled, make the @@ -785,7 +772,7 @@ bool Xdrv35(uint8_t function) // Top 0 1 1 0 // Middle 1 2 15 0 // Bottom 15 3 15 1 - if (buttons_pressed == 1 && Settings.flag4.multiple_device_groups) { + if (!buttons_pressed && Settings.flag4.multiple_device_groups) { power_button_index = button_index; down_button_index = (Pin(GPIO_KEY1, power_button_index) == 15 ? TasmotaGlobal.gpio_pin[1] : TasmotaGlobal.gpio_pin[15]) - 32; active_remote_pwm_dimmer = nullptr; @@ -793,9 +780,17 @@ bool Xdrv35(uint8_t function) active_remote_pwm_dimmer = &remote_pwm_dimmers[power_button_index]; } #endif // USE_PWM_DIMMER_REMOTE + + // Flag the button as pressed, increment the buttons pressed count and set the hold time. + button_pressed[button_index] = true; + buttons_pressed++; + if (buttons_pressed > 1) multibutton_in_progress = true; + uint32_t hold_delay = 250; + if (button_index == power_button_index) hold_delay = Settings.param[P_HOLD_TIME] * 10; + button_hold_time[button_index] = now + hold_delay; } - // If hold time has arrived and a rule is enabled that handles the button hold, handle it. + // If hold time has arrived and no rule is enabled that handles the button hold, handle it. else if (button_hold_time[button_index] <= now) { #ifdef USE_RULES sprintf(TasmotaGlobal.mqtt_data, PSTR("{\"Button%u\":{\"State\":3}}"), button_index + 1);