-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash-watchface.ps1
More file actions
136 lines (103 loc) · 3.08 KB
/
flash-watchface.ps1
File metadata and controls
136 lines (103 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<#
.SYNOPSIS
Compiles and uploads the Nova watchface firmware to the connected Waveshare board.
.EXAMPLE
.\flash-watchface.ps1
.EXAMPLE
.\flash-watchface.ps1 -ArcCount 12
.EXAMPLE
.\flash-watchface.ps1 -CompileOnly -ArcCount 20
#>
[CmdletBinding()]
param(
[ValidateRange(1, 60)]
[int]$ArcCount = 16,
[string]$Port,
[switch]$CompileOnly,
[switch]$Clean,
[switch]$VerifyUpload,
[string]$CliPath = (Join-Path $HOME "bin\arduino-cli.exe"),
[string]$Fqbn = "esp32:esp32:waveshare_esp32_s3_touch_lcd_169"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$SketchPath = (Resolve-Path $PSScriptRoot).Path
if (-not (Test-Path -LiteralPath $CliPath -PathType Leaf)) {
throw "Arduino CLI not found at '$CliPath'."
}
function Invoke-ArduinoCli {
param(
[Parameter(Mandatory = $true)]
[string[]]$Arguments
)
Write-Host ""
Write-Host "> $CliPath $($Arguments -join ' ')"
& $CliPath @Arguments
if ($LASTEXITCODE -ne 0) {
throw "arduino-cli failed with exit code $LASTEXITCODE."
}
}
function Find-WatchfacePort {
$ports = @(
Get-CimInstance Win32_SerialPort -ErrorAction SilentlyContinue |
Where-Object { $_.PNPDeviceID -match "VID_303A" } |
Sort-Object DeviceID
)
if ($ports.Count -eq 0) {
throw "No Waveshare/ESP32-S3 VID_303A serial port found. If the board is not enumerating, use the restore workflow."
}
$preferred = @($ports | Where-Object { $_.PNPDeviceID -match "PID_1001" })
if ($preferred.Count -gt 0) {
$ports = $preferred
}
if ($ports.Count -gt 1) {
Write-Host "Multiple VID_303A ports found; using $($ports[0].DeviceID). Pass -Port to choose explicitly."
}
return $ports[0].DeviceID
}
function Write-AvatarConfig {
$configPath = Join-Path $SketchPath "avatar_config.local.h"
$config = @(
"// Generated by flash-watchface.ps1. Not committed.",
"#pragma once",
"#define NOVA_AVATAR_ARC_COUNT $ArcCount"
)
Set-Content -LiteralPath $configPath -Value $config -Encoding ASCII
}
Write-AvatarConfig
$compileArgs = @(
"compile",
"--fqbn", $Fqbn,
"--board-options", "PSRAM=enabled"
)
if ($Clean) {
$compileArgs += "--clean"
}
if ($CompileOnly) {
$compileArgs += $SketchPath
Write-Host "Compiling Nova watchface firmware with $ArcCount avatar arcs..."
Invoke-ArduinoCli -Arguments $compileArgs
Write-Host ""
Write-Host "Compile complete. Skipping upload because -CompileOnly was set."
exit 0
}
if (-not $Port) {
$Port = Find-WatchfacePort
}
$compileArgs += @("--upload", "--port", $Port)
if ($VerifyUpload) {
$compileArgs += "--verify"
}
$compileArgs += $SketchPath
Write-Host "Compiling and uploading Nova watchface firmware with $ArcCount avatar arcs to $Port..."
Invoke-ArduinoCli -Arguments $compileArgs
Start-Sleep -Seconds 3
$reenumerated = @(
Get-CimInstance Win32_SerialPort -ErrorAction SilentlyContinue |
Where-Object { $_.PNPDeviceID -match "VID_303A" }
)
if ($reenumerated.Count -eq 0) {
throw "Upload finished, but no VID_303A serial port re-enumerated."
}
Write-Host ""
Write-Host "Upload complete. Board re-enumerated as: $($reenumerated.DeviceID -join ', ')"