From 0a2770351d4d4e895f0c45fd24b74e2f3a742205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Sat, 28 Jun 2025 09:00:17 +0200 Subject: [PATCH] qr timeout - cancel in IDLE mode --- Fotobox.py | 22 ++++++++++++---------- timer.py | 3 +++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Fotobox.py b/Fotobox.py index 2d2d3e0..04c6a21 100644 --- a/Fotobox.py +++ b/Fotobox.py @@ -97,16 +97,16 @@ class Fotobox: camera.hflip = True camera.resolution = (2592, 1944) camera.rotation = 270 - + camera.preview_configuration.main.size = res camera.preview_configuration.main.format = 'BGR888' camera.configure("preview") - + self._capture_config = camera.create_still_configuration() camera.still_configuration.main.size = (2592, 1944) - + camera.start() - + self._camera = camera self._running: bool = True self._state: State = State.IDLE @@ -144,16 +144,16 @@ class Fotobox: def _shooting_callback(self): print("SHOT: %d/%d" % (self._shooting_timer.current(), SHOOTING_COUNT)) - + screen.fill((255, 255, 255)) pygame.display.flip() if not DEBUG: time.sleep(0.5) - + frame = self._camera.switch_mode_and_capture_array(self._capture_config, "main") image = Image.fromarray(frame) self._photos.append(Photo(self._shooting_timer.current(), image)) - + screen.fill((0, 0, 0)) pygame.display.flip() @@ -268,7 +268,7 @@ class Fotobox: screen.blit(PRINT_SURFACE, PRINT_RECT) screen.blit(DONE_SURFACE, DONE_RECT) pygame.display.flip() - + def _draw_live_frame(self): array = self._camera.capture_array() img = pygame.image.frombuffer(array.data, res, 'RGB') @@ -277,7 +277,9 @@ class Fotobox: def _set_state(self, new_state: State): print(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) self._countdown_timer.restart() elif new_state == State.SHOOTING: @@ -349,5 +351,5 @@ class Fotobox: os.link(path, upload) os.chmod(upload, 0o777) print("Photo saved: %s" % path.absolute()) - + diff --git a/timer.py b/timer.py index f926984..65a68c4 100644 --- a/timer.py +++ b/timer.py @@ -32,6 +32,9 @@ class Timer: if self._callback: self._callback() + def cancel(self): + self._enabled = False + def current(self): return self._current