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
|
# 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,17 +300,28 @@ 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:
|
||||||
# Clear screen (ANSI escape)
|
now = time.time()
|
||||||
sys.stdout.write("\033[2J\033[H")
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
# Draw frame
|
# Only redraw if enough time has passed (reduces flicker)
|
||||||
frame = self.draw_frame()
|
if now - self.last_draw >= DISPLAY_INTERVAL:
|
||||||
sys.stdout.write(frame)
|
# Clear screen (ANSI escape)
|
||||||
sys.stdout.write("\n")
|
sys.stdout.write("\033[2J\033[H")
|
||||||
sys.stdout.flush()
|
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)
|
time.sleep(UPDATE_INTERVAL)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|||||||
Reference in New Issue
Block a user