From 96d37ec535846232e63f7ecf09d1b4e3849255b5 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 12 Jul 2020 18:53:57 +0200 Subject: [PATCH] Add Rotary features Add On/Off functionality to rotary dial (#8263) --- tasmota/support_button.ino | 2 +- tasmota/support_rotary.ino | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index 2d7c6a415..e6e6e27ea 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -303,7 +303,7 @@ void ButtonHandler(void) } } #ifdef ROTARY_V1 - if (!((0 == button_index) && RotaryButtonPressed())) { + if (!RotaryButtonPressed(button_index)) { #endif if (!Settings.flag3.mqtt_buttons && single_press && SendKey(KEY_BUTTON, button_index + Button.press_counter[button_index], POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set // Success diff --git a/tasmota/support_rotary.ino b/tasmota/support_rotary.ino index cfe549a5f..3367b70d4 100644 --- a/tasmota/support_rotary.ino +++ b/tasmota/support_rotary.ino @@ -91,13 +91,6 @@ struct ROTARY { void update_rotary(void) ICACHE_RAM_ATTR; void update_rotary(void) { if (Rotary.busy) { return; } - bool powered_on = (power); -#ifdef USE_LIGHT - if (!Settings.flag4.rotary_uses_rules) { // SetOption98 - Use rules instead of light control - powered_on = (LightPowerIRAM()); - } -#endif // USE_LIGHT - if (!powered_on) { return; } #ifdef ROTARY_OPTION1 // https://github.com/PaulStoffregen/Encoder/blob/master/Encoder.h @@ -212,8 +205,10 @@ void update_rotary(void) { #endif // ROTARY_OPTION3 } -bool RotaryButtonPressed(void) { +//bool RotaryButtonPressed(void) { +bool RotaryButtonPressed(uint32_t button_index) { if (!Rotary.present) { return false; } + if (0 != button_index) { return false; } bool powered_on = (power); #ifdef USE_LIGHT @@ -254,6 +249,13 @@ void RotaryHandler(void) { Rotary.timeout--; if (!Rotary.timeout) { Rotary.direction = 0; +#ifdef USE_LIGHT + if (!Settings.flag4.rotary_uses_rules) { // SetOption98 - Use rules instead of light control + LightState(0); + MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_DIMMER)); + XdrvRulesProcess(); + } +#endif // USE_LIGHT } } if (Rotary.last_position == Rotary.position) { return; }