diff --git a/CHANGELOG.md b/CHANGELOG.md index 633172b6b..6aacc2a7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +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 +- Berry `FUNC_BUTTON_MULTI_PRESSED` event and make `FUNC_BUTTON_PRESSED` called only on state changes and once per second ### 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 dc6281b39..5e90a1130 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino @@ -947,13 +947,17 @@ bool Xdrv52(uint32_t function) 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); + { + static uint32_t timer_last_button_sent = 0; + // XdrvMailbox.index = button_index; + // XdrvMailbox.payload = button; + // XdrvMailbox.command_code = Button.last_state[button_index]; + if ((XdrvMailbox.payload != XdrvMailbox.command_code) || TimeReached(timer_last_button_sent)) { // fire event only when state changes + timer_last_button_sent = millis() + 1000; // wait for 1 second + 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: