30 lines
1.1 KiB
Bash
Executable File
30 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
MODE="${1:-potentiometer-breath-monitor}"
|
|
PORT="${PORT:-}"
|
|
|
|
case "$MODE" in
|
|
potentiometer-breath-monitor) SKETCH_DIR="$ROOT_DIR/potentiometer_breath_monitor" ;;
|
|
potentiometer-breath-monitor-buzzer) SKETCH_DIR="$ROOT_DIR/potentiometer_breath_monitor_buzzer" ;;
|
|
*) echo "Use: potentiometer-breath-monitor or potentiometer-breath-monitor-buzzer" >&2; exit 2 ;;
|
|
esac
|
|
|
|
if [[ -z "$PORT" ]]; then
|
|
PORT="$(arduino-cli board list | awk '/ttyACM|ttyUSB/ {print $1; exit}')"
|
|
fi
|
|
if [[ -z "$PORT" && "${NO_UPLOAD:-0}" != "1" ]]; then
|
|
echo "Set PORT=/dev/ttyACM0 or use NO_UPLOAD=1." >&2
|
|
exit 1
|
|
fi
|
|
|
|
FQBN="esp32:esp32:esp32s3:USBMode=hwcdc,CDCOnBoot=cdc,UploadSpeed=921600,CPUFreq=240,FlashMode=dio,FlashSize=16M,PartitionScheme=app3M_fat9M_16MB,PSRAM=opi"
|
|
BUILD_DIR="$ROOT_DIR/.arduino-build/$MODE"
|
|
|
|
arduino-cli compile --fqbn "$FQBN" --build-path "$BUILD_DIR" "$SKETCH_DIR"
|
|
if [[ "${NO_UPLOAD:-0}" == "1" ]]; then
|
|
exit 0
|
|
fi
|
|
arduino-cli upload --fqbn "$FQBN" -p "$PORT" --input-dir "$BUILD_DIR" "$SKETCH_DIR"
|