From 4707c102091a181ddd88ebdfa042249dedcdec7f Mon Sep 17 00:00:00 2001 From: Level2 Pidor Date: Mon, 27 Jun 2016 21:50:45 +0200 Subject: [PATCH] better beamer and reciver control with volume keys bug corrections --- scripts/.gitignore | 1 + scripts/beamercontrol.sh | 106 +++++++++---------------- scripts/beamerdetect.sh | 3 +- scripts/lightcommander | 8 +- scripts/opendoor.sh | 4 +- scripts/upd_status.sh | 6 +- scripts/upd_status.sh.d/tweet | 4 +- www/htdocs/lights.level2.lu/index.html | 7 +- 8 files changed, 59 insertions(+), 80 deletions(-) diff --git a/scripts/.gitignore b/scripts/.gitignore index 07e2aaf..7105fde 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -1,3 +1,4 @@ spaceapikey.txt beamerip.txt peoplecounterip.txt +secret.txt diff --git a/scripts/beamercontrol.sh b/scripts/beamercontrol.sh index de53775..96c7ccd 100755 --- a/scripts/beamercontrol.sh +++ b/scripts/beamercontrol.sh @@ -1,4 +1,5 @@ #!/bin/bash +# this is called by lightcommander logger $0 1=$1 2=$2 BEAMERIP=$(cat $(dirname "$0")"/beamerip.txt") function raisescreen() { @@ -9,13 +10,30 @@ function lowerscreen() { echo "Rolling projection screen down" ssh pi@doorbuzz 'doorbuzz/projectionscreen.sh down' } +function beamerquery() { + signalsource="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info' |awk -F'[<>]' '//{print substr($3,33,2)}')" + if [ "$signalsource" = "" ] + then + signalsource="off" # I know bash can do this in 1 line, but this should still be readable + fi + echo "$signalsource" +} function beameroff() { echo "Switching beamer off" wget -qO/dev/null http://$projip/tgi/return.tgi?command=2a3102fd0660 #projector off } function beameron() { - echo "Switching beamer on" + currstatus="$(beamerquery)" + echo "Switching beamer on (input was $currstatus)" wget -qO/dev/null http://$projip/tgi/return.tgi?command=2a3101fe0660 #projector on + if [ "$currstatus" = "off" ] + then + echo "Waiting for beamer to boot..." + sleep 15 + echo "... is now booted" + return 0 + fi + return 1 } function dvi() { echo "Switching to dvi" @@ -26,11 +44,8 @@ function hdmi1() { wget -qO/dev/null http://$projip/tgi/return.tgi?command=2a3109f6071475 #switch to hdmi1 } function hdmi2() { - receiveron echo "Switching to hdmi2" wget -qO/dev/null http://$projip/tgi/return.tgi?command=2a3109f6071576 #switch to hdmi2 - sleep 4 - receiverhdmi } function vga1() { echo "Switching to vga1" @@ -70,6 +85,14 @@ function receivertuner() { echo "Switching receiver to tuner" ssh pi@doorbuzz '/usr/bin/irsend SEND_ONCE pioneer "KEY_TUNER"' } +function receivervolumeup() { + echo "Turning reciever volume up" + ssh pi@doorbuzz '/usr/bin/irsend SEND_ONCE pioneer "KEY_VOLUMEUP"' +} +function receivervolumedown() { + echo "Turning reciever volume down" + ssh pi@doorbuzz '/usr/bin/irsend SEND_ONCE pioneer "KEY_VOLUMEDOWN"' +} function usage() { echo "Usage: $0 (beamer|screen) (on|dvi|hdmi1|hdmi2|vga|off|down|up)" exit @@ -82,13 +105,17 @@ case $1 in ;; off) beameroff ;; - dvi) beameron; dvi + dvi) dvi ; beameron && dvi ;; - hdmi1) beameron; hdmi1 + hdmi1) hdmi1 ; beameron && hdmi1 ;; - hdmi2) beameron; hdmi2 + hdmi2) hdmi2 + ( receiveron + sleep 4 + receiverhdmi ) & + beameron && hdmi2 ;; - vga1) beameron; vga1 + vga1) vga1 ; beameron && vga1 ;; *) usage esac @@ -118,6 +145,10 @@ case $1 in ;; tuner) receivertuner ;; + "vol+") receivervolumeup + ;; + "vol-") receivervolumedown + ;; *) usage esac ;; @@ -125,62 +156,3 @@ case $1 in usage ;; esac 2>&1 | logger -t $0 -exit -if [ "$1" = "off" ] -then - ( - echo "called with parameter $1" - projip="$BEAMERIP" - if [ "$projip" = "" ] - then - echo "no projector IP found" - arp -a - raisescreen - exit - fi - signalsource="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info' |awk -F'[<>]' '//{print substr($3,33,2)}')" - if [ "$signalsource" = "00" ] || [ "$signalsource" = "15" ] || [ "$signalsource" = "" ] - then - raisescreen - echo "wget http://$projip/tgi/return.tgi?command=2a3102fd0660 #projector off" - wget -qO - 'http://'"$projip"'/tgi/return.tgi?command=2a3102fd0660' 2>&1 - echo $? - else - echo "not disabling projector because source is at $signalsource" - fi - ) | logger -t "$(basename $0) $$" - exit -fi & -if [ "$1" = "off" ] -then - exit # because the if before is in background -fi -prevstatus="unknown" -while true -do - if [ $(date +%H) -eq 23 ] - then - pingall - fi - projip="$BEAMERIP" - # from the acer webpage we read that bytes 30-31 contain 00 if power off and 01 if power on - # we only test if 01, because if off, it can also give no response - # but seems to be bytes 32-33 more accurate - statusbyte="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info'|awk -F'[<>]' '//{print substr($3,31,2)}')" - if [ "$statusbyte" = "01" ] - then - if [ "$prevstatus" != "on" ] - then - logger -t $(basename $0) "$$ Projector is on" - ssh pi@doorbuzz 'doorbuzz/projectionscreen.sh down' - prevstatus="on" - fi - else - if [ "$prevstatus" != "off" ] - then - logger -t $(basename $0) "$$ Projector is off" - prevstatus="off" - fi - fi - sleep 10 -done diff --git a/scripts/beamerdetect.sh b/scripts/beamerdetect.sh index bb29b5d..695d66b 100755 --- a/scripts/beamerdetect.sh +++ b/scripts/beamerdetect.sh @@ -26,7 +26,8 @@ then exit fi signalsource="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info' |awk -F'[<>]' '//{print substr($3,33,2)}')" - if [ "$signalsource" = "00" ] || [ "$signalsource" = "15" ] || [ "$signalsource" = "" ] + #if [ "$signalsource" = "00" ] || [ "$signalsource" = "15" ] || [ "$signalsource" = "" ] + if [ "$signalsource" = "00" ] || [ "$signalsource" = "02" ] || [ "$signalsource" = "" ] then raisescreen echo "wget http://$projip/tgi/return.tgi?command=2a3102fd0660 #projector off" diff --git a/scripts/lightcommander b/scripts/lightcommander index 09704e1..c799948 100755 --- a/scripts/lightcommander +++ b/scripts/lightcommander @@ -3,8 +3,8 @@ if [ "$1" = "" ] then echo "usage: $0 {main|chill|status|labsocket|alarm|screen} {on|off}" echo "usage: $0 {projector} {on|hdmi1|hdmi2|dvi|vga1|off}" - echo "usage; $0 {receiver} {on|off|hdmi|jack1|jack2|optical}" - echo "usage: $0 {maindoor} {open}" + echo "usage; $0 {receiver} {on|off|hdmi|jack1|jack2|optical|vol-|vol+}" +# echo "usage: $0 {maindoor} {open}" exit 1 fi function dolight() { @@ -36,8 +36,8 @@ function dolight() { ;; receiver) sudo /root/pidor/scripts/beamercontrol.sh receiver "$2" ;; - maindoor) sudo /root/pidor/scripts/opendoor.sh - ;; +# maindoor) sudo /root/pidor/scripts/opendoor.sh +# ;; esac # type (2=10bit) # | house 1-16 (the dial thingie) diff --git a/scripts/opendoor.sh b/scripts/opendoor.sh index cf9696e..2eb9e2e 100755 --- a/scripts/opendoor.sh +++ b/scripts/opendoor.sh @@ -1,3 +1,3 @@ #!/bin/bash -BUZZERURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml?relay1State=2&pulseTime1=5" -wget -O - --timeout=1 --tries=1 $BUZZERSTATUSURL +RELAYURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml?relay1State=2&pulseTime1=5" +wget -O - --timeout=1 --tries=1 $RELAYURL diff --git a/scripts/upd_status.sh b/scripts/upd_status.sh index 422d07e..e70cae7 100755 --- a/scripts/upd_status.sh +++ b/scripts/upd_status.sh @@ -42,7 +42,7 @@ doorlockbutton="$(cat /run/doorlockbutton)" nai=$(stat -c "%Y" /run/spacestatus) # get mtime as status change time if [ "$status" = "open" ] then - /usr/bin/curl --max-time 1 --silent --data key="$spaceapikey" --data-urlencode sensors='{"state":{"open":true,"lastchange":'"$nai"'}}' http://spaceapi.syn2cat.lu/sensor/set + /usr/bin/curl --max-time 1 --silent --insecure --data key="$spaceapikey" --data-urlencode sensors='{"state":{"open":true,"lastchange":'"$nai"'}}' http://spaceapi.syn2cat.lu/sensor/set #logger -t $(basename $0) "$$ sending status $status to spacapi ret=$?" fi for plugin in $(ls "$0".d) @@ -60,7 +60,7 @@ then # problem: if closing state but not actually shuting door for a longer time, the status in spaceapi # will be the time of closing but not that of actually shutting the door # but the status will only be updated once the door is shut - /usr/bin/curl --max-time 1 --silent --data key="$spaceapikey" --data-urlencode sensors='{"state":{"open":false,"lastchange":'"$nai"'}}' http://spaceapi.syn2cat.lu/sensor/set + /usr/bin/curl --max-time 1 --silent --insecure --data key="$spaceapikey" --data-urlencode sensors='{"state":{"open":false,"lastchange":'"$nai"'}}' http://spaceapi.syn2cat.lu/sensor/set #logger -t $(basename $0) "$$ sending status $status to spacapi ret=$?" fi @@ -74,5 +74,5 @@ if [ "$status" = "closed" ] then presency=0 fi -/usr/bin/curl --max-time 1 --silent --data key="$spaceapikey" --data-urlencode sensors='{"sensors":{"people_now_present":[{"value":'"$presency"'}]}}' http://spaceapi.syn2cat.lu/sensor/set +/usr/bin/curl --max-time 1 --silent --insecure --data key="$spaceapikey" --data-urlencode sensors='{"sensors":{"people_now_present":[{"value":'"$presency"'}]}}' http://spaceapi.syn2cat.lu/sensor/set V diff --git a/scripts/upd_status.sh.d/tweet b/scripts/upd_status.sh.d/tweet index 87cafa4..709093c 100755 --- a/scripts/upd_status.sh.d/tweet +++ b/scripts/upd_status.sh.d/tweet @@ -50,9 +50,9 @@ if ( $currentStatus != $previousStatus ) { case 'closed': $peopleMax=""; - if($peopleMax=file_get_contents("/var/spool/peoplecountermax")) { + if($peopleMax=file_get_contents("/var/cache/peoplecountermax")) { $peopleMax=str_replace("\n", '', $peopleMax); - file_put_contents("/var/spool/peoplecountermax","0"); + file_put_contents("/var/cache/peoplecountermax","0"); if($peopleMax>8) { // only write this info if the place has been quite busy $peopleMax="There were up to $peopleMax hackers today.\n"; } else { diff --git a/www/htdocs/lights.level2.lu/index.html b/www/htdocs/lights.level2.lu/index.html index 5356281..be7723a 100644 --- a/www/htdocs/lights.level2.lu/index.html +++ b/www/htdocs/lights.level2.lu/index.html @@ -90,15 +90,20 @@

HDMI (projector) 2.0

Optical (BluRay) 5.1

Tuner

-

Off

+

Vol-

+

Vol+

+

Off

+ +