43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import os
|
|
from os.path import join
|
|
import time
|
|
from . import config
|
|
|
|
# Delay between to captures
|
|
DELAY = 0.5
|
|
|
|
|
|
def scan(output_dir: str):
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
with config.GPIO_LEDS:
|
|
for count, led in enumerate(config.GPIO_LEDS.leds):
|
|
print(f'Turn on {led}')
|
|
img = join(output_dir, f'{led}')
|
|
|
|
# Measure the time it takes to capture
|
|
start = time.time()
|
|
|
|
led.on()
|
|
config.CAMERA.capture(img)
|
|
led.off()
|
|
|
|
delta = time.time() - start
|
|
|
|
# Wait for at least one second between each capture
|
|
if delta < DELAY:
|
|
time.sleep(DELAY - delta)
|
|
|
|
print(f'Turn off {led}')
|
|
if count == len(config.LEDS_UUIDS) - 1:
|
|
# capture with all leds ON OFF
|
|
config.GPIO_LEDS.on()
|
|
img = join(output_dir, 'all_on')
|
|
config.CAMERA.capture(img)
|
|
|
|
config.GPIO_LEDS.off()
|
|
img = join(output_dir, 'all_off')
|
|
config.CAMERA.capture(img)
|
|
|
|
yield led
|