diff --git a/README.md b/README.md index 2ea0c09..4562c43 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ ln -s $CLONE/nginx/default /etc/nginx/default ln -s $CLONE/projektor /opt/projektor apt install python3-serial python3-bottle ``` +Optionally, set keyboard hotkeys from projektor/hotkey_commands.txt + # #### web ``` @@ -51,4 +53,4 @@ systemctl start websockify.service # Now, essential code seems to be symlinked and `git pull` keeps everything up-to-date.. - And as always, this readme is under destruction :) \ No newline at end of file + And as always, this readme is under destruction :) diff --git a/projektor/control.sh b/projektor/control.sh new file mode 100755 index 0000000..0584d43 --- /dev/null +++ b/projektor/control.sh @@ -0,0 +1,167 @@ +#!/bin/bash + +PROJECTOR_HOSTNAME='projektor' + +display_help() +{ + echo "Usage: $0 [option...] []" >&2 + echo + echo " -h, --help Show this message" + echo " -f, --force" + echo + echo "Commands:" + echo " get " + echo " set " + echo " switch " + echo + echo "Settings:" + echo " power" + echo " mute" + echo " freeze" + echo + echo "Examples:" + echo " get mute" + echo " set freeze on" + echo " switch power" + exit 1 +} + +send_request() +{ + D="" + for a in $@ + do + D="$D%$a" + done + URL="http://$PROJECTOR_HOSTNAME/cgi-bin/pjctrl.cgi.elf?D=$D" + echo $(curl -s $URL | sed 's/\[//; s/\]//' | xargs -d ',') +} + +get_power() +{ + STATUS=(`send_request 06 00 85 00 00 01 01 87`) + echo ${STATUS[7]} +} + +set_power() +{ + if [[ $1 -eq 1 ]]; + then + STATUS=`send_request 05 02 00 00 00 00` + else + STATUS=`send_request 05 02 01 00 00 00` + fi +} + +switch_power() +{ + STATUS=`get_power` + if [[ $STATUS -eq 1 ]]; + then + STATUS=`set_power 0` + else + STATUS=`set_power 1` + fi +} + +get_mute() +{ + STATUS=(`send_request 06 00 85 00 00 01 03 89`) + echo ${STATUS[5]} +} + +set_mute() +{ + if [[ $1 -eq 1 ]]; + then + STATUS=`send_request 05 02 10 00 00 00 13` + else + STATUS=`send_request 05 02 11 00 00 00 13` + fi +} + +switch_mute() +{ + STATUS=`get_mute` + if [[ $STATUS -eq 1 ]]; + then + STATUS=`set_mute 0` + else + STATUS=`set_mute 1` + fi +} + +get_freeze() +{ + STATUS=(`send_request 06 00 BF 00 00 01 02 C2`) + echo ${STATUS[14]} +} + +set_freeze() +{ + if [[ $1 -eq 1 ]]; + then + STATUS=`send_request 06 01 98 00 00 01 01 00` + else + STATUS=`send_request 06 01 98 00 00 01 02 00` + fi +} + +switch_freeze() +{ + STATUS=`get_freeze` + if [[ $STATUS -eq 1 ]]; + then + STATUS=`set_freeze 0` + else + STATUS=`set_freeze 1` + fi +} + + +# options +while : +do + case "$1" in + -h | --help) + display_help + exit 0 + ;; + -f | --force) + echo "Nothing to force, man" + shift + ;; + --) + shift + break + ;; + -*) + display_help + exit 1 + ;; + *) + break + ;; + esac +done + +# commands +case "$1" in + get | set | switch) + FNAME="$1_$2" + if [[ `type -t $FNAME` == '' ]] + then + echo "Invalid parameter for $1" + display_help + exit 1 + fi + OPT=`sed 's/on/1/; s/off/0/' <<< $3` + $FNAME $OPT + ;; + *) + echo 'Invalid command' + display_help + exit 1 + ;; +esac + diff --git a/projektor/volume.txt b/projektor/hotkey_commands.txt similarity index 70% rename from projektor/volume.txt rename to projektor/hotkey_commands.txt index d0cab00..f63fbbb 100644 --- a/projektor/volume.txt +++ b/projektor/hotkey_commands.txt @@ -1,3 +1,4 @@ +# Receiver volume curl -X POST -F 'mode=volumedown' http://viido/projektor/status curl -X POST -F 'mode=volumeup' http://viido/projektor/status @@ -6,3 +7,9 @@ curl -X POST -F 'mode=viido' http://viido/projektor/status curl -X POST -F 'mode=steam' http://viido/projektor/status curl -X POST -F 'mode=hdmi' http://viido/projektor/status curl -X POST -F 'mode=aux' http://viido/projektor/status + +# Projector states +/opt/projektor/control.sh switch power +/opt/projektor/control.sh switch mute +/opt/projektor/control.sh switch freeze +