From de053f043fd670b9ed14d9767b9909835d3d014d Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Mon, 8 Jul 2024 17:32:49 +0200 Subject: [PATCH] Streaming --- app.py | 9 ++++++-- scanner.py | 1 + templates/calibrate.html | 47 ++++++++++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/app.py b/app.py index a6b2943..5ecf9ec 100755 --- a/app.py +++ b/app.py @@ -54,8 +54,13 @@ def preview(id: int): def scan_calibration(id: int): conn = db.get() db.Object.get_from_id(id, conn) - scanner.scan(join(config.DATA_DIR, id, 'calibration')) - return jsonify(config.LEDS_UUIDS) + + def generate(): + length = len(config.LEDS_UUIDS) + for index, led_uuid in enumerate(scanner.scan(join(config.DATA_DIR, id, 'calibration'))): + yield f"{led_uuid},{(index+1)/length}\n" + + return app.response_class(generate(), mimetype='text/plain') @app.route("/calibration/") diff --git a/scanner.py b/scanner.py index 6086c21..d02d867 100644 --- a/scanner.py +++ b/scanner.py @@ -20,3 +20,4 @@ def scan(output_dir: str): img = join(output_dir, led + '.jpg') capture(img) print(f'Turn off {led}') + yield led diff --git a/templates/calibrate.html b/templates/calibrate.html index fb56f98..ffb2f4f 100644 --- a/templates/calibrate.html +++ b/templates/calibrate.html @@ -22,17 +22,22 @@
-
+
+
+
+
{% endblock content %} {% block extrajs %} {% endblock extrajs %}