intial import from article

This commit is contained in:
2019-07-31 20:02:36 +02:00
commit a46da2a8bf
3 changed files with 99 additions and 0 deletions

12
pir.service Normal file
View File

@@ -0,0 +1,12 @@
[Unit]
Description=Display timeout PIR daemon
Wants=local-fs.target
[Service]
ExecStart=/usr/local/sbin/pir
Restart=always
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target

51
smartmirror_ir.py Normal file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env python
import RPi.GPIO as GPIO
import os
import time
import sys
# PIR pin
PIR_GPIO = 16
# Display timeout in seconds
TIMEOUT = 60
# DONT EDIT BELOW THIS LINE
# UNLESS YOU KNOW WHAT YOU ARE DOING
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIR_GPIO, GPIO.IN)
timer = 0
display = False
def set_display(enable):
global display
display = enable
os.system("vcgencmd display_power " + str(int(enable)))
def check_timeout():
if timer >= TIMEOUT and display:
set_display(False)
elif not display and timer < TIMEOUT:
set_display(True)
def motion(pin):
global timer
timer = 0
if __name__ == "__main__":
try:
GPIO.add_event_detect(PIR_GPIO, GPIO.RISING, callback=motion)
while True:
time.sleep(1)
if timer < TIMEOUT:
timer += 1
check_timeout()
except KeyboardInterrupt:
GPIO.cleanup()
sys.exit(0)

36
smartmirror_poll.py Normal file
View File

@@ -0,0 +1,36 @@
import RPi.GPIO as GPIO
import time
import os
#Board Mode: Angabe der Pin-Nummer
GPIO.setmode(GPIO.BOARD)
#GPIO Pin definieren fuer den Dateneingang vom Sensor
PIR_GPIO = 16
GPIO.setup(PIR_GPIO,GPIO.IN)
read=0
wait=0
try:
#PIR auslesen
while GPIO.input(PIR_GPIO)==1:
read=0
#Abbruch ctrl+c
while True :
#PIR Status abfragen
read = GPIO.input(PIR_GPIO)
if read==1 and wait==0:
os.system("vcgencmd display_power 1")
wait=1
elif read==0 and wait==1:
wait=0
time.sleep(0.01)
except KeyboardInterrupt:
GPIO.cleanup()