; RemoteRig — Dual-Board Camera Node Firmware
; ============================================
; Each camera node has TWO boards connected via UART:
;
;   ESP8266 (Camera Bridge):   Connects to GoPro AP → HTTP status/control
;   ESP32   (MQTT Bridge):     Connects to travel router → MQTT to hub
;
;   ESP8266 ←──UART──→ ESP32
;   (TX/RX)           (RX16/TX17)
;
; Build:
;   pio run -e esp8266-camera        (ESP8266 — GoPro camera bridge)
;   pio run -e seeed_xiao_esp32c6    (XIAO ESP32-C6 — MQTT bridge)
;
; Upload:
;   pio run -e esp8266-camera --target upload
;   pio run -e seeed_xiao_esp32c6 --target upload
;
; Filesystem:
;   pio run -e esp8266-camera --target uploadfs
;   pio run -e seeed_xiao_esp32c6 --target uploadfs

[common]
lib_deps =
    knolleary/PubSubClient @ ^2.8
    bblanchon/ArduinoJson @ ^7.3
build_flags =
    -D CORE_DEBUG_LEVEL=0

; ── ESP-01S: Camera Bridge ──────────────────────────────────
; Flashed onto an ESP-01S (ESP8266, 1MB flash). Talks to the GoPro
; over Wi-Fi, relays to the XIAO over the hardware UART (GPIO1/3).
; No MQTT, no router connection.
;
; Flash with a 3.3V USB-UART adapter: tie GPIO0 → GND, power up /
; reset into bootloader, then upload. ESP-01S flash is qio/dout;
; keep upload_speed modest for adapter reliability.

[env:esp8266-camera]
platform = espressif8266
board = esp01_1m
framework = arduino
monitor_speed = 115200
upload_speed = 115200
lib_deps = ${common.lib_deps}
build_flags = ${common.build_flags}
    -D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
board_build.flash_mode = dout
board_build.f_cpu = 160000000L
build_src_filter =
    -<*.cpp>
    +<esp8266-camera-bridge.cpp>
    +<../lib/>

; ── XIAO ESP32-C6: MQTT Bridge ─────────────────────────────
; Flashed onto a Seeed Studio XIAO ESP32-C6. Connects to the
; travel router, publishes MQTT to the Pi hub. Reads camera
; status from the ESP-01S over UART (Serial1: RX=D7, TX=D6).
; No direct camera communication.
;
; ESP32-C6 requires the pioarduino fork of platform-espressif32
; (mainline espressif32 lagged on the Arduino-core 3.x the C6
; needs). USB-CDC-on-boot is required for Serial over native USB.
;
; Upload fallback if it can't connect: hold B (BOOT), tap
; R (RESET), release B, then re-run upload.

[env:seeed_xiao_esp32c6]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
board = seeed_xiao_esp32c6
framework = arduino
monitor_speed = 115200
lib_deps =
    ${common.lib_deps}
    olikraus/U8g2 @ ^2.35
build_flags = ${common.build_flags}
    -D CONFIG_ARDUINO_LOOP_STACK_SIZE=8192
    -D ARDUINO_USB_MODE=1
    -D ARDUINO_USB_CDC_ON_BOOT=1
build_src_filter =
    -<*.cpp>
    +<esp32-mqtt-bridge.cpp>
    +<../lib/>
