75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
import RPi.GPIO as GPIO
|
|
import time
|
|
import threading
|
|
|
|
class GPIOControl:
|
|
def __init__(self, camera):
|
|
GPIO.setmode(GPIO.BCM)
|
|
self.camera = camera
|
|
|
|
#Verzögerung im Ein- und Ausschalten der Beleuchtung
|
|
self.lighting_delay = 100 / 1000
|
|
|
|
# Pin-Definitionen
|
|
self.lighting_trigger_gpio = 17 #Schalter für Beleuchtung Ein/Aus
|
|
self.camera_trigger_gpio = 27 #Schalter für Kamera auslösen
|
|
self.lighting_output_gpio = 23 #Ausgang für Beleuchtung
|
|
|
|
self.activate_flash = False
|
|
self.permanent_lighting = False
|
|
|
|
# Pin-Setup
|
|
GPIO.setup(self.lighting_trigger_gpio, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|
GPIO.setup(self.camera_trigger_gpio, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|
GPIO.setup(self.lighting_output_gpio, GPIO.OUT, initial=GPIO.LOW)
|
|
|
|
self.camera_trigger_time = None
|
|
self.running = True
|
|
|
|
def start(self):
|
|
# Startet die Überwachung in einem separaten Thread, ist wegen der blockierenden Ausführung der Benutzeroberfläche erforderlich
|
|
self.thread = threading.Thread(target=self.monitor_gpio)
|
|
self.thread.start()
|
|
|
|
def stop(self):
|
|
self.running = False
|
|
self.thread.join()
|
|
|
|
#Blitz / Dauerbeleuchtung an/aus wird durch GUI eingestellt
|
|
def get_gui_settings(self, activate_flash, permanent_lighting):
|
|
self.activate_flash = activate_flash
|
|
self.permanent_lighting = permanent_lighting
|
|
|
|
self.activate_lighting()
|
|
self.deactivate_lighting()
|
|
|
|
|
|
|
|
def activate_lighting(self):
|
|
if self.activate_flash == True or self.permanent_lighting == True:
|
|
GPIO.output(self.lighting_output_gpio, GPIO.HIGH)
|
|
|
|
def deactivate_lighting(self):
|
|
if self.permanent_lighting == False:
|
|
GPIO.output(self.lighting_output_gpio, GPIO.LOW)
|
|
|
|
def monitor_gpio(self):
|
|
try:
|
|
while self.running:
|
|
if GPIO.input(self.lighting_trigger_gpio) == GPIO.LOW:
|
|
self.activate_lighting()
|
|
|
|
if GPIO.input(self.camera_trigger_gpio) == GPIO.LOW:
|
|
self.activate_lighting()
|
|
time.sleep(self.lighting_delay)
|
|
self.camera.get_still_image()
|
|
time.sleep(self.lighting_delay)
|
|
self.deactivate_lighting()
|
|
|
|
else:
|
|
if GPIO.input(self.camera_trigger_gpio) == GPIO.HIGH and GPIO.input(self.lighting_trigger_gpio) == GPIO.HIGH:
|
|
self.deactivate_lighting()
|
|
time.sleep(0.1)
|
|
finally:
|
|
GPIO.cleanup()
|