diff --git a/routes/acquisition.py b/routes/acquisition.py index 8896f0c..029d065 100644 --- a/routes/acquisition.py +++ b/routes/acquisition.py @@ -48,9 +48,8 @@ def run(object_id: int): def generate(): yield str(acquisition.id) - length = len(config.LEDS_UUIDS) + 2 # with all_on and all_off - for index, led_uuid in enumerate(scanner.scan(join(config.OBJECT_DIR, str(object.id), str(acquisition.id)))): - yield f"{led_uuid},{(index+1)/length}\n" + for value in scanner.scan(join(config.OBJECT_DIR, str(object.id), str(acquisition.id))): + yield value return Response(generate(), mimetype='text/plain') @@ -74,9 +73,8 @@ def rescan(acquisition_id: int): object = acquisition.object(conn) def generate(): - length = len(config.LEDS_UUIDS) + 2 # with all_on and all_off - for index, led_uuid in enumerate(scanner.scan(join(config.OBJECT_DIR, str(object.id), str(acquisition.id)))): - yield f"{led_uuid},{(index+1)/length}\n" + for value in scanner.scan(join(config.OBJECT_DIR, str(object.id), str(acquisition.id))): + yield value return Response(generate(), mimetype='text/plain') diff --git a/routes/calibration.py b/routes/calibration.py index 5c817c4..35b56ec 100644 --- a/routes/calibration.py +++ b/routes/calibration.py @@ -56,9 +56,8 @@ def scan(): calibration = utils.get_calibration(conn) def generate(): - length = len(config.LEDS_UUIDS) - for index, led_uuid in enumerate(scanner.scan(join(config.CALIBRATION_DIR, calibration_id), False)): - yield f"{led_uuid},{(index+1)/length}\n" + for value in scanner.scan(join(config.CALIBRATION_DIR, calibration_id), False): + yield value with conn: calibration.state = db.CalibrationState.HasData diff --git a/scanner.py b/scanner.py index b221deb..9cc87cf 100644 --- a/scanner.py +++ b/scanner.py @@ -35,6 +35,8 @@ def scan(output_dir: str, on_and_off: bool = True): os.makedirs(output_dir, exist_ok=True) file_paths = [] + length = len(config.LEDS_UUIDS) + (2 if on_and_off else 0) + with camera.get() as cam: with leds.get() as gpio_leds: for count, led in enumerate(gpio_leds.leds): @@ -46,15 +48,23 @@ def scan(output_dir: str, on_and_off: bool = True): print(f'Turn off {led}') + ratio = (count + 1) / (2 * length) + yield f'{{ "status": "captured", "id": "{led}", "ratio": {ratio:.3} }}\n' + # capture with all leds ON OFF if on_and_off: gpio_leds.on() file_paths.append(('all_on', delay_capture(cam))) + ratio = (length - 1) / (2 * length) + yield f'{{ "status": "captured", "id": "all_on", "ratio": {ratio:.3} }}\n' gpio_leds.off() file_paths.append(('all_off', delay_capture(cam))) + ratio = 0.5 + yield f'{{ "status": "captured", "id": "all_off", "ratio": {ratio:.3} }}\n' with camera.get() as cam: - for target, source in file_paths: + for count, (target, source) in enumerate(file_paths): delay_save(cam, source, join(output_dir, target)) - yield target + ratio = 0.5 + (count + 1) / (2 * length) + yield f'{{ "status": "ready", "id": "{target}", "ratio": {ratio:.3} }}\n' diff --git a/templates/calibrate.html b/templates/calibrate.html index cefc74e..b8cf3b5 100644 --- a/templates/calibrate.html +++ b/templates/calibrate.html @@ -86,15 +86,20 @@ break; } - let [ uuid, ratio ] = value.trim().split(','); + console.log(value); + let { status, id, ratio } = JSON.parse(value); + console.log(status, id, ratio); progress = Math.ceil(1000 * parseFloat(ratio)); - let cell = document.createElement('div'); - cell.classList.add('cell'); - let img = document.createElement('img'); - img.classList.add('is-loading'); - img.src = '/data/calibrations/{{ calibration.id }}/' + uuid + '.jpg?v=' + scanIndex; - cell.appendChild(img); - grid.appendChild(cell); + + if (status === "ready") { + let cell = document.createElement('div'); + cell.classList.add('cell'); + let img = document.createElement('img'); + img.classList.add('is-loading'); + img.src = '/data/calibrations/{{ calibration.id }}/' + id + '.jpg?v=' + scanIndex; + cell.appendChild(img); + grid.appendChild(cell); + } } }); diff --git a/templates/scan.html b/templates/scan.html index 27d70ea..706af5c 100644 --- a/templates/scan.html +++ b/templates/scan.html @@ -156,15 +156,18 @@ continue; } - let [ uuid, ratio ] = value.trim().split(','); + let { status, id, ratio } = JSON.parse(value); progress = Math.ceil(1000 * parseFloat(ratio)); - let cell = document.createElement('div'); - cell.classList.add('cell'); - let img = document.createElement('img'); - img.classList.add('is-loading'); - img.src = '/data/objects/{{ object.id }}/' + acquisitionId + '/' + uuid + '.jpg?v=' + scanIndex; - cell.appendChild(img); - grid.appendChild(cell); + + if (status === "ready") { + let cell = document.createElement('div'); + cell.classList.add('cell'); + let img = document.createElement('img'); + img.classList.add('is-loading'); + img.src = '/data/objects/{{ object.id }}/' + acquisitionId + '/' + id + '.jpg?v=' + scanIndex; + cell.appendChild(img); + grid.appendChild(cell); + } } });