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