GPIO flash and spots
This commit is contained in:
parent
8f091c8831
commit
4c27cc6300
64
Fotobox.py
64
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())
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user