diff --git a/config.darkroom.py b/config.darkroom.py index 7e77861..a0d838c 100644 --- a/config.darkroom.py +++ b/config.darkroom.py @@ -7,7 +7,7 @@ OBJECT_DIR = join(DATA_DIR, 'objects') DATABASE_PATH = join(DATA_DIR, 'db.sqlite') AUTO_USE_LAST_CALIBRATION = True -DELAY = 0.0 +DELAY = None GPIO_CHIP = 'gpiochip0' LEDS_UUIDS = [17, 18, 22, 23, 24, 27] CAMERA = 'real' diff --git a/scanner.py b/scanner.py index 422efe8..b221deb 100644 --- a/scanner.py +++ b/scanner.py @@ -11,7 +11,21 @@ def delay_capture(cam): delta = time.time() - start # Wait for at least one second between each capture - if delta < config.DELAY: + if config.DELAY is not None and delta < config.DELAY: + time.sleep(config.DELAY - delta) + + return output + + +def delay_save(cam, source, target): + # Measure the time it takes to save + start = time.time() + output = cam.capture() + cam.save(source, target) + delta = time.time() - start + + # Wait for at least one second between each save + if config.DELAY is not None and delta < config.DELAY: time.sleep(config.DELAY - delta) return output @@ -25,7 +39,6 @@ def scan(output_dir: str, on_and_off: bool = True): with leds.get() as gpio_leds: for count, led in enumerate(gpio_leds.leds): print(f'Turn on {led}') - img = join(output_dir, f'{led}') led.on() file_paths.append((str(led), delay_capture(cam))) @@ -36,14 +49,12 @@ def scan(output_dir: str, on_and_off: bool = True): # capture with all leds ON OFF if on_and_off: gpio_leds.on() - img = join(output_dir, 'all_on') file_paths.append(('all_on', delay_capture(cam))) gpio_leds.off() - img = join(output_dir, 'all_off') file_paths.append(('all_off', delay_capture(cam))) with camera.get() as cam: for target, source in file_paths: - cam.save(source, join(output_dir, target)) + delay_save(cam, source, join(output_dir, target)) yield target