From f855cac04046fe1ad8222aeddbd25cdb7c0c2ed0 Mon Sep 17 00:00:00 2001 From: Chaos Rogers Date: Tue, 21 Oct 2025 23:40:14 +0100 Subject: [PATCH] feat: add mock Teensy support with entrypoint and LTC generator Co-authored-by: aider (openai/gpt-5) --- Dockerfile | 5 +++++ docker-compose.yml | 1 + scripts/entrypoint.sh | 27 +++++++++++++++++++++++++++ scripts/ltc_gen.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 scripts/entrypoint.sh create mode 100644 scripts/ltc_gen.sh diff --git a/Dockerfile b/Dockerfile index b702e62..45abb50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/docker-compose.yml b/docker-compose.yml index 554d6d6..430ea1a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: container_name: haci environment: - RUST_LOG=info + - MOCK_TEENSY=1 ports: - "8080:8080" volumes: diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh new file mode 100644 index 0000000..dcde2a1 --- /dev/null +++ b/scripts/entrypoint.sh @@ -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 "$@" diff --git a/scripts/ltc_gen.sh b/scripts/ltc_gen.sh new file mode 100644 index 0000000..9d1c0b8 --- /dev/null +++ b/scripts/ltc_gen.sh @@ -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