support held button

This commit is contained in:
Karl Hudgell 2024-09-20 21:02:54 +01:00
parent 78f46cfce1
commit a7a38c6633

View File

@ -31,8 +31,20 @@ def button_callback_2(channel):
control_player(client, "SKIP") control_player(client, "SKIP")
control_player(client, "PLAY") control_player(client, "PLAY")
# Handling button 3 with a hold check
def button_callback_3(channel): def button_callback_3(channel):
print("Button 3 pressed!") start_time = time.time()
# Wait until the button is released or held for more than 3 seconds
while GPIO.input(BUTTON_PINS[2]) == GPIO.LOW: # Button is pressed (active low)
if time.time() - start_time >= 3: # Check if 3 seconds have passed
print("Button 3 held for 3 seconds! Sending RADIO2.")
client = create_client()
control_player(client, "RADIO2")
return # Exit after sending RADIO2
# If button was not held for 3 seconds, send RADIO
print("Button 3 pressed briefly! Sending RADIO.")
client = create_client() client = create_client()
control_player(client, "RADIO") control_player(client, "RADIO")