Files
roro9stack/scripts/serial_log.py
T
twislaandClaude Opus 5.5 05c9d9cc56 Add serial dev commands and a serial log helper
The firmware accepts burst, key <name>, sound on|off and short|normal
over serial, so UI behaviour can be reproduced on the device without
the keyboard. scripts/serial_log.sh records (and drives) it in a named
container that flash.sh removes before uploading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-02 13:38:25 +02:00

31 lines
1.1 KiB
Python

# Reads the Cardputer's serial port, reconnecting when it re-enumerates. Run via serial_log.sh.
import glob, os, sys, time
import serial
end = time.time() + float(sys.argv[1])
commands = sys.argv[2:] # sent once after connecting, e.g. "burst"
while time.time() < end:
ports = glob.glob('/dev/serial/by-id/*Espressif*')
if not ports:
time.sleep(1)
continue
try:
s = serial.Serial(os.path.realpath(ports[0]), 115200, timeout=0.2)
print('[connected]', flush=True)
for c in commands: # "sleep:N" waits N seconds between commands
if c.startswith('sleep:'):
time.sleep(float(c[6:]))
continue
time.sleep(1)
s.write((c + '\n').encode())
commands = []
buf = b''
while time.time() < end:
buf += s.read(512)
while b'\n' in buf:
line, buf = buf.split(b'\n', 1)
print(line.decode(errors='replace').rstrip(), flush=True)
except Exception as e:
print('[disconnected]', e, flush=True)
time.sleep(1)