commit a46da2a8bf9809a998580f4a355f51217bde5278 Author: Giovanni Harting <539@idlegandalf.com> Date: Wed Jul 31 20:02:36 2019 +0200 intial import from article diff --git a/pir.service b/pir.service new file mode 100644 index 0000000..db867c3 --- /dev/null +++ b/pir.service @@ -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 + diff --git a/smartmirror_ir.py b/smartmirror_ir.py new file mode 100644 index 0000000..018b483 --- /dev/null +++ b/smartmirror_ir.py @@ -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) + diff --git a/smartmirror_poll.py b/smartmirror_poll.py new file mode 100644 index 0000000..5159182 --- /dev/null +++ b/smartmirror_poll.py @@ -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() +