#!/bin/bash # Build / upload / monitor the HomeKit garage door firmware. # # ./flash.sh build compile only # ./flash.sh upload [port] compile + upload # ./flash.sh monitor [port] serial console at 115200 # # The min_spiffs partition scheme is REQUIRED: HomeSpan + WiFi + OTA # overflows the stock 1.2MB app partition. min_spiffs gives 1.9MB with # OTA still available. set -euo pipefail export PATH="$HOME/.local/bin:$PATH" FQBN="esp32:esp32:XIAO_ESP32C3:PartitionScheme=min_spiffs" SKETCH="$(dirname "$(readlink -f "$0")")/garage_door" detect_port() { for p in /dev/ttyACM* /dev/ttyUSB*; do [ -e "$p" ] && { echo "$p"; return; } done echo "ERROR: no serial device found. Plug in the XIAO, or hold BOOT while" >&2 echo " connecting to force the bootloader." >&2 exit 1 } cmd="${1:-build}" port="${2:-}" case "$cmd" in build) arduino-cli compile --fqbn "$FQBN" "$SKETCH" ;; upload) [ -n "$port" ] || port="$(detect_port)" echo "Uploading to $port" arduino-cli compile --fqbn "$FQBN" "$SKETCH" arduino-cli upload -p "$port" --fqbn "$FQBN" "$SKETCH" echo "Done. Watch it boot with: $0 monitor" ;; monitor) [ -n "$port" ] || port="$(detect_port)" arduino-cli monitor -p "$port" -c baudrate=115200 ;; *) sed -n '2,12p' "$0" | sed 's/^# \?//' exit 1 ;; esac