GPIOPATH=/sys/class/gpio/gpio
#VALID_ONOFF_IDS="7 18 20 29"
VALID_ONOFF_IDS="7 18 20"
+VALID_SEND_IDS=""
print_gpio_state() {
GPIOVALUE=$(cat "${GPIOPATH}${1}/value")
}
if [ "$POWER" == "1" -o "$POWER" == "0" ]; then
- for CHECKID in $VALID_ONOFF_IDS ; do
+ for CHECKID in $VALID_ONOFF_IDS ; do
if [ "$CHECKID" == "$ID" ]; then
echo "$POWER" > "${GPIOPATH}${ID}/value"
echo "Content-type: text/html"
echo "<head>"
echo "<title>Realraum Relay Power</title>"
echo '<script type="text/javascript">'
-echo 'function updateButtons(data)
-{
+echo 'function callbackUpdateButtons(req) {
+ if (req.status != 200) {
+ return;
+ }
+ var data = JSON.parse(req.responseText);
+ for (var keyid in data) {
+ on_btn = document.getElementById("onbtn_"+keyid);
+ off_btn = document.getElementById("offbtn_"+keyid);
+ if (on_btn && off_btn)
+ {
+ on_btn.className = "onbutton";
+ off_btn.className = "offbutton";
+ if (data[keyid])
+ { on_btn.className += " enableborder"; }
+ else
+ { off_btn.className += " enableborder"; }
+ }
+ }
}'
+
+echo 'function updateButtons(uri) {
+ var req = new XMLHttpRequest;
+ req.overrideMimeType("application/json");
+ req.open("GET", uri, true);
+ req.onload = function() {callbackUpdateButtons(req)};
+ req.setRequestHeader("googlechromefix","");
+ req.send(null);
+}'
+
+echo 'function sendMultiButton( str ) {
+ url = "/cgi-bin/mswitch.cgi?"+str;
+ updateButtons(url);
+}'
+
+echo 'setInterval("updateButtons(\"/cgi-bin/mswitch.cgi\");", 30*1000);'
+
echo 'function sendButton( onoff, btn )'
echo '{'
echo ' var req = new XMLHttpRequest();'
#echo ' height: 32px;'
echo ' padding:0;'
echo '}'
-
+
echo 'div.switchnameleft {'
echo ' width:12em; display:inline-block; vertical-align:middle; margin-left:3px;'
echo '}'
NAME="$(eval echo -n \$DESC_$DISPID)"
[ -z "$NAME" ] && NAME=$DISPID
-echo "<div class=\"switchbox\">"
+ echo "<div class=\"switchbox\">"
echo "<span class=\"alignbuttonsleft\">"
if gpio_is_on $DISPID; then
- echo " <button id=\"onbtn_$DISPID\" class=\"onbutton enableborder\" onClick='sendButton(\"1\",\"$DISPID\");'>On</button>"
- echo " <button id=\"offbtn_$DISPID\" class=\"offbutton\" onClick='sendButton(\"0\",\"$DISPID\");'>Off</button>"
+ echo " <button id=\"onbtn_$DISPID\" class=\"onbutton enableborder\" onClick='sendMultiButton(\"$DISPID=1\");'>On</button>"
+ echo " <button id=\"offbtn_$DISPID\" class=\"offbutton\" onClick='sendMultiButton(\"$DISPID=0\");'>Off</button>"
else
- echo " <button id=\"onbtn_$DISPID\" class=\"onbutton\" onClick='sendButton(\"1\",\"$DISPID\");'>On</button>"
- echo " <button id=\"offbtn_$DISPID\" class=\"offbutton enableborder\" onClick='sendButton(\"0\",\"$DISPID\");'>Off</button>"
+ echo " <button id=\"onbtn_$DISPID\" class=\"onbutton\" onClick='sendMultiButton(\"$DISPID=1\");'>On</button>"
+ echo " <button id=\"offbtn_$DISPID\" class=\"offbutton enableborder\" onClick='sendMultiButton(\"$DISPID=0\");'>Off</button>"
fi
echo "</span>"
echo -n "<div class=\"switchnameright\">$NAME</div>"
# print_gpio_state $DISPID
# echo ")</div>"
echo "</div>"
-
+
if [ "$NOFLOAT" == "1" ]; then
echo "<br/>"
- fi
+ fi
done
+echo "<div class=\"switchbox\">"
+echo "<span class=\"alignbuttonsleft\">"
+echo -n " <button class=\"onbutton\" onClick='sendMultiButton(\""
+for DISPID in $VALID_ONOFF_IDS; do echo -n "$DISPID=1&"; done
+echo "\");'>On</button>"
+echo -n " <button class=\"offbutton\" onClick='sendMultiButton(\""
+for DISPID in $VALID_ONOFF_IDS; do echo -n "$DISPID=0&"; done
+echo "\");'>Off</button>"
+echo "</span>"
+echo -n "<div class=\"switchnameright\">Alle</div>"
+echo "</div>"
+if [ "$NOFLOAT" == "1" ]; then
+ echo "<br/>"
+fi
echo "</div>"
-if [ "$MOBILE" != "1" ]; then
+if [ "$MOBILE" != "1" -a -n "$VALID_SEND_IDS" ]; then
echo "<div style=\"float:left; border:1px solid black; margin-right:2ex; margin-bottom:2ex;\">"
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>"
-
- if [ "$NOFLOAT" == "1" ]; then
- echo "<div style=\"float:left; border:1px solid black;\">"
- tail -n+107 /www/ymhremote.html | head -n 5
- echo "</div>"
- fi
-echo "<div style=\"float:left; border:1px solid black; margin-top:5px;\">"
-for DISPID in $VALID_BANSHEE_IDS $VALID_CAM_MOTOR_IDS; do
- 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" ]; then
+ if [ "$NOFLOAT" == "1" -a $((ITEMCOUNT % 2 )) -ne 1 ]; then
echo "<br/>"
- fi
+ fi
done
echo "</div>"