Berry FUNC_BUTTON_MULTI_PRESSED event and make FUNC_BUTTON_PRESSED called only on state changes and once per second (#21711)

This commit is contained in:
s-hadinger 2024-06-30 21:00:14 +02:00 committed by GitHub
parent 6842b53425
commit 2cc785bf20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 8 deletions

View File

@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file.
- Berry `tasmota.rtc("config_time")` (#21698) - Berry `tasmota.rtc("config_time")` (#21698)
- Berry `math.min()` and `math.max()` (#21705) - Berry `math.min()` and `math.max()` (#21705)
- Berry `FUNC_ANY_KEY` event calling `any_key()` (#21708) - 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 ### Breaking Changed

View File

@ -947,13 +947,17 @@ bool Xdrv52(uint32_t function)
result = callBerryEventDispatcher(PSTR("set_power_handler"), nullptr, XdrvMailbox.index, nullptr); result = callBerryEventDispatcher(PSTR("set_power_handler"), nullptr, XdrvMailbox.index, nullptr);
break; break;
case FUNC_BUTTON_PRESSED: case FUNC_BUTTON_PRESSED:
// XdrvMailbox.index = button_index; {
// XdrvMailbox.payload = button; static uint32_t timer_last_button_sent = 0;
// XdrvMailbox.command_code = Button.last_state[button_index]; // XdrvMailbox.index = button_index;
if (XdrvMailbox.payload != XdrvMailbox.command_code) { // fire event only when state changes // XdrvMailbox.payload = button;
result = callBerryEventDispatcher(PSTR("button_pressed"), nullptr, // XdrvMailbox.command_code = Button.last_state[button_index];
(XdrvMailbox.payload & 0xFF) << 16 | (XdrvMailbox.command_code & 0xFF) << 8 | (XdrvMailbox.index & 0xFF) , if ((XdrvMailbox.payload != XdrvMailbox.command_code) || TimeReached(timer_last_button_sent)) { // fire event only when state changes
nullptr); 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; break;
case FUNC_BUTTON_MULTI_PRESSED: case FUNC_BUTTON_MULTI_PRESSED: