From c4cbae7f68209d08c23371eda56d39af49bd1b36 Mon Sep 17 00:00:00 2001 From: jeanGaston Date: Sun, 9 Jun 2024 22:33:56 +0200 Subject: [PATCH] Fix bug The screen saver wouldn't launch --- Client/main.py | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/Client/main.py b/Client/main.py index ac01e16..7bbbd38 100644 --- a/Client/main.py +++ b/Client/main.py @@ -114,7 +114,6 @@ def draw_circle(oled, x0, y0, radius, color): # Screensaver function with circular wave animation def screensaver(): """ -<<<<<<< Updated upstream Activate the screensaver with RF-AD animation. This function activates the screensaver by displaying an RF-AD animation moving across the screen. @@ -124,9 +123,6 @@ def screensaver(): - screensaver_thread_running (bool): Flag indicating if the screensaver thread is running. - last_activity_time (float): Timestamp of the last activity. -======= - Screensaver function with circular wave animation ->>>>>>> Stashed changes """ global screensaver_active, screensaver_thread_running text = "RF-AD" @@ -135,22 +131,25 @@ def screensaver(): radius = 36 max_radius = 64 # Maximum radius for the animation while screensaver_active: - oled.fill(0) - oled.text(text, 44, 28) - - # Draw expanding circles - for r in range(radius, max_radius, 5): - draw_circle(oled, center_x, center_y, r, 1) - - oled.show() - radius += 1 - if radius > max_radius: - radius = 36 - - time.sleep(0.01) - + try: + oled.fill(0) + oled.text(text, 44, 28) + + # Draw expanding circles + for r in range(radius, max_radius, 5): + draw_circle(oled, center_x, center_y, r, 1) + + oled.show() + radius += 1 + if radius > max_radius: + radius = 36 + + time.sleep(0.01) + except Exception as e: + break # Check for activity if time.time() - last_activity_time <= 60: + oled.fill(0) screensaver_active = False screensaver_thread_running = False break @@ -171,10 +170,10 @@ def start_screensaver_thread(): if not screensaver_thread_running: screensaver_active = True screensaver_thread_running = True - _thread.start_new_thread(screensaver, ()) + _thread.start_new_thread(screensaver,()) -def handle_inactivity(): +def handle_inactivity(timer): """ Handle user inactivity by starting the screensaver if necessary.