Created
July 14, 2013 03:14
-
-
Save jrotello/5993057 to your computer and use it in GitHub Desktop.
A PowerShell script that lights a blink(1) LED based upon the CPU utilization of the computer. The CPU load is polled and updated every 3 seconds. Requires a ThingM blink(1). Assumes that the blink1-tool.exe is the the system path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$global:cpuMonitor = $null | |
function Enable-CpuMonitor() { | |
if ($global:cpuMonitor -eq $null) { | |
$global:cpuMonitor = New-Object Timers.Timer | |
$global:cpuMonitor.Interval = 3000 | |
$global:cpuMonitor.Enabled = $true | |
Register-ObjectEvent -InputObject $global:cpuMonitor -SourceIdentifier CpuMonitor -EventName Elapsed -Action { | |
$processor = Get-WmiObject win32_processor | |
if ($processor.LoadPercentage -le 50) { | |
blink1-tool.exe --green -q | |
} elseif ($processor.LoadPercentage -gt 50 -and $processor.LoadPercentage -le 90) { | |
blink1-tool.exe --rgb "255,204,0" -q #yellow | |
} else { | |
blink1-tool.exe --red -q | |
} | |
} | Out-Null | |
$global:cpuMonitor.Start() | |
} else { | |
Write-Host "CpuMonitor has already been enabled." | |
} | |
} | |
function Disable-CpuMonitor() { | |
if ($global:cpuMonitor -ne $null) { | |
blink1-tool.exe --off -q | |
Unregister-Event -SourceIdentifier CpuMonitor | |
$global:cpuMonitor.Stop() | |
$global:cpuMonitor.Dispose() | |
$global:cpuMonitor = $null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment