From 038905fe51d38c55594e5f4652cc395ad7ac8dba Mon Sep 17 00:00:00 2001 From: Seth Date: Thu, 12 Mar 2026 04:13:54 +0000 Subject: [PATCH] Reduce flicker by increasing display refresh interval - Changed from 1-second full screen clear to 2-second redraws - Data fetches happen every 0.5 seconds for responsiveness - Reduces unnecessary screen clearing that was causing ASCII art to flicker - Keeps display stable and readable while still updating status in real-time - Deployed and verified on Pi --- piNail2/tty_status_display.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/piNail2/tty_status_display.py b/piNail2/tty_status_display.py index 88593f4..2af84c7 100644 --- a/piNail2/tty_status_display.py +++ b/piNail2/tty_status_display.py @@ -31,7 +31,8 @@ except ImportError: # Configuration API_BASE = "http://localhost:5000" -UPDATE_INTERVAL = 1.0 # seconds +UPDATE_INTERVAL = 0.5 # seconds between fetches +DISPLAY_INTERVAL = 2.0 # seconds between screen redraws TTY_PATH = "/dev/tty1" # ANSI color codes @@ -72,6 +73,8 @@ class StatusDisplay: def __init__(self): self.running = True self.last_update = 0 + self.last_draw = 0 + self.last_frame = None self.data = { "nail1": {}, "nail2": {}, @@ -297,17 +300,28 @@ class StatusDisplay: fetch_thread.daemon = True fetch_thread.start() + # Initial draw + sys.stdout.write("\033[2J\033[H") + sys.stdout.flush() + self.last_draw = time.time() + try: while self.running: - # Clear screen (ANSI escape) - sys.stdout.write("\033[2J\033[H") - sys.stdout.flush() + now = time.time() - # Draw frame - frame = self.draw_frame() - sys.stdout.write(frame) - sys.stdout.write("\n") - sys.stdout.flush() + # Only redraw if enough time has passed (reduces flicker) + if now - self.last_draw >= DISPLAY_INTERVAL: + # Clear screen (ANSI escape) + sys.stdout.write("\033[2J\033[H") + sys.stdout.flush() + + # Draw frame + frame = self.draw_frame() + sys.stdout.write(frame) + sys.stdout.write("\n") + sys.stdout.flush() + + self.last_draw = now time.sleep(UPDATE_INTERVAL) except KeyboardInterrupt: