mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-15 07:12:44 +02:00
Updated write-value.ps1
This commit is contained in:
@ -17,26 +17,27 @@
|
||||
param([float]$value = 0.5, [string]$unit = "Mach", [float]$redMin, [float]$yellowMin, [float]$yellowMax, [float]$redMax)
|
||||
|
||||
function WriteValueInRange([float]$value, [string]$unit, [float]$redMin, [float]$yellowMin, [float]$yellowMax, [float]$redMax) {
|
||||
$line = "------------------------------------------------"
|
||||
$text = "[$redMin$($value)$unit $redMax]"
|
||||
[float]$total = 20.0 - $text.Length
|
||||
$line = "--------------------------------------"
|
||||
$text = "[$redMin$value$unit$redMax]"
|
||||
[float]$both = 20.0 - $text.Length
|
||||
if ($value -gt $redMax) {
|
||||
Write-Host "[$redMin$($line.Substring(0, $total))$redMax]" -noNewline
|
||||
Write-Host "$($value)$unit " -noNewline -foregroundColor red
|
||||
Write-Host "[$redMin$($line.Substring(0,$both))$redMax]" -noNewline
|
||||
Write-Host "$value$unit" -noNewline -foregroundColor red
|
||||
} elseif ($value -lt $redMin) {
|
||||
Write-Host "$($value)$unit" -noNewline -foregroundColor red
|
||||
Write-Host "[$redMin$($line.Substring(0, $total))$redMax] " -noNewline
|
||||
Write-Host "$value$unit" -noNewline -foregroundColor red
|
||||
Write-Host "[$redMin$($line.Substring(0,$both))$redMax] " -noNewline
|
||||
} else {
|
||||
[float]$leftSide = (($value - $redMin) * $total) / ($redMax - $redMin)
|
||||
if ($leftSide -lt 1.0) { $leftSide = 1.0 }
|
||||
if ($leftSide -gt ($total - 1.0)) { $leftSide = $total - 1.0 }
|
||||
Write-Host "[$redMin$($line.Substring(0, $leftSide))" -noNewline
|
||||
[float]$left = (($value - $redMin) * $both) / ($redMax - $redMin)
|
||||
if ($left -lt 1.0) { $left = 1.0 }
|
||||
elseif ($left -gt ($both - 1.0)) { $left = $both - 1.0 }
|
||||
[float]$right = $both - $left
|
||||
Write-Host "[$redMin$($line.Substring(0,$left))" -noNewline
|
||||
if (($value -le $yellowMin) -or ($value -ge $yellowMax)) {
|
||||
Write-Host "$($value)$unit" -noNewline -foregroundColor yellow
|
||||
Write-Host "$value$unit" -noNewline -foregroundColor yellow
|
||||
} else {
|
||||
Write-Host "$($value)$unit" -noNewline -foregroundColor green
|
||||
Write-Host "$value$unit" -noNewline -foregroundColor green
|
||||
}
|
||||
Write-Host "$($line.Substring(0, $total - $leftSide + 0.49))$redMax] " -noNewline
|
||||
Write-Host "$($line.Substring(0,$right))$redMax]" -noNewline
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,11 +51,11 @@ WriteValueInRange 800 "m" 0 0 6000 8000
|
||||
Write-Host ""
|
||||
|
||||
Write-Host " SPEED " -noNewline
|
||||
WriteValueInRange 190 "km/h" 0 0 180 200
|
||||
WriteValueInRange 230 "km/h" 0 0 180 200
|
||||
Write-Host ""
|
||||
|
||||
Write-Host " BANK " -noNewline
|
||||
WriteValueInRange 3.3 "°" -30 -10 10 30
|
||||
WriteValueInRange -30.3 "°" -30 -10 10 30
|
||||
Write-Host ""
|
||||
|
||||
Write-Host " ENG " -noNewline
|
||||
@ -73,4 +74,8 @@ Write-Host " FREQ " -noNewline
|
||||
WriteValueInRange 104.4 "MHz" 80 80 108 108
|
||||
Write-Host ""
|
||||
|
||||
Write-Host " BRAKE " -noNewline
|
||||
WriteValueInRange 0.0 "%" 0 -1 90 100
|
||||
Write-Host ""
|
||||
|
||||
exit 0 # success
|
||||
|
Reference in New Issue
Block a user