move client

This commit is contained in:
Karl Hudgell 2024-09-20 21:12:59 +01:00
parent c026592e9f
commit f3b1f7653c

View File

@ -34,20 +34,18 @@ def button_callback_2(channel):
# Handling button 3 with a hold check # Handling button 3 with a hold check
def button_callback_3(channel): def button_callback_3(channel):
start_time = time.time() start_time = time.time()
client = create_client()
# Wait until the button is released or held for more than 3 seconds # 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) 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 if time.time() - start_time >= 3: # Check if 3 seconds have passed
print("Button 3 held for 3 seconds! Sending RADIO2.") print("Button 3 held for 3 seconds! Sending RADIO2.")
disc_data = check_current_disc(client) disc_data = check_current_disc(client)
client = create_client()
control_player(client, f"{disc_data[0]}:{disc_data[1]}:{disc_data[2]}:RESET") control_player(client, f"{disc_data[0]}:{disc_data[1]}:{disc_data[2]}:RESET")
control_player(client, f"{disc_data[0]}:{disc_data[1]}:{disc_data[2]}:{disc_data[3]}") control_player(client, f"{disc_data[0]}:{disc_data[1]}:{disc_data[2]}:{disc_data[3]}")
return # Exit after sending RADIO2 return # Exit after sending RADIO2
# If button was not held for 3 seconds, send RADIO # If button was not held for 3 seconds, send RADIO
print("Button 3 pressed briefly! Sending RADIO.") print("Button 3 pressed briefly! Sending RADIO.")
client = create_client()
control_player(client, "RADIO") control_player(client, "RADIO")
# Add event detection for each button press # Add event detection for each button press