added environment variables and fixed some stuff

This commit is contained in:
Daniel Sommer 2021-04-09 02:04:53 +02:00
parent 5066dd647e
commit 901f1809a8

View file

@ -4,17 +4,18 @@
# license: MIT
# blinky
blinky_url="127.0.0.1:3000"
blinky_mode="morph"
blinky_duration="2500"
blinky_url="${BLINKY_URL:-localhost:3000}"
blinky_type="${BLINKY_MODE:-morph}"
blinky_duration="${BLINKY_DURATON:-2500}"
blinky_mode="${BLINKY_MODE:-$1}"
# temperature
max_temp="65000"
crit_temp="70000"
threshold_upper="66"
threshold_lower="33"
temperature_high="${BLINKY_TEMPERATURE_HIGH:-85000}"
temperature_critical="${BLINKY_TEMPERATURE_CRITICAL:-90000}"
threshold_upper="${BLINKY_THRESHOLD_UPPER:-66}"
threshold_lower="${BLINKY_THRESHOLD_LOWER:-33}"
thermal_zones=(
"3"
"*"
)
#############
@ -29,7 +30,7 @@ function checkRoot() {
function temperatureToRGB() {
[[ ! "$1" ]] && printf "error: did not receive a temperature value to convert to a rgb value\n" && exit 1
printf "converting temperature to rgb value... "
percentage="$(bc <<< "$1 / ( $max_temp / 100 )")"
percentage="$(bc <<< "$1 / ( $temperature_high / 100 )")"
[[ "$percentage" -gt "100" ]] && percentage="100"
color_main="$(bc <<< "$percentage * 2.55")"
color_supplement="$(bc <<< "255 - $color_main")"
@ -51,7 +52,7 @@ function sendPOST() {
for arg in "$@"; do
cmd="$cmd -d \"$arg\""
done
cmd="$cmd \"$blinky_url\""
cmd="$cmd \"$blinky_url\" -s"
printf "sending post request '$cmd'...\n"
eval "$cmd"
}
@ -69,8 +70,8 @@ function getTemperature() {
done
result="$(( $temp / $counter ))"
printf "result: '$result'\n"
[[ "$result" -ge "$crit_temp" ]] && printf "warning: critical temperature reached\n" && blinky_mode="pulse" && blinky_duration="500" && return 0
[[ "$result" -ge "$max_temp" ]] && printf "warning: maximum temperature reached\n" && blinky_mode="pulse" && blinky_duration="1500" && return 0
[[ "$result" -ge "$temperature_critical" ]] && printf "warning: critical temperature reached\n" && blinky_type="pulse" && blinky_duration="500" && return 0
[[ "$result" -ge "$temperature_high" ]] && printf "warning: maximum temperature reached\n" && blinky_type="pulse" && blinky_duration="1500" && return 0
}
@ -79,37 +80,35 @@ function getTemperature() {
#############
argument_count="$#"
index=1
[[ "$argument_count" -lt 1 ]] && printf "error: missing arguments\n" && exit 1
url="${@: $argument_count: 1}"
while [[ "$index" -lt $(( $argument_count -1 )) ]]; do
argument="${@: $index: 1}"
argument="${argument,,}"
(( index++ ))
printf "checking arg $argument\n"
case "$argument" in
-bm|--blinky-mode)
blinky_mode="${@: $index: 1}"
-u|--url|--blinky-url)
blinky_url="${@: $index: 1}"
;;
-t|--type|--blinky-type)
blinky_type="${@: $index: 1}"
;;
-bd|--blinky-duration)
-d|--duration|--blinky-duration)
blinky_duration="${@: $index: 1}"
;;
-m|--mode)
mode="${@: $index: 1}"
-m|--mode|--blinky-mode)
blinky_mode="${@: $index: 1}"
;;
esac
done
printf "checking mode '$mode'...\n"
case "$mode" in
-t|--temp|--temperature)
case "$blinky_mode" in
t|temp|temperature)
checkRoot
getTemperature
temperatureToRGB "$result"
sendPOST "color=$result" "mode=$blinky_mode" "duration=$blinky_duration"
sendPOST "color=$result" "mode=$blinky_type" "duration=$blinky_duration"
;;
*)
sendPOST "color=random" "mode=$blinky_mode" "duration=$blinky_duration"
sendPOST "color=random" "mode=$blinky_type" "duration=$blinky_duration"
;;
esac