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
This commit is contained in:
2026-03-12 04:13:54 +00:00
parent 5b18116a41
commit 038905fe51
+15 -1
View File
@@ -31,7 +31,8 @@ except ImportError:
# Configuration # Configuration
API_BASE = "http://localhost:5000" 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" TTY_PATH = "/dev/tty1"
# ANSI color codes # ANSI color codes
@@ -72,6 +73,8 @@ class StatusDisplay:
def __init__(self): def __init__(self):
self.running = True self.running = True
self.last_update = 0 self.last_update = 0
self.last_draw = 0
self.last_frame = None
self.data = { self.data = {
"nail1": {}, "nail1": {},
"nail2": {}, "nail2": {},
@@ -297,8 +300,17 @@ class StatusDisplay:
fetch_thread.daemon = True fetch_thread.daemon = True
fetch_thread.start() fetch_thread.start()
# Initial draw
sys.stdout.write("\033[2J\033[H")
sys.stdout.flush()
self.last_draw = time.time()
try: try:
while self.running: while self.running:
now = time.time()
# Only redraw if enough time has passed (reduces flicker)
if now - self.last_draw >= DISPLAY_INTERVAL:
# Clear screen (ANSI escape) # Clear screen (ANSI escape)
sys.stdout.write("\033[2J\033[H") sys.stdout.write("\033[2J\033[H")
sys.stdout.flush() sys.stdout.flush()
@@ -309,6 +321,8 @@ class StatusDisplay:
sys.stdout.write("\n") sys.stdout.write("\n")
sys.stdout.flush() sys.stdout.flush()
self.last_draw = now
time.sleep(UPDATE_INTERVAL) time.sleep(UPDATE_INTERVAL)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass