From 4c27cc630008fcbd0981d95673fe06b3458efc60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Sat, 28 Jun 2025 08:03:41 +0200 Subject: [PATCH] GPIO flash and spots --- Fotobox.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/Fotobox.py b/Fotobox.py index 6197bfc..fdacf2c 100644 --- a/Fotobox.py +++ b/Fotobox.py @@ -18,6 +18,67 @@ from config import read, file_increase, iso, now from timer import Timer from libcamera import Transform +import RPi.GPIO as GPIO + +GPIO_LED_BORDER = 7 +GPIO_SPOT_RIGHT = 35 +GPIO_SPOT_LEFT = 37 +GPIO_BUTTON_LED = 36 +GPIO_BUTTON = 38 + + +# GPIO helpers + +spot_mode = 0 + +def led_border(state): + global GPIO_LED_BORDER + GPIO.output(GPIO_LED_BORDER, state) + + +def set_spot_mode(new_mode): + global spot_mode + spot_mode = new_mode % 4 + GPIO.output(GPIO_SPOT_LEFT, not (spot_mode & 1)) + GPIO.output(GPIO_SPOT_RIGHT, not (spot_mode & 2)) + + +def next_spot_mode(): + global spot_mode + set_spot_mode(spot_mode + 1) + + +# user interface + +def button_press(gpio_id): + next_spot_mode() + + +# INIT GPIO +GPIO.setmode(GPIO.BOARD) +GPIO.setwarnings(False) + +GPIO.setup(GPIO_SPOT_RIGHT, GPIO.OUT, initial=GPIO.HIGH) +GPIO.setup(GPIO_SPOT_LEFT, GPIO.OUT, initial=GPIO.HIGH) +GPIO.setup(GPIO_LED_BORDER, GPIO.OUT, initial=GPIO.LOW) +GPIO.setup(GPIO_BUTTON_LED, GPIO.OUT, initial=GPIO.LOW) + +GPIO.setup(GPIO_BUTTON, GPIO.IN) +GPIO.add_event_detect(GPIO_BUTTON, GPIO.FALLING, button_press, bouncetime=300) + +led_border(False) +time.sleep(0.02) +led_border(True) +time.sleep(0.02) +led_border(False) +time.sleep(0.02) +led_border(True) +time.sleep(0.02) +led_border(False) +time.sleep(0.02) +led_border(True) +time.sleep(0.02) +led_border(False) class State(Enum): IDLE = 0 @@ -207,6 +268,7 @@ class Fotobox: print(new_state) self._state = new_state if new_state == State.COUNTDOWN: + led_border(True) self._countdown_timer.restart() elif new_state == State.SHOOTING: self._photos = [] @@ -215,6 +277,7 @@ class Fotobox: print("Starting shooting: S%04d-%s" % (self._shooting_number, iso(self._shooting_datetime))) self._shooting_timer.restart() elif new_state == State.PREPARE: + led_border(False) screen.fill((0, 0, 0)) screen.blit(LOADING_SURFACE, LOADING_RECT) pygame.display.flip() @@ -275,3 +338,4 @@ class Fotobox: os.chmod(upload, 0o777) print("Photo saved: %s" % path.absolute()) +