#!/bin/zsh
-VALID_ONOFF_IDS=(4 17 18 21 22 23)
+VALID_ONOFF_IDS=(ceiling1 ceiling2 ceiling3 ceiling4 ceiling5 ceiling6)
+VALID_GPIO_IDS=(4 23 18 17 22 21)
+local -A IDGPIOMAP
+local -A GPIOIDMAP
+IDGPIOMAP[ceiling1]=4
+IDGPIOMAP[ceiling2]=23
+IDGPIOMAP[ceiling3]=18
+IDGPIOMAP[ceiling4]=17
+IDGPIOMAP[ceiling5]=22
+IDGPIOMAP[ceiling6]=21
GPIOPATH=/sys/class/gpio/gpio
+
+for k v in ${(kv)IDGPIOMAP}; do
+ GPIOIDMAP[$v]=$k
+done
+
local -A GPIOS
for QUERY in `echo $QUERY_STRING | tr '&' ' '`; do
for VALIDID in $VALID_ONOFF_IDS; do
if [ "$QUERY" = "$VALIDID=1" ]; then
- GPIOS[$VALIDID]=1
+ GPIOS[$IDGPIOMAP[$VALIDID]]=1
elif [ "$QUERY" = "$VALIDID=0" ]; then
- GPIOS[$VALIDID]=0
+ GPIOS[$IDGPIOMAP[$VALIDID]]=0
fi
done
if [ "$QUERY" = "mobile=1" ]; then
print_gpio_state() {
- GPIOVALUE=$(cat "${GPIOPATH}${1}/value")
+ GPIO=${IDGPIOMAP[$1]}
+ GPIOVALUE=$(cat "${GPIOPATH}${GPIO}/value")
if [[ $GPIOVALUE == "0" ]]; then
echo -n "true"
else
}
gpio_is_on() {
- GPIOVALUE=$(cat "${GPIOPATH}${1}/value")
+ GPIO=${IDGPIOMAP[$1]}
+ GPIOVALUE=$(cat "${GPIOPATH}${GPIO}/value")
[ "$GPIOVALUE" = "0" ]
}
local -a GPIOSTATES
for CHECKID in $VALID_ONOFF_IDS; do
- VAL=$GPIOS[$CHECKID]
+ VAL=$GPIOS[$IDGPIOMAP[$CHECKID]]
if [[ $VAL == 1 || $VAL == 0 ]]; then
[[ $VAL == 1 ]] && VAL=0 || VAL=1
- echo "$VAL" > "${GPIOPATH}${CHECKID}/value"
+ echo "$VAL" > "${GPIOPATH}${IDGPIOMAP[$CHECKID]}/value"
fi
GPIOSTATES+=(\"${CHECKID}\":"$(print_gpio_state $CHECKID)")
done
done
done
-
-GPIOPATH=/sys/class/gpio/gpio
-VALID_ONOFF_IDS="4 23 18 17 22 21"
+VALID_ONOFF_IDS="ceiling1 ceiling2 ceiling3 ceiling4 ceiling5 ceiling6"
VALID_SEND_IDS=""
-print_gpio_state() {
- GPIOVALUE=$(cat "${GPIOPATH}${1}/value")
- if [ "$GPIOVALUE" = "0" ]; then
- echo "ON"
- else
- echo "Off"
- fi
-}
-
-gpio_is_on() {
- GPIOVALUE=$(cat "${GPIOPATH}${1}/value")
- [ "$GPIOVALUE" = "0" ]
-}
-
-if [ "$POWER" = "1" -o "$POWER" = "0" ]; then
- for CHECKID in $VALID_ONOFF_IDS ; do
- if [ "$CHECKID" = "$ID" ]; then
- [ $POWER = 1 ] && POWER=0 || POWER=1
- echo "$POWER" > "${GPIOPATH}${ID}/value"
- echo "Content-type: text/html"
- echo ""
- echo "<html>"
- echo "<head>"
- echo "<title>Realraum Relay Switch</title>"
- echo '<script type="text/javascript">window.location="/cgi-bin/switch.cgi";</script>'
- echo "</head></html>"
- exit 0
- fi
- done
-fi
-
-DESC_23="Decke Leinwand (S)"
-DESC_4="Decke E-Labor (SSW)"
-DESC_18="Decke Eingang (W)"
-DESC_17="Decke Durchgang (O)"
-DESC_22="Decke Auslage (N)"
-DESC_21="Decke Küche (NNO)"
+DESC_ceiling1="Decke Leinwand (S)"
+DESC_ceiling2 ="Decke E-Labor (SSW)"
+DESC_ceiling3 ="Decke Eingang (W)"
+DESC_ceiling4 ="Decke Durchgang (O)"
+DESC_ceiling5 ="Decke Auslage (N)"
+DESC_ceiling6 ="Decke Küche (NNO)"
echo "Content-type: text/html"
echo ""
}'
echo 'setInterval("updateButtons(\"/cgi-bin/mswitch.cgi\");", 30*1000);'
+echo 'updateButtons("/cgi-bin/mswitch.cgi");'
-echo 'function sendButton( onoff, btn )'
-echo '{'
-echo ' var req = new XMLHttpRequest();'
-echo ' url = "/cgi-bin/switch.cgi?power="+onoff+"&id="+btn;'
-echo ' req.open("GET", url ,false);'
-echo ' //google chrome workaround'
-echo ' req.setRequestHeader("googlechromefix","");'
-echo ' req.send(null);'
-echo '}'
echo '</script>'
echo '<style>'
echo 'div.switchbox {'
ITEMCOUNT=0
-for DISPID in $VALID_SEND_IDS; do
- ITEMCOUNT=$((ITEMCOUNT+1))
- NAME="$(eval echo \$DESC_$DISPID)"
- [ -z "$NAME" ] && NAME=$DISPID
-
- echo "<div class=\"switchbox\">"
- echo "<span class=\"alignbuttonsleft\">"
- echo " <button class=\"sendbutton\" onClick='sendButton(\"on\",\"$DISPID\");'> </button>"
- echo "</span>"
- echo "<div class=\"switchnameright\">$NAME</div>"
- echo "</div>"
- if [ "$NOFLOAT" = "1" -a $((ITEMCOUNT % 2 )) -ne 1 ]; then
- echo "<br/>"
- fi
-
-done
echo "</div>"
fi
echo "</div>"