#!/usr/bin/env bash
# AutoSense Flash Tool - ESP32
# Requires: Python + esptool (pip install esptool)
set -e

read -p "Enter the serial port your ESP32 is connected to (e.g. /dev/ttyUSB0 or /dev/cu.usbserial-XXXX): " PORT

python3 -m esptool --chip esp32 --port "$PORT" --baud 460800 write_flash -z \
  --flash_mode dout --flash_freq 40m --flash_size 4MB \
  0x1000   bin/esp32/bootloader.bin \
  0x8000   bin/esp32/partitions.bin \
  0xe000   bin/esp32/boot_app0.bin \
  0x10000  bin/esp32/firmware.bin \
  0x310000 bin/esp32/littlefs.bin

echo "Done. Disconnect and power-cycle the device."
