removed flash by semaphore in redis. error code display on clock dial

py3
Level2 DoorBuzz 2016-03-24 23:33:11 +01:00
parent 01a6c13db3
commit 3fabf743f5
4 changed files with 64 additions and 22 deletions

View File

@ -24,7 +24,7 @@ pulseon() {
echo $!
}
echo "Initializing hardware"
logger $0 "Initializing hardware"
# the button
ledcolor() {
@ -33,7 +33,7 @@ ledcolor() {
blue=$3
showleds set $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION))
}
echo "Main loop"
logger $0 "Main loop"
while true
do
if [ $(arp -a | awk '{arp[$2]=$4;ip[$4]=ip[$4]" "$2}END{print ip[arp["(10.2.113.1)"]]}' | wc -w) -gt 1 ]

View File

@ -1,5 +1,4 @@
#!/bin/bash
# led is not neopixel, so use the python lib for that
BUTTONPIN=25
BUZZERURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml?relay1State=2&pulseTime1=5"
BUZZERSTATUSURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml"
@ -9,11 +8,13 @@ cd $(dirname "$0")
showleds() {
./redi.sh <<EOF
valid=no
neoaction=$1
neored=$2
neogreen=$3
neoblue=$4
neomorse=$5
neovalue=$5
valid=yes
EOF
# sudo kill $(ps -edf| awk '/[s]etneocolor.py/{print $2}' ) 2>/dev/null
# sudo python /home/pi/doorbuzz/setneocolor.py $1 $2 $3 $4
@ -58,7 +59,7 @@ morse[8]="---.."
morse[9]="----."
morseled() {
message=$1
echo $message
logger $0 morseled $message
msglen=${#message}
pos=0
morsecode=""
@ -75,14 +76,36 @@ echo $morsecode
echo
}
dialcode() {
# shows number code on clock dial
message=$1
logger $0 dialcode $message
msglen=${#message}
pos=0
while [ $pos -lt $msglen ]
do
dcode="${message:${pos}:1}"
dcode=$((dcode*5)) # convert numbers into clock values
pos=$((pos+1))
echo $dcode
red=$2
green=$3
blue=$4
showleds set 0 0 0
showleds number $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) "$dcode"
sleep 1
done
showleds set 0 0 0
}
echo "morsing IP"
morseled "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 255 0 0
sleep 10
echo "Main loop"
logger $0 "morsing IP"
#morseled "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 255 0 0
dialcode "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 255 0 0
sleep 1
logger $0 "Main loop"
while true
do
ledcolor 0 255 255
#ledcolor 0 255 255
pulsepid=$(pulseon 0 0 255 )
trap "ledcolor 0 0 0;exit" 1 2 3
gpio -g wfi $BUTTONPIN falling
@ -91,12 +114,13 @@ do
gpio -g wfi $BUTTONPIN falling
done
ledcolor 0 255 255
echo "Pushiii"
logger $0 "Big Red Button pushed"
wget -O - -S --timeout=1 --tries=1 "$BUZZERURL" 2>&1
ret=$?
if [ $ret -ne 0 ]
then
morseled "$ret" 255 0 0
#morseled "$ret" 255 0 0
dialcode "$ret" 255 0 0
sleep 5
else
while wget -O - --timeout=1 --tries=1 $BUZZERSTATUSURL|grep '<relay1state>1</relay1state>'
@ -107,7 +131,7 @@ do
sleep 0.1
done
fi
echo "DOOONE"
logger $0 "button push action finished"
done

View File

@ -17,10 +17,10 @@ do
ret=$?
if [ $ret -eq 1 ] # no more coprocess
then
echo "connecting to pidor"
logger $0 "connecting to pidor"
coproc ssh -i ~/.ssh/doorbuzz $pidor
sleep 10
echo "connected"
logger $0 "connected"
echo "flashoff" >&"${COPROC[1]}"
ret=0
fi
@ -28,7 +28,7 @@ do
then
break
fi
echo "$status"
logger $0 "$status"
done
echo "spacestatus" >&"${COPROC[1]}"
read status <&"${COPROC[0]}"
@ -46,7 +46,7 @@ do
if [ "$new_status" -eq "$old_status" ]; then
continue
fi
echo "phone status change detected"
logger $0 "phone status change detected"
if [ "$new_status" -eq 0 ]; then
echo "neoaction=flash" | ./redi.sh
echo "flashon" >&"${COPROC[1]}"

View File

@ -30,6 +30,10 @@ def wheel(pos):
def clockcalc(value):
return 1+((30+int(value))%60)
def showit():
if ( valid == "yes" ):
strip.show()
# Main program logic follows:
if __name__ == '__main__':
# Create NeoPixel object with appropriate configuration.
@ -55,17 +59,31 @@ if __name__ == '__main__':
action=myredis.get('neoaction')
except:
action="set"
try:
valid=myredis.get('valid')
except:
valid="yes"
if ( valid != "yes" ):
continue
if(action == "set"):
print "Color set to: ",r,g,b
for i in range(0,LED_COUNT):
strip.setPixelColor(i, Color(r,g,b))
strip.show()
showit()
if(action == "number"):
tmp=myredis.get('neovalue')
if(not tmp):
continue
i=clockcalc(int(tmp))
print "Digit ",i," set to: ",r,g,b
strip.setPixelColor(i, Color(r,g,b))
showit()
if(action == "morse"):
print "Morsing with: ",r,g,b
speed=10
for i in range(0,LED_COUNT):
strip.setPixelColor(i, Color(0,0,0))
morsecode=myredis.get('neomorse')
morsecode=myredis.get('neovalue')
morsep=1
for c in morsecode:
if c==".":
@ -91,7 +109,7 @@ if __name__ == '__main__':
morsep+=1
strip.setPixelColor(morsep, Color(0,0,0))
morsep+=1
strip.show()
showit()
time.sleep(1)
if(action == "pulse"):
print "Pulsing with: ",r,g,b
@ -112,7 +130,7 @@ if __name__ == '__main__':
strip.setPixelColor(clockcalc(j), color)
strip.setPixelColor(clockcalc(time.strftime('%M',time.localtime())),Color(30,0,0))
strip.setPixelColor(clockcalc(time.strftime('%S',time.localtime())),Color(0,30,0))
strip.show()
showit()
time.sleep(50/1000.0)
if(action == "flash"):
@ -129,7 +147,7 @@ if __name__ == '__main__':
for q in range(3):
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i+q, wheel((i+j) % 255))
strip.show()
showit()
time.sleep(wait_ms/1000.0)
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i+q, 0)