mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
increase curses refresh rate
This commit is contained in:
parent
632c5be35e
commit
4e181f7fe3
1 changed files with 20 additions and 16 deletions
|
|
@ -4,9 +4,9 @@ import curses
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
|
import select
|
||||||
|
|
||||||
def start_ltc_stream():
|
def start_ltc_stream():
|
||||||
# Launch ffmpeg piped into ltcdump
|
|
||||||
ffmpeg = subprocess.Popen(
|
ffmpeg = subprocess.Popen(
|
||||||
["ffmpeg", "-f", "alsa", "-i", "default", "-ac", "1", "-ar", "48000", "-f", "s16le", "-"],
|
["ffmpeg", "-f", "alsa", "-i", "default", "-ac", "1", "-ar", "48000", "-f", "s16le", "-"],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
|
@ -17,39 +17,43 @@ def start_ltc_stream():
|
||||||
stdin=ffmpeg.stdout,
|
stdin=ffmpeg.stdout,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
text=True
|
text=True,
|
||||||
|
bufsize=1 # Line-buffered
|
||||||
)
|
)
|
||||||
ffmpeg.stdout.close() # Let ltcdump consume the pipe
|
ffmpeg.stdout.close()
|
||||||
return ffmpeg, ltcdump
|
return ffmpeg, ltcdump
|
||||||
|
|
||||||
def main(stdscr):
|
def main(stdscr):
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
stdscr.nodelay(True)
|
stdscr.nodelay(True)
|
||||||
|
|
||||||
stdscr.addstr(1, 2, "🌀 NTP Timeturner Status")
|
|
||||||
stdscr.addstr(3, 4, "Streaming LTC from default input...")
|
|
||||||
|
|
||||||
ffmpeg_proc, ltcdump_proc = start_ltc_stream()
|
ffmpeg_proc, ltcdump_proc = start_ltc_stream()
|
||||||
|
|
||||||
latest_tc = "⌛ Waiting for LTC..."
|
latest_tc = "⌛ Waiting for LTC..."
|
||||||
last_refresh = time.time()
|
last_update = time.time()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
stdscr.clear()
|
# Check for new output from ltcdump (non-blocking)
|
||||||
|
rlist, _, _ = select.select([ltcdump_proc.stdout], [], [], 0)
|
||||||
|
if rlist:
|
||||||
|
line = ltcdump_proc.stdout.readline().strip()
|
||||||
|
if line and line[0].isdigit():
|
||||||
|
latest_tc = line
|
||||||
|
last_update = time.time()
|
||||||
|
|
||||||
|
# Detect stale or missing LTC
|
||||||
|
if time.time() - last_update > 1:
|
||||||
|
latest_tc = "⚠️ No LTC signal"
|
||||||
|
|
||||||
|
# UI
|
||||||
|
stdscr.erase()
|
||||||
stdscr.addstr(1, 2, "🌀 NTP Timeturner Status")
|
stdscr.addstr(1, 2, "🌀 NTP Timeturner Status")
|
||||||
stdscr.addstr(3, 4, "Streaming LTC from default input...")
|
stdscr.addstr(3, 4, "Streaming LTC from default input...")
|
||||||
stdscr.addstr(5, 6, f"🕰️ LTC Timecode: {latest_tc}")
|
stdscr.addstr(5, 6, f"🕰️ LTC Timecode: {latest_tc}")
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
|
|
||||||
# Check if new LTC line available
|
time.sleep(0.04) # ~25 FPS
|
||||||
if ltcdump_proc.stdout.readable():
|
|
||||||
line = ltcdump_proc.stdout.readline().strip()
|
|
||||||
if line and line[0].isdigit():
|
|
||||||
latest_tc = line
|
|
||||||
|
|
||||||
# Limit screen redraw to ~10fps
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
stdscr.addstr(8, 6, "🔚 Shutting down...")
|
stdscr.addstr(8, 6, "🔚 Shutting down...")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue