Skip to content

Commit 2cc785b

Browse files
authored
Berry FUNC_BUTTON_MULTI_PRESSED event and make FUNC_BUTTON_PRESSED called only on state changes and once per second (#21711)
1 parent 6842b53 commit 2cc785b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file.
99
- Berry `tasmota.rtc("config_time")` (#21698)
1010
- Berry `math.min()` and `math.max()` (#21705)
1111
- Berry `FUNC_ANY_KEY` event calling `any_key()` (#21708)
12-
- Berry `FUNC_BUTTON_MULTI_PRESSED` event and make `FUNC_BUTTON_PRESSED` called only on state changes
12+
- Berry `FUNC_BUTTON_MULTI_PRESSED` event and make `FUNC_BUTTON_PRESSED` called only on state changes and once per second
1313

1414
### Breaking Changed
1515

tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -947,13 +947,17 @@ bool Xdrv52(uint32_t function)
947947
result = callBerryEventDispatcher(PSTR("set_power_handler"), nullptr, XdrvMailbox.index, nullptr);
948948
break;
949949
case FUNC_BUTTON_PRESSED:
950-
// XdrvMailbox.index = button_index;
951-
// XdrvMailbox.payload = button;
952-
// XdrvMailbox.command_code = Button.last_state[button_index];
953-
if (XdrvMailbox.payload != XdrvMailbox.command_code) { // fire event only when state changes
954-
result = callBerryEventDispatcher(PSTR("button_pressed"), nullptr,
955-
(XdrvMailbox.payload & 0xFF) << 16 | (XdrvMailbox.command_code & 0xFF) << 8 | (XdrvMailbox.index & 0xFF) ,
956-
nullptr);
950+
{
951+
static uint32_t timer_last_button_sent = 0;
952+
// XdrvMailbox.index = button_index;
953+
// XdrvMailbox.payload = button;
954+
// XdrvMailbox.command_code = Button.last_state[button_index];
955+
if ((XdrvMailbox.payload != XdrvMailbox.command_code) || TimeReached(timer_last_button_sent)) { // fire event only when state changes
956+
timer_last_button_sent = millis() + 1000; // wait for 1 second
957+
result = callBerryEventDispatcher(PSTR("button_pressed"), nullptr,
958+
(XdrvMailbox.payload & 0xFF) << 16 | (XdrvMailbox.command_code & 0xFF) << 8 | (XdrvMailbox.index & 0xFF) ,
959+
nullptr);
960+
}
957961
}
958962
break;
959963
case FUNC_BUTTON_MULTI_PRESSED:

0 commit comments

Comments
 (0)