hw_button_state service to control buttons individually

Solves #1934
This commit is contained in:
Edward Firmo
2024-03-19 11:13:55 +01:00
parent f28a02fd5d
commit cc756fda35
5 changed files with 65 additions and 23 deletions

View File

@@ -279,13 +279,16 @@ api:
# Hardware Button State Indication Service
- service: hw_button_state
variables:
left: bool # State for the left button indication bar
right: bool # State for the right button indication bar
button_mask: int # Bitwise value for buttons: 1 for "left button", 2 for "right button", 3 for both buttons
state: bool # State for the button(s) indication: true for active, false for inactive
then:
- lambda: |-
// Updates the visual state indication for hardware buttons
update_bitwise_setting(id(buttons_settings), left, ButtonSettings::ButtonLeft_State);
update_bitwise_setting(id(buttons_settings), right, ButtonSettings::ButtonRight_State);
// Use bitwise AND to check specific bits
if (button_mask & 1) // Checks if the least significant bit is set (left button)
update_bitwise_setting(id(buttons_settings), state, ButtonSettings::ButtonLeft_State);
if (button_mask & 2) // Checks if the second least significant bit is set (right button)
update_bitwise_setting(id(buttons_settings), state, ButtonSettings::ButtonRight_State);
// Refreshes the indication bars on the display
refresh_hardware_buttons_bars->execute();