Mimir/scripts/start-starfire-move-light.ps1
2026-06-14 19:40:03 +01:00

70 lines
2 KiB
PowerShell

param(
[string]$Rgb = "#35ff6c",
[int]$RefreshMs = 250,
[double]$HoldSeconds = 0,
[switch]$TurnOffOnExit,
[switch]$KeepExisting,
[switch]$DryRun
)
$ErrorActionPreference = "Stop"
$repo = Split-Path -Parent $PSScriptRoot
$runId = Get-Date -Format "yyyyMMdd-HHmmss"
$runDir = Join-Path $repo "artifacts\runtime\starfire-move-light-$runId"
$probe = Join-Path $repo "src\Mimir.PsMoveProbe\bin\Release\net10.0\Mimir.PsMoveProbe.exe"
$eventLog = Join-Path $runDir "move-light-events.jsonl"
New-Item -ItemType Directory -Force -Path $runDir | Out-Null
if (-not (Test-Path $probe)) {
dotnet build (Join-Path $repo "src\Mimir.PsMoveProbe\Mimir.PsMoveProbe.csproj") -c Release -p:UseSharedCompilation=false
}
if (-not $KeepExisting) {
Get-Process -Name "Mimir.PsMoveProbe" -ErrorAction SilentlyContinue |
ForEach-Object {
Stop-Process -Id $_.Id -Force
}
}
$args = @(
"--rgb", $Rgb,
"--breathe-led",
"--hold-seconds", "$HoldSeconds",
"--refresh-ms", "$RefreshMs",
"--event-log", $eventLog
)
if ($TurnOffOnExit) {
$args += "--turn-off-on-exit"
}
if ($DryRun) {
Write-Host "DRY starfire-move-light: $probe $($args -join ' ')"
return
}
$stdout = Join-Path $runDir "starfire-move-light.out.log"
$stderr = Join-Path $runDir "starfire-move-light.err.log"
$process = Start-Process `
-FilePath $probe `
-ArgumentList $args `
-WorkingDirectory $repo `
-WindowStyle Hidden `
-RedirectStandardOutput $stdout `
-RedirectStandardError $stderr `
-PassThru
Set-Content -Path (Join-Path $runDir "starfire-move-light.pid") -Value $process.Id
[ordered]@{
kind = "mimir.starfire_move_light_supervisor.v1"
runId = $runId
runDir = $runDir
rgb = $Rgb
refreshMs = $RefreshMs
holdSeconds = $HoldSeconds
pid = $process.Id
eventLog = $eventLog
startedAt = (Get-Date).ToString("o")
} | ConvertTo-Json -Depth 4 | Set-Content -Path (Join-Path $runDir "supervisor.json")
Write-Host "starfire-move-light pid=$($process.Id) runDir=$runDir eventLog=$eventLog"