From ca40d2d27aa13d6ae286402e5402932f1f4989c4 Mon Sep 17 00:00:00 2001 From: ezn Date: Sun, 17 Nov 2024 18:07:02 +0000 Subject: [PATCH] deactivate cuttent all current buttons once one of the current buttons is pressed --- p33_from31.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/p33_from31.py b/p33_from31.py index d3dab2f..f834ff2 100644 --- a/p33_from31.py +++ b/p33_from31.py @@ -156,7 +156,7 @@ def wait_for_button_press(video_info): if pressed_button: # Find the index of the pressed button in the video_info['buttons'] button_index = video_info["buttons"].index(pressed_button) - + # Now select the next video based on this index if button_index < len(video_info["next_videos"]): next_video_id = video_info["next_videos"][button_index] # Use the index of the button press @@ -173,7 +173,6 @@ def wait_for_button_press(video_info): no_press_count = 0 print(f"Restarting service: {service_name}") subprocess.run(["sudo", "systemctl", "restart", service_name], check=True) - restart_service(service_name) print(f"Service {service_name} restarted successfully.") exit() else: @@ -185,12 +184,23 @@ def wait_for_button_press(video_info): print("No next video available. Restarting from Video 1.") print(f"Restarting service: {service_name}") subprocess.run(["sudo", "systemctl", "restart", service_name], check=True) - restart_service(service_name) print(f"Service {service_name} restarted successfully.") exit() time.sleep(0.1) # Small delay to reduce CPU usage +# Function to deactivate all buttons and LEDs +def deactivate_all_buttons_and_leds(): + print("Deactivating all buttons and LEDs...") + # Deactivate all buttons + for button in buttons: + GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) + # Turn off all LEDs + for led in leds: + GPIO.output(led, GPIO.LOW) + time.sleep(0.1) # Ensure all GPIO changes take effect + print("All buttons and LEDs deactivated.") + # Function to handle the video chain def handle_video_chain(video_id): video_info = video_paths.get(video_id) @@ -203,6 +213,7 @@ def handle_video_chain(video_id): play_video(video_info["video"], loop=True) else: play_video(video_info["video"], loop=False) + deactivate_all_buttons_and_leds() activate_before_video_ends(video_info) wait_for_button_press(video_info)