feat: add mock Teensy support with entrypoint and LTC generator

Co-authored-by: aider (openai/gpt-5) <aider@aider.chat>
This commit is contained in:
Chaos Rogers 2025-10-21 23:40:14 +01:00
parent ddbdf8cb72
commit f855cac040
4 changed files with 76 additions and 0 deletions

View file

@ -31,14 +31,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libudev1 \
ca-certificates \
tzdata \
socat \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /app/target/release/get-haci /usr/local/bin/get-haci
COPY static ./static
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY scripts/ltc_gen.sh /usr/local/bin/ltc-gen.sh
RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/ltc-gen.sh
ENV RUST_LOG=info
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["get-haci"]

View file

@ -6,6 +6,7 @@ services:
container_name: haci
environment:
- RUST_LOG=info
- MOCK_TEENSY=1
ports:
- "8080:8080"
volumes:

27
scripts/entrypoint.sh Normal file
View file

@ -0,0 +1,27 @@
#!/bin/sh
set -eu
# If enabled, start a mock Teensy that exposes a PTY at /dev/ttyACM0 and streams LTC-like lines.
if [ "${MOCK_TEENSY:-0}" = "1" ]; then
echo "[entrypoint] Starting mock Teensy (PTY at /dev/ttyACM0)..." >&2
# Bridge the LTC generator to a PTY that looks like a Teensy serial port.
# Left side runs the generator, right side is a PTY linked to /dev/ttyACM0
socat -d -d -lf /dev/stderr EXEC:'/usr/local/bin/ltc-gen.sh',pty,ctty,echo=0,raw PTY,link=/dev/ttyACM0,raw,echo=0 &
SOCAT_PID=$!
# Wait briefly for the PTY to appear
i=0
while [ $i -lt 50 ]; do
if [ -e /dev/ttyACM0 ]; then
break
fi
i=$((i+1))
sleep 0.1
done
if [ ! -e /dev/ttyACM0 ]; then
echo "[entrypoint] WARNING: Failed to create /dev/ttyACM0 (mock Teensy)" >&2
fi
fi
# Run the requested command (default: get-haci)
exec "$@"

43
scripts/ltc_gen.sh Normal file
View file

@ -0,0 +1,43 @@
#!/bin/sh
set -eu
# Simple LTC-like line generator to feed into a PTY for development.
# It outputs lines like: "LOCK HH:MM:SS;FF 25.00"
# Configure frames-per-second via LTC_FPS environment variable (23,24,25,29,30 supported).
FPS="${LTC_FPS:-25}"
case "$FPS" in
23) PERIOD="0.0417083"; RATE_STR="23.98" ;;
24) PERIOD="0.0416667"; RATE_STR="24.00" ;;
25) PERIOD="0.0400000"; RATE_STR="25.00" ;;
29) PERIOD="0.0333667"; RATE_STR="29.97" ;;
30) PERIOD="0.0333333"; RATE_STR="30.00" ;;
*) PERIOD="0.0400000"; RATE_STR="25.00"; FPS="25" ;;
esac
h=12
m=0
s=0
f=0
while true; do
printf "LOCK %02d:%02d:%02d;%02d %s\r\n" "$h" "$m" "$s" "$f" "$RATE_STR"
# increment frame
f=$((f+1))
if [ "$f" -ge "$FPS" ]; then
f=0
s=$((s+1))
if [ "$s" -ge 60 ]; then
s=0
m=$((m+1))
if [ "$m" -ge 60 ]; then
m=0
h=$(( (h + 1) % 24 ))
fi
fi
fi
# sleep to approximate frame cadence
sleep "$PERIOD"
done