import os from os.path import join import time from . import leds, camera # Delay between to captures DELAY = 0.5 def delay_capture(cam, output_path): # Measure the time it takes to capture start = time.time() output = cam.capture(output_path) delta = time.time() - start # Wait for at least one second between each capture if delta < DELAY: time.sleep(DELAY - delta) return output def scan(output_dir: str, on_and_off: bool = True): os.makedirs(output_dir, exist_ok=True) with leds.get() as gpio_leds: for count, led in enumerate(gpio_leds.leds): with camera.get() as cam: print(f'Turn on {led}') img = join(output_dir, f'{led}') led.on() delay_capture(cam, img) led.off() print(f'Turn off {led}') yield str(led) # capture with all leds ON OFF if on_and_off: with camera.get() as cam: gpio_leds.on() img = join(output_dir, 'all_on') delay_capture(cam, img) yield 'all_on' with camera.get() as cam: gpio_leds.off() img = join(output_dir, 'all_off') delay_capture(cam, img) yield 'all_off'