diff --git a/chch-power.py b/chch-power.py index 654aa01..29dcd31 100644 --- a/chch-power.py +++ b/chch-power.py @@ -1,5 +1,6 @@ import pifacedigitalio import time +from subprocess import call button_count = 8 longpress_delay = 0.4 @@ -35,8 +36,7 @@ def switch_longpressed(event): elif pin_shortpress_count[event.pin_num] == 1: event.chip.output_pins[event.pin_num].toggle() elif pin_shortpress_count[event.pin_num] == 2: - for i in range(button_count): - event.chip.output_pins[i].turn_on() + call(["/root/chch-power/ligth.sh"]) def switch_verylongpressed(event): shortpress_delay = pin_last_rise_date[event.pin_num] - pin_last_shortpress[event.pin_num] diff --git a/ligth.sh b/ligth.sh new file mode 100755 index 0000000..a5cc55c --- /dev/null +++ b/ligth.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +TMPFILE=/tmp/light_state +touch $TMPFILE +LIGHT_STATE=$(cat $TMPFILE) +[ -z "$LIGHT_STATE" ] && LIGHT_STATE=0 + +STATE_0="a\x00\x03\x00\x00\x00" +STATE_1="a\x00\x03\xff\xff\xff" +STATE_2="n\x00\x02\x01\x00" + +LIGHT_STATE=$(( $LIGHT_STATE+1 )) +case $LIGHT_STATE in + 0) + STATE=$STATE_0 + ;; + 1) + STATE=$STATE_1 + ;; + 2) + STATE=$STATE_2 + ;; + *) + STATE=$STATE_0 + LIGHT_STATE=0 + ;; +esac + +echo -en $STATE | nc -w1 172.23.92.15 49152 +echo $LIGHT_STATE > $TMPFILE