diff --git a/requirements.txt b/requirements.txt index 3718bca..1dacac3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,5 @@ Flask pillow opencv-python gphoto2 -gpiozero scipy lgpio diff --git a/scanner.py b/scanner.py index c58175e..bba3da1 100644 --- a/scanner.py +++ b/scanner.py @@ -4,12 +4,14 @@ from os.path import join import shutil import time import gphoto2 as gp -from gpiozero import PWMLED +import gpiod from . import config # Delay between to captures DELAY = 0.5 +LED2_PIN = 17 +LED3_PIN = 18 def capture(output_path: str) -> bool: try: @@ -21,32 +23,46 @@ def capture(output_path: str) -> bool: target =output_path print('Copying image to', target) camera_file = camera.file_get( - file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL) + file_path.folder, file_path.name, gp.GP_FILE_TYPE_RAW) camera_file.save(target) + camera.exit() s = True except: print(f'Somethings wrong on gphoto2') s = False - finally: - camera.exit() + return s def scan(output_dir: str): os.makedirs(output_dir, exist_ok=True) - gpio= PWMLED(17) - gpio.value = 0 + chip = gpiod.Chip('gpiochip0') + + led2 = chip.get_line(LED2_PIN) + led2.request(consumer="LED", type=gpiod.LINE_REQ_DIR_OUT) + + led3 = chip.get_line(LED3_PIN) + led3.request(consumer="LED", type=gpiod.LINE_REQ_DIR_OUT) + + led3.set_value(0) + led3.set_value(0) + for count,led in enumerate(config.LEDS_UUIDS): print(f'Turn on {count} {led}') img = join(output_dir, led + '.jpg') # Measure the time it takes to capture start = time.time() - gpio.value = count/len(config.LEDS_UUIDS) + if count % 2 == 0: + led2.set_value(1) + else : + led3.set_value(1) + capture(img) # For debug purposes #shutil.copyfile(join('data-keep/small', led + '.jpg'), img) - gpio.value = 0 + led2.set_value(0) + led3.set_value(0) delta = time.time() - start @@ -54,5 +70,12 @@ def scan(output_dir: str): if delta < DELAY: time.sleep(DELAY - delta) - print(f'Turn off {count} {led}') + print(f'Turn off {count} {led}') + if count == len(config.LEDS_UUIDS) -1 : + led2.set_value(0) + led3.set_value(0) + led2.release() + led3.release() + yield led +