From 724da873d221b589632f33e392c1dbc98fb17c64 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Tue, 3 Dec 2024 07:16:25 +0100 Subject: [PATCH] Updated write-value.ps1 --- scripts/write-value.ps1 | 47 ++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/scripts/write-value.ps1 b/scripts/write-value.ps1 index 5bb1d460..a08e248c 100644 --- a/scripts/write-value.ps1 +++ b/scripts/write-value.ps1 @@ -14,7 +14,7 @@ Author: Markus Fleschutz | License: CC0 #> -param([float]$value = 0.5, [string]$unit = "Mach", [float]$min = 0.0, [float]$max = 10.0) +param([float]$value = 0.5, [string]$unit = "Mach", [float]$redMin = 0.0, [float]$redMax = 10.0) function WriteLine([float]$count) { while ($count -ge 1.0) { @@ -24,42 +24,55 @@ function WriteLine([float]$count) { return $count } -function WriteBlock([float]$value, [string]$unit, [float]$min, [float]$max) { - $text = "[$min $($value)$unit $max]" +function WriteBlock([float]$value, [string]$unit, [float]$redMin, [float]$yellowMin, [float]$yellowMax, [float]$redMax) { + $text = "[$redMin $($value)$unit $redMax]" [float]$left = 20.0 - $text.Length - if ($value -gt $max) { - Write-Host "[$min" -noNewline + if ($value -gt $redMax) { + Write-Host "[$redMin" -noNewline $rest = WriteLine $left - Write-Host "$max]" -noNewline + Write-Host "$redMax]" -noNewline Write-Host " $($value)$unit " -noNewline -foregroundColor red - } elseif ($value -lt $min) { + } elseif ($value -lt $redMin) { Write-Host "$($value)$unit" -noNewline -foregroundColor red - Write-Host " [$min" -noNewline + Write-Host " [$redMin" -noNewline $rest = WriteLine $left - Write-Host "$max] " -noNewline + Write-Host "$redMax] " -noNewline + } elseif (($value -le $yellowMin) -or ($value -ge $yellowMax)) { + [float]$percent = (($value - $redMin) * $left) / ($redMax - $redMin) + Write-Host "[$redMin" -noNewline + $rest = WriteLine $percent + Write-Host "$($value)$unit" -noNewline -foregroundColor yellow + $rest = WriteLine ($left - $percent + $rest + 1.0) + Write-Host "$redMax] " -noNewline } else { - [float]$percent = (($value - $min) * $left) / ($max - $min) - Write-Host "[$min" -noNewline + [float]$percent = (($value - $redMin) * $left) / ($redMax - $redMin) + Write-Host "[$redMin" -noNewline $rest = WriteLine $percent Write-Host "$($value)$unit" -noNewline -foregroundColor green $rest = WriteLine ($left - $percent + $rest + 1.0) - Write-Host "$max] " -noNewline + Write-Host "$redMax] " -noNewline } } -WriteBlock -3.5 "°C" 0 100 +WriteBlock -3.5 "°C" 0 10 90 100 Write-Host "CPU too cold" -WriteBlock 15 "°C" 0 100 +WriteBlock 5 "°C" 0 10 90 100 +Write-Host "CPU quite cold" + +WriteBlock 15 "°C" 0 10 90 100 Write-Host "OK" -WriteBlock 50 "°C" 0 100 +WriteBlock 50 "°C" 0 10 90 100 Write-Host "OK" -WriteBlock 70 "°C" 0 100 +WriteBlock 70 "°C" 0 10 90 100 Write-Host "OK" -WriteBlock 110 "°C" 0 100 +WriteBlock 95 "°C" 0 10 90 100 +Write-Host "CPU quite hot " + +WriteBlock 110 "°C" 0 10 90 100 Write-Host "CPU too hot " exit 0 # success