# ectool monitor: loop run "temps 0" and "pwmgetfanrpm all". Admin. Ctrl+C quit.

$EctoolPath = "C:\Program Files\crosec\ectool.exe"
$IntervalSeconds = 2

if (-not (Test-Path $EctoolPath)) {
    Write-Host "ectool not found: $EctoolPath" -ForegroundColor Red
    exit 1
}

Write-Host "ectool monitor (every ${IntervalSeconds}s, Ctrl+C quit)" -ForegroundColor Green
Write-Host ""

try {
    while ($true) {
        Write-Host ("--- " + (Get-Date -Format "yyyy-MM-dd HH:mm:ss") + " ---") -ForegroundColor Cyan

        Write-Host "> ectool temps 0" -ForegroundColor DarkGray
        & $EctoolPath temps 0

        Write-Host "> ectool pwmgetfanrpm all" -ForegroundColor DarkGray
        & $EctoolPath pwmgetfanrpm all

        Write-Host "> ectool pwmgetduty 0" -ForegroundColor DarkGray
        $dutyOut = & $EctoolPath pwmgetduty 0
        $dutyOut | Write-Host
        if ($dutyOut -match 'duty:\s*(\d+)') {
            $raw = [int]$Matches[1]
            $pct = [Math]::Round(100.0 * $raw / 65535, 1)
            Write-Host "  -> Duty cycle: $pct% (raw $raw / 65535)" -ForegroundColor Yellow
        }

        Write-Host ""
        Start-Sleep -Seconds $IntervalSeconds
    }
} finally {
    Write-Host "Done." -ForegroundColor Cyan
}
