From 1f7761d53c316364ed555bf6db2b5a347be4cd99 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 13 Mar 2017 23:18:15 +0000 Subject: [PATCH] implemented random color fading for main light in e-lab --- light.sh | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/light.sh b/light.sh index dcf7d87..ed2abd9 100755 --- a/light.sh +++ b/light.sh @@ -21,7 +21,7 @@ STATE_2="n\x00\x02\x01\x00|!;\ n\x00\x02\x01\x00|FFCC11;\ 000000000000000000" STATE_3="!/usr/bin/python3 /home/automation/fensterbogenbeleuchtung_animations/animations.py|!;\ -a\x00\x03\xff\xff\xff|FFCC11;\ +a\x00\x03\xff\xff\xff|!;\ 000000000000000000" get_room_color_string() { @@ -81,16 +81,41 @@ case "$ROOM_NUMBER" in fi ;; 2) + find "$(dirname "$TMPFILE_PID_BASE")" -name "$(basename "${TMPFILE_PID_BASE}_2_*")" -exec sh -c 'cat {} | xargs kill; rm -f {}' \; # COLOR_A="$(echo "$STATE" | cut -d";" -f2 | cut -d"|" -f1)" COLOR_B="$(echo "$STATE" | cut -d";" -f2 | cut -d"|" -f2)" - # echo -en "$COLOR_A" > /dev/udp/172.23.92.18/49152 & - COLOR_B_TMP=$COLOR_B - for i in 5 4 3; do - wget -q -O- http://172.23.92.5/ecmd?channel%20$i%20$(printf "%d" "0x${COLOR_B_TMP:0:2}") > /dev/null 2>&1 & - COLOR_B_TMP="$(echo "$COLOR_B_TMP" | cut -c3-)" - done + # if [ "${COLOR_B:0:1}" == "!" ]; then + # + # else + # echo -en "$COLOR_A" > /dev/udp/172.23.92.18/49152 & + # fi + if [ "${COLOR_B:0:1}" == "!" ]; then + ( + R=$(( RANDOM % 256 )); G=$(( RANDOM % 256 )); B=$(( RANDOM % 256 )) + while true; do + R_=$(( RANDOM % 256 )); G_=$(( RANDOM % 256 )); B_=$(( RANDOM % 256 )) + while [ $R -ne $R_ -o $G -ne $G_ -o $B -ne $B_ ]; do + DR=$(sign $(($R_-$R))); DG=$(sign $(($G_-$G))); DB=$(sign $(($B_-$B))) + R=$(($R+$DR)); G=$((G+$DG)); B=$(($B+$DB)) + for i in 5:$R 4:$G 3:$B; do + wget -q -O- http://172.23.92.5/ecmd?channel%20$(echo $i | cut -d: -f1)%20$(echo $i | cut -d: -f2) > /dev/null 2>&1 & + COLOR_B_TMP="$(echo "$COLOR_B_TMP" | cut -c3-)" + done + sleep .1 + done + done + ) & + echo $! > ${TMPFILE_PID_BASE}_2_B + else + COLOR_B_TMP=$COLOR_B + for i in 5 4 3; do + wget -q -O- http://172.23.92.5/ecmd?channel%20$i%20$(printf "%d" "0x${COLOR_B_TMP:0:2}") > /dev/null 2>&1 & + COLOR_B_TMP="$(echo "$COLOR_B_TMP" | cut -c3-)" + done + fi ;; 3) + # find "$(dirname "$TMPFILE_PID_BASE")" -name "$(basename "${TMPFILE_PID_BASE}_3_*")" -exec sh -c 'cat {} | xargs kill; rm -f {}' \; # COLOR_A="$(echo "$STATE" | cut -d";" -f3 | cut -d"|" -f1)" # COLOR_B="$(echo "$STATE" | cut -d";" -f3 | cut -d"|" -f2)" # echo -en "$COLOR_A" > /dev/null