Skip to content

Commit

Permalink
Berry FUNC_BUTTON_MULTI_PRESSED event and make `FUNC_BUTTON_PRESSED…
Browse files Browse the repository at this point in the history
…` called only on state changes and once per second (arendst#21711)
  • Loading branch information
s-hadinger authored Jun 30, 2024
1 parent 6842b53 commit 2cc785b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 11 additions & 7 deletions tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2cc785b

Please sign in to comment.