mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
final push for phase 1
This commit is contained in:
parent
c9d0bf0937
commit
007f8ffd7d
1 changed files with 32 additions and 25 deletions
|
|
@ -50,15 +50,15 @@ def run_curses(stdscr):
|
||||||
|
|
||||||
serial_port = find_serial_port()
|
serial_port = find_serial_port()
|
||||||
if not serial_port:
|
if not serial_port:
|
||||||
stdscr.addstr(0, 0, "❌ Could not find Teensy serial port (ACM/USB).")
|
stdscr.addstr(0, 0, "Could not find Teensy serial port (ACM/USB).")
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ser = serial.Serial(serial_port, BAUD_RATE, timeout=1)
|
ser = serial.Serial(serial_port, BAUD_RATE, timeout=0.1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
stdscr.addstr(0, 0, f"❌ Failed to open {serial_port}: {e}")
|
stdscr.addstr(0, 0, f"Failed to open {serial_port}: {e}")
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
return
|
return
|
||||||
|
|
@ -72,31 +72,38 @@ def run_curses(stdscr):
|
||||||
sync_requested = False
|
sync_requested = False
|
||||||
syncing = False
|
syncing = False
|
||||||
|
|
||||||
|
read_buffer = ""
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
now = get_system_time()
|
now = get_system_time()
|
||||||
line = ser.readline().decode(errors='ignore').strip()
|
try:
|
||||||
if line:
|
data = ser.read(128).decode(errors='ignore')
|
||||||
parsed = parse_ltc_line(line)
|
read_buffer += data
|
||||||
if parsed:
|
while '\n' in read_buffer:
|
||||||
status, tc_str, fps = parsed
|
line, read_buffer = read_buffer.split('\n', 1)
|
||||||
frame_rate = fps
|
parsed = parse_ltc_line(line)
|
||||||
last_ltc_dt = timecode_to_dt(tc_str)
|
if parsed:
|
||||||
last_status = status
|
status, tc_str, fps = parsed
|
||||||
if status == "LOCK":
|
frame_rate = fps
|
||||||
lock_count += 1
|
last_ltc_dt = timecode_to_dt(tc_str)
|
||||||
else:
|
last_status = status
|
||||||
free_count += 1
|
if status == "LOCK":
|
||||||
|
lock_count += 1
|
||||||
|
else:
|
||||||
|
free_count += 1
|
||||||
|
|
||||||
if sync_requested and not syncing:
|
if sync_requested and not syncing:
|
||||||
syncing = True
|
syncing = True
|
||||||
new_time = last_ltc_dt.strftime("%H:%M:%S")
|
new_time = last_ltc_dt.strftime("%H:%M:%S")
|
||||||
try:
|
try:
|
||||||
subprocess.run(["sudo", "date", "-s", new_time], check=True)
|
subprocess.run(["sudo", "date", "-s", new_time], check=True)
|
||||||
sync_feedback = f"[OK] Clock set to {new_time}"
|
sync_feedback = f"[OK] Clock set to {new_time}"
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
sync_feedback = f"[ERR] Failed to sync: {e}"
|
sync_feedback = f"[ERR] Failed to sync: {e}"
|
||||||
sync_requested = False
|
sync_requested = False
|
||||||
syncing = False
|
syncing = False
|
||||||
|
except Exception as e:
|
||||||
|
pass # ignore serial read errors
|
||||||
|
|
||||||
if last_ltc_dt:
|
if last_ltc_dt:
|
||||||
sys_time = now.replace(microsecond=0)
|
sys_time = now.replace(microsecond=0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue