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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user