# T1 RID Sensor — One-shot flash script (PowerShell)
# Usage:
#   .\flash.ps1                            # standard build, auto-detect port
#   .\flash.ps1 -Uav                       # UAV cross-band bridge variant
#   .\flash.ps1 -Port COM7                 # specify port
#   .\flash.ps1 -FsOnly                    # refresh LittleFS only
[CmdletBinding()]
param(
    [switch]$Uav,
    [switch]$FsOnly,
    [string]$Port = ""
)

$ErrorActionPreference = "Stop"
Set-Location -Path $PSScriptRoot

$Env_ = if ($Uav) { "heltec_wifi_lora_v4_uav_bridge" } else { "heltec_wifi_lora_v4" }
$portArg = if ($Port) { @("--upload-port", $Port) } else { @() }

Write-Host "============================================================"
Write-Host "  T1 RID Sensor flash"
Write-Host "  Env:    $Env_"
Write-Host "  Port:   $(if ($Port) { $Port } else { 'auto-detect' })"
Write-Host "  Mode:   $(if ($FsOnly) { 'fs-only' } else { 'firmware + fs' })"
Write-Host "============================================================"

if (-not $FsOnly) {
    Write-Host "[1/2] Flashing firmware..."
    & pio run -e $Env_ -t upload @portArg
}

Write-Host "[*] Flashing LittleFS model image..."
& pio run -e $Env_ -t uploadfs @portArg

Write-Host ""
Write-Host "Done. Monitor with: pio device monitor -e $Env_ $($portArg -join ' ')"
