From 8f476b3ad609555cab9e7343098080c5e349653d Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Tue, 22 Oct 2013 22:10:57 +0000 Subject: [PATCH] display state and switch multiple at once --- router_gpio_relay_licht/mswitch.cgi | 59 +++++++++++++++++++++++++++++++++++ router_gpio_relay_licht/switch.cgi | 34 ++++++++++++++++++-- 2 files changed, 90 insertions(+), 3 deletions(-) create mode 100755 router_gpio_relay_licht/mswitch.cgi diff --git a/router_gpio_relay_licht/mswitch.cgi b/router_gpio_relay_licht/mswitch.cgi new file mode 100755 index 0000000..6d0d587 --- /dev/null +++ b/router_gpio_relay_licht/mswitch.cgi @@ -0,0 +1,59 @@ +#!/bin/sh + +VALID_ONOFF_IDS="7 18 20" +GPIOPATH=/sys/class/gpio/gpio + +for QUERY in `echo $QUERY_STRING | tr '&' ' '`; do + for VALIDID in $VALID_ONOFF_IDS; do + if [ "$QUERY" == "$VALIDID=1" ]; then + eval "GPIO_$VALIDID"=1 + elif [ "$QUERY" == "$VALIDID=0" ]; then + eval "GPIO_$VALIDID=0" + elif [ "$QUERY" == "$VALIDID=q" ]; then + eval "GPIO_$VALIDID=q" + fi + done + if [ "$QUERY" == "mobile=1" ]; then + MOBILE='1' + NOFLOAT='1' + elif [ "$QUERY" == "nofloat=1" ]; then + NOFLOAT='1' + fi +done + + +print_gpio_state() { + GPIOVALUE=$(cat "${GPIOPATH}${1}/value") + if [ "$GPIOVALUE" = "1" ]; then + echo "1" + else + echo "0" + fi +} + +gpio_is_on() { + GPIOVALUE=$(cat "${GPIOPATH}${1}/value") + [ "$GPIOVALUE" = "1" ] +} + +echo "Content-type: text/html" +echo "" + + +for CHECKID in $VALID_ONOFF_IDS; do + VAL="" + VAL="$(eval echo \$GPIO_$CHECKID)" + if [ $VAL == 1 -o $VAL == 0 ]; then + echo "$VAL" > "${GPIOPATH}${CHECKID}/value" + fi + echo -n "$CHECKID:" + print_gpio_state $CHECKID +done + +# echo "" +# echo "" +# echo "Realraum Relay Switch" +# echo '' +# echo "" +# exit 0 + diff --git a/router_gpio_relay_licht/switch.cgi b/router_gpio_relay_licht/switch.cgi index 9f53097..9406356 100755 --- a/router_gpio_relay_licht/switch.cgi +++ b/router_gpio_relay_licht/switch.cgi @@ -25,6 +25,20 @@ GPIOPATH=/sys/class/gpio/gpio #VALID_ONOFF_IDS="7 18 20 29" VALID_ONOFF_IDS="7 18 20" +print_gpio_state() { + GPIOVALUE=$(cat "${GPIOPATH}${1}/value") + if [ "$GPIOVALUE" = "1" ]; then + echo "ON" + else + echo "Off" + fi +} + +gpio_is_on() { + GPIOVALUE=$(cat "${GPIOPATH}${1}/value") + [ "$GPIOVALUE" = "1" ] +} + if [ "$POWER" == "1" -o "$POWER" == "0" ]; then for CHECKID in $VALID_ONOFF_IDS ; do if [ "$CHECKID" == "$ID" ]; then @@ -113,6 +127,12 @@ echo ' height: 32px;' #echo ' background-color: grey;' echo ' margin: 0px;' echo '}' + +echo '.enableborder { + font-weight: bold; + font-variant: small-caps; + border-style: inset;' +echo '}' echo '' echo "" echo "" @@ -121,15 +141,23 @@ echo "" echo "
" echo "
" for DISPID in $VALID_ONOFF_IDS; do - NAME="$(eval echo \$DESC_$DISPID)" + NAME="$(eval echo -n \$DESC_$DISPID)" [ -z "$NAME" ] && NAME=$DISPID echo "
" echo "" - echo " " + if gpio_is_on $DISPID; then + echo " " echo " " + else + echo " " + echo " " + fi echo "" - echo "
$NAME
" + echo -n "
$NAME
" +# echo -n "
$NAME (" +# print_gpio_state $DISPID +# echo ")
" echo "
" if [ "$NOFLOAT" == "1" ]; then -- 1.7.10.4