From 6842b534255dc004ab1103f831dd87e1856ea127 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Sun, 30 Jun 2024 19:14:32 +0200 Subject: [PATCH] Berry `FUNC_BUTTON_MULTI_PRESSED` event and make `FUNC_BUTTON_PRESSED` called only on state changes (#21709) --- CHANGELOG.md | 1 + .../tasmota_xdrv_driver/xdrv_52_9_berry.ino | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4021fc26b..633172b6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. - Berry `tasmota.rtc("config_time")` (#21698) - Berry `math.min()` and `math.max()` (#21705) - Berry `FUNC_ANY_KEY` event calling `any_key()` (#21708) +- Berry `FUNC_BUTTON_MULTI_PRESSED` event and make `FUNC_BUTTON_PRESSED` called only on state changes ### Breaking Changed diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino index 7384f1ebb..dc6281b39 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino @@ -946,6 +946,23 @@ bool Xdrv52(uint32_t function) case FUNC_SET_DEVICE_POWER: result = callBerryEventDispatcher(PSTR("set_power_handler"), nullptr, XdrvMailbox.index, nullptr); break; + case FUNC_BUTTON_PRESSED: + // XdrvMailbox.index = button_index; + // XdrvMailbox.payload = button; + // XdrvMailbox.command_code = Button.last_state[button_index]; + if (XdrvMailbox.payload != XdrvMailbox.command_code) { // fire event only when state changes + result = callBerryEventDispatcher(PSTR("button_pressed"), nullptr, + (XdrvMailbox.payload & 0xFF) << 16 | (XdrvMailbox.command_code & 0xFF) << 8 | (XdrvMailbox.index & 0xFF) , + nullptr); + } + break; + case FUNC_BUTTON_MULTI_PRESSED: + // XdrvMailbox.index = button_index; + // XdrvMailbox.payload = Button.press_counter[button_index]; + result = callBerryEventDispatcher(PSTR("button_multi_pressed"), nullptr, + (XdrvMailbox.payload & 0xFF) << 8 | (XdrvMailbox.index & 0xFF) , + nullptr); + break; case FUNC_ANY_KEY: // XdrvMailbox.payload = device_save << 24 | key << 16 | state << 8 | device; // key 0 = KEY_BUTTON = button_topic @@ -1014,10 +1031,6 @@ bool Xdrv52(uint32_t function) callBerryEventDispatcher(PSTR("after_teleperiod"), nullptr, 0, nullptr); break; - case FUNC_BUTTON_PRESSED: - callBerryEventDispatcher(PSTR("button_pressed"), nullptr, 0, nullptr); - break; - case FUNC_ACTIVE: result = true; break;