qr timeout - cancel in IDLE mode

This commit is contained in:
Patrick Haßel 2025-06-28 09:00:17 +02:00
parent 11701f58b8
commit 0a2770351d
2 changed files with 15 additions and 10 deletions

View File

@ -97,16 +97,16 @@ class Fotobox:
camera.hflip = True camera.hflip = True
camera.resolution = (2592, 1944) camera.resolution = (2592, 1944)
camera.rotation = 270 camera.rotation = 270
camera.preview_configuration.main.size = res camera.preview_configuration.main.size = res
camera.preview_configuration.main.format = 'BGR888' camera.preview_configuration.main.format = 'BGR888'
camera.configure("preview") camera.configure("preview")
self._capture_config = camera.create_still_configuration() self._capture_config = camera.create_still_configuration()
camera.still_configuration.main.size = (2592, 1944) camera.still_configuration.main.size = (2592, 1944)
camera.start() camera.start()
self._camera = camera self._camera = camera
self._running: bool = True self._running: bool = True
self._state: State = State.IDLE self._state: State = State.IDLE
@ -144,16 +144,16 @@ class Fotobox:
def _shooting_callback(self): def _shooting_callback(self):
print("SHOT: %d/%d" % (self._shooting_timer.current(), SHOOTING_COUNT)) print("SHOT: %d/%d" % (self._shooting_timer.current(), SHOOTING_COUNT))
screen.fill((255, 255, 255)) screen.fill((255, 255, 255))
pygame.display.flip() pygame.display.flip()
if not DEBUG: if not DEBUG:
time.sleep(0.5) time.sleep(0.5)
frame = self._camera.switch_mode_and_capture_array(self._capture_config, "main") frame = self._camera.switch_mode_and_capture_array(self._capture_config, "main")
image = Image.fromarray(frame) image = Image.fromarray(frame)
self._photos.append(Photo(self._shooting_timer.current(), image)) self._photos.append(Photo(self._shooting_timer.current(), image))
screen.fill((0, 0, 0)) screen.fill((0, 0, 0))
pygame.display.flip() pygame.display.flip()
@ -268,7 +268,7 @@ class Fotobox:
screen.blit(PRINT_SURFACE, PRINT_RECT) screen.blit(PRINT_SURFACE, PRINT_RECT)
screen.blit(DONE_SURFACE, DONE_RECT) screen.blit(DONE_SURFACE, DONE_RECT)
pygame.display.flip() pygame.display.flip()
def _draw_live_frame(self): def _draw_live_frame(self):
array = self._camera.capture_array() array = self._camera.capture_array()
img = pygame.image.frombuffer(array.data, res, 'RGB') img = pygame.image.frombuffer(array.data, res, 'RGB')
@ -277,7 +277,9 @@ class Fotobox:
def _set_state(self, new_state: State): def _set_state(self, new_state: State):
print(new_state) print(new_state)
self._state = new_state self._state = new_state
if new_state == State.COUNTDOWN: if new_state == State.IDLE:
self._qr_timer.cancel()
elif new_state == State.COUNTDOWN:
led_border(True) led_border(True)
self._countdown_timer.restart() self._countdown_timer.restart()
elif new_state == State.SHOOTING: elif new_state == State.SHOOTING:
@ -349,5 +351,5 @@ class Fotobox:
os.link(path, upload) os.link(path, upload)
os.chmod(upload, 0o777) os.chmod(upload, 0o777)
print("Photo saved: %s" % path.absolute()) print("Photo saved: %s" % path.absolute())

View File

@ -32,6 +32,9 @@ class Timer:
if self._callback: if self._callback:
self._callback() self._callback()
def cancel(self):
self._enabled = False
def current(self): def current(self):
return self._current return self._current