Skip to content

Commit 6842b53

Browse files
authored
Berry FUNC_BUTTON_MULTI_PRESSED event and make FUNC_BUTTON_PRESSED called only on state changes (#21709)
1 parent 65588b8 commit 6842b53

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +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
1213

1314
### Breaking Changed
1415

tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,23 @@ bool Xdrv52(uint32_t function)
946946
case FUNC_SET_DEVICE_POWER:
947947
result = callBerryEventDispatcher(PSTR("set_power_handler"), nullptr, XdrvMailbox.index, nullptr);
948948
break;
949+
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);
957+
}
958+
break;
959+
case FUNC_BUTTON_MULTI_PRESSED:
960+
// XdrvMailbox.index = button_index;
961+
// XdrvMailbox.payload = Button.press_counter[button_index];
962+
result = callBerryEventDispatcher(PSTR("button_multi_pressed"), nullptr,
963+
(XdrvMailbox.payload & 0xFF) << 8 | (XdrvMailbox.index & 0xFF) ,
964+
nullptr);
965+
break;
949966
case FUNC_ANY_KEY:
950967
// XdrvMailbox.payload = device_save << 24 | key << 16 | state << 8 | device;
951968
// key 0 = KEY_BUTTON = button_topic
@@ -1014,10 +1031,6 @@ bool Xdrv52(uint32_t function)
10141031
callBerryEventDispatcher(PSTR("after_teleperiod"), nullptr, 0, nullptr);
10151032
break;
10161033

1017-
case FUNC_BUTTON_PRESSED:
1018-
callBerryEventDispatcher(PSTR("button_pressed"), nullptr, 0, nullptr);
1019-
break;
1020-
10211034
case FUNC_ACTIVE:
10221035
result = true;
10231036
break;

0 commit comments

Comments
 (0)