Files
uno-q-audio-synth/system/configure-usb-host.sh
T
david 8cd796e3dd Initial commit: Arduino Uno Q USB Audio Synth project
- USB gadget (UAC1 + MIDI) with boot persistence
- USB host mode with auto-detection
- Pure Data synth patch with ALSA + UDP netreceive MIDI input
- MIDI rawmidi-to-UDP bridge (midi-bridge.py)
- LED matrix visualization (led-matrix-viz.py via arduino-router RPC)
- MCU sketch for LED matrix control (Arduino_RouterBridge + ArduinoGraphics)
- Conftest/OPA Rego policy validation suite for .pd files
- gen_synth_pd.py: programmatic .pd file generator
- System services: midi-bridge, led-matrix-viz, pd-synth-auto, usb-role-detect
- Justfile with deploy, enable, diagnostic recipes
- Diagnostic script (diag.sh)
2026-06-22 22:46:36 -07:00

42 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# configure-usb-host.sh — Wait for USB audio interface in host mode.
# Finds the first USB audio capture/playback device and writes device
# info to /run/usb-audio-dev for Pd to use.
#
# When the Uno Q acts as USB host (MIDI controller + USB audio interface
# connected via hub), the USB audio interface appears as a ALSA card
# driven by snd-usb-audio.
set -euo pipefail
DEV_FILE="/run/usb-audio-dev"
POLL_SECONDS=10
die() { echo "[USB-HOST] $*" >&2; exit 1; }
info() { echo "[USB-HOST] $*"; }
info "Waiting for USB audio interface..."
for ((i = 0; i < POLL_SECONDS; i++)); do
# Look for USB audio cards (not UAC1Gadget, not internal)
cards=$(aplay -l 2>/dev/null | grep -i "usb" | grep -vi "gadget" || true)
if [ -n "$cards" ]; then
# Pick the first USB audio card
card=$(echo "$cards" | head -1 | awk '{print $2}' | tr -d ':')
info "Found USB audio card: $card"
echo "hw:$card,0" > "$DEV_FILE"
cat "$DEV_FILE"
exit 0
fi
# Also check if any MIDI devices appeared
if command -v aseqdump &>/dev/null; then
midi_ports=$(aconnect -i -o -l 2>/dev/null | grep -i "usb" | head -1 || true)
if [ -n "$midi_ports" ]; then
info "Found USB MIDI device: $midi_ports"
fi
fi
sleep 1
done
die "No USB audio interface found after ${POLL_SECONDS}s (connect one and restart)"