45 lines
1.3 KiB
PowerShell
45 lines
1.3 KiB
PowerShell
param(
|
|
[string]$ComPort,
|
|
|
|
[switch]$BuildOnly
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$repoRoot = Split-Path -Parent $scriptDir
|
|
$envName = "rfp_esp32s3_wroom1_n16r8_3x106"
|
|
$venvPython = Join-Path $repoRoot ".venv\Scripts\python.exe"
|
|
|
|
if (-not $BuildOnly -and [string]::IsNullOrWhiteSpace($ComPort)) {
|
|
throw "ComPort is required unless -BuildOnly is used."
|
|
}
|
|
|
|
if (Test-Path $venvPython) {
|
|
$pythonCommand = $venvPython
|
|
$pythonArgs = @()
|
|
} elseif (Get-Command py -ErrorAction SilentlyContinue) {
|
|
$pythonCommand = "py"
|
|
$pythonArgs = @("-3")
|
|
} elseif (Get-Command python -ErrorAction SilentlyContinue) {
|
|
$pythonCommand = "python"
|
|
$pythonArgs = @()
|
|
} else {
|
|
throw "No Python runtime found. Install Python or create .venv first."
|
|
}
|
|
|
|
$pioHome = Join-Path $repoRoot ".piohome"
|
|
$env:PLATFORMIO_CORE_DIR = $pioHome
|
|
$env:PLATFORMIO_PACKAGES_DIR = Join-Path $pioHome "packages"
|
|
$env:PLATFORMIO_PLATFORMS_DIR = Join-Path $pioHome "platforms"
|
|
$env:PLATFORMIO_CACHE_DIR = Join-Path $pioHome ".cache"
|
|
$env:PLATFORMIO_BUILD_CACHE_DIR = Join-Path $pioHome "buildcache"
|
|
|
|
$args = @("-m", "platformio", "run", "-e", $envName)
|
|
if (-not $BuildOnly) {
|
|
$args += @("-t", "upload", "--upload-port", $ComPort)
|
|
}
|
|
|
|
& $pythonCommand @pythonArgs @args
|
|
exit $LASTEXITCODE
|