@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user