aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xwatch-co2.sh36
1 files changed, 23 insertions, 13 deletions
diff --git a/watch-co2.sh b/watch-co2.sh
index 4a20708..1525635 100755
--- a/watch-co2.sh
+++ b/watch-co2.sh
@@ -5,9 +5,10 @@ topic="$1"
host="${2-mqtt}"
# config
-low="600" # green
-medium="1000" # yellow
-high="2000" # red
+l1="500" # green
+l2="1000" # yellow
+l3="1500" # red
+l4="2000" # purple
sleep="60"
######################################################################################
@@ -27,21 +28,20 @@ function tty_reset() {
function colorize_ppm() {
local ppm="$1"
- if test $ppm -lt $low; then
+ if test $ppm -lt $l1; then
tty_rgb 0 255 0
-# echo "$ppm: low"
- elif test $ppm -lt $medium; then
- red=$(( ($ppm - $low) * 255 / ($medium - $low) ))
+ elif test $ppm -lt $l2; then
+ red=$(( ($ppm - $l1) * 255 / ($l2 - $l1) ))
tty_rgb $red 255 0
-# echo "$ppm: low-medium: red $red"
- elif test $ppm -lt $high; then
- green=$(( ($ppm - $medium) * 255 / ($high - $medium) ))
+ elif test $ppm -lt $l3; then
+ green=$(( ($ppm - $l2) * 255 / ($l3 - $l2) ))
green=$(( 255 - $green ))
tty_rgb 255 $green 0
-# echo "$ppm: medium-high: green $green"
+ elif test $ppm -lt $l4; then
+ blue=$(( ($ppm - $l3) * 255 / ($l4 - $l3) ))
+ tty_rgb 255 0 $blue
else
- tty_rgb 255 0 0
-# echo "$ppm: high"
+ tty_rgb 255 0 255
fi
}
@@ -55,6 +55,16 @@ function show_ppm() {
######################################################################################
+if test "$topic" = "test"; then
+ for ppm in $(seq $l1 50 $l4); do
+ colorize_ppm $ppm
+ echo -n " -*- test -*- $ppm -*-"
+ tty_reset
+ echo ""
+ done
+ exit 0
+fi
+
if test -f /var/lib/scd/values.json; then
# direct mode
while true; do