1st leds conversion

This commit is contained in:
Nicolas Bertrand 2024-11-12 15:26:08 +01:00
parent a658be3216
commit 8cfcf1ec55
2 changed files with 32 additions and 10 deletions

View File

@ -2,6 +2,5 @@ Flask
pillow pillow
opencv-python opencv-python
gphoto2 gphoto2
gpiozero
scipy scipy
lgpio lgpio

View File

@ -4,12 +4,14 @@ from os.path import join
import shutil import shutil
import time import time
import gphoto2 as gp import gphoto2 as gp
from gpiozero import PWMLED import gpiod
from . import config from . import config
# Delay between to captures # Delay between to captures
DELAY = 0.5 DELAY = 0.5
LED2_PIN = 17
LED3_PIN = 18
def capture(output_path: str) -> bool: def capture(output_path: str) -> bool:
try: try:
@ -21,32 +23,46 @@ def capture(output_path: str) -> bool:
target =output_path target =output_path
print('Copying image to', target) print('Copying image to', target)
camera_file = camera.file_get( 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_file.save(target)
camera.exit()
s = True s = True
except: except:
print(f'Somethings wrong on gphoto2') print(f'Somethings wrong on gphoto2')
s = False s = False
finally:
camera.exit()
return s return s
def scan(output_dir: str): def scan(output_dir: str):
os.makedirs(output_dir, exist_ok=True) os.makedirs(output_dir, exist_ok=True)
gpio= PWMLED(17) chip = gpiod.Chip('gpiochip0')
gpio.value = 0
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): for count,led in enumerate(config.LEDS_UUIDS):
print(f'Turn on {count} {led}') print(f'Turn on {count} {led}')
img = join(output_dir, led + '.jpg') img = join(output_dir, led + '.jpg')
# Measure the time it takes to capture # Measure the time it takes to capture
start = time.time() 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) capture(img)
# For debug purposes # For debug purposes
#shutil.copyfile(join('data-keep/small', led + '.jpg'), img) #shutil.copyfile(join('data-keep/small', led + '.jpg'), img)
gpio.value = 0 led2.set_value(0)
led3.set_value(0)
delta = time.time() - start delta = time.time() - start
@ -55,4 +71,11 @@ def scan(output_dir: str):
time.sleep(DELAY - delta) 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 yield led