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
This commit is contained in:
2026-10-02 13:38:25 +02:00
co-authored by Claude Opus 5.5
parent 9218a34c3e
commit 05c9d9cc56
5 changed files with 86 additions and 0 deletions
+1
View File
@@ -5,6 +5,7 @@ set -euo pipefail
PORT="${1:-$(readlink -f /dev/serial/by-id/*Espressif* 2>/dev/null | head -1)}"
[ -n "$PORT" ] || { echo "No Cardputer found on USB (is it plugged in / attached to the VM?)" >&2; exit 1; }
source "$(dirname "$0")/_docker.sh"
docker rm -f roro9stack-serial >/dev/null 2>&1 || true # a serial log would hold the port
DOCKER_EXTRA=(--device "$PORT" --group-add "$(stat -c %g "$PORT")" -it)
run_in_container bash -c "git config --global --add safe.directory /work && pio run -e cardputer-adv -t upload --upload-port $PORT && pio device monitor -p $PORT -b 115200"
+30
View File
@@ -0,0 +1,30 @@
# 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)
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Dev helper: record the Cardputer's serial output for N seconds (follows port changes).
# Usage: scripts/serial_log.sh [seconds] [command...] — stop early with: docker rm -f roro9stack-serial
set -euo pipefail
source "$(dirname "$0")/_docker.sh"
docker rm -f roro9stack-serial >/dev/null 2>&1 || true
DOCKER_EXTRA=(--name roro9stack-serial --group-add "$(getent group dialout | cut -d: -f3)" --privileged -v /dev:/dev)
run_in_container /pio/penv/bin/python scripts/serial_log.py "${1:-60}" "${@:2}"