diff --git a/src/nenuscanner/routes/camera.py b/src/nenuscanner/routes/camera.py index 106e81f..c9c0f19 100644 --- a/src/nenuscanner/routes/camera.py +++ b/src/nenuscanner/routes/camera.py @@ -1,4 +1,4 @@ -from flask import Blueprint, render_template, request, redirect +from flask import Blueprint, render_template, request, send_file, jsonify import json from .. import camera as C @@ -11,61 +11,93 @@ blueprint = Blueprint('camera', __name__) @blueprint.route('/') def get(): """ - Returns the page showing camera configuration + Returns the page showing camera configuration for all parameters in capturesettings and imgsettings, + grouped by section. """ # Load configCamera.json with open('configCamera.json', 'r') as f: config = json.load(f) - # Extract shutterspeed choices and current value - shutterspeed = config['main']['capturesettings']['shutterspeed'] - shutterspeed_choices = [ - {'value': c.get('id', idx), 'label': c['label']} - for idx, c in enumerate(shutterspeed['Choices']) - ] - shutterspeed_current = shutterspeed['Current'] - - # Extract aperture choices and current value - aperture = config['main']['capturesettings']['aperture'] - aperture_choices = [ - {'value': c.get('id', idx), 'label': c['label']} - for idx, c in enumerate(aperture['Choices']) - ] - aperture_current = aperture['Current'] + grouped_params = [] + for section in ['capturesettings', 'imgsettings']: + section_params = [] + settings = config['main'].get(section, {}) + for param_name, param in settings.items(): + if 'Choices' in param and isinstance(param['Choices'], list) and param['Choices']: + choices = [ + {'value': c.get('id', idx), 'label': c['label']} + for idx, c in enumerate(param['Choices']) + ] + if len(choices) > 1: + section_params.append({ + 'name': param_name, + 'label': param.get('Label', param_name.capitalize()), + 'choices': choices, + 'current': param.get('Current', '') + }) + if section_params: + grouped_params.append({ + 'section': section, + 'params': section_params + }) + import pprint + pprint.pprint(grouped_params) + return render_template( 'camera.html', - shutterspeed_choices=shutterspeed_choices, - shutterspeed_current=shutterspeed_current, - aperture_choices=aperture_choices, - aperture_current=aperture_current + grouped_params=grouped_params ) @blueprint.route('/set', methods=['POST']) def set_camera_settings(): """ - Receives and processes new camera settings (shutterspeed, aperture) from the client. + Receives and processes new camera settings for all parameters from the client. """ data = request.get_json() - shutterspeed = data.get('shutterspeed') - aperture = data.get('aperture') - - if shutterspeed is not None: - print(f"Received shutterspeed: {shutterspeed}") - C.set_config('shutterspeed', shutterspeed) - - if aperture is not None: - print(f"Received aperture: {aperture}") - C.set_config('aperture', aperture) - - return {'status': 'ok', 'shutterspeed': shutterspeed, 'aperture': aperture} - - - -# filepath: /home/nicolas/dev/git/git.polymny.net/source/nenuscanner/src/nenuscanner/routes/camera.py -from flask import send_file + updated = {} + for key, value in data.items(): + print(f"Received {key}: {value}") + C.set_config(key, value) + updated[key] = value + return {'status': 'ok', **updated} @blueprint.route('/feed.jpg') def camera_feed(): return send_file('static/feed.jpg', mimetype='image/jpeg') + + +@blueprint.route('/config', methods=['GET']) +def get_camera_config(): + """ + Returns grouped camera parameters as JSON for frontend JS. + """ + with open('configCamera.json', 'r') as f: + config = json.load(f) + + grouped_params = [] + for section in ['capturesettings', 'imgsettings']: + section_params = [] + settings = config['main'].get(section, {}) + for param_name, param in settings.items(): + if 'Choices' in param and isinstance(param['Choices'], list) and param['Choices']: + choices = [ + {'value': c.get('id', idx), 'label': c['label']} + for idx, c in enumerate(param['Choices']) + ] + if len(choices) > 1: + section_params.append({ + 'name': param_name, + 'label': param.get('Label', param_name.capitalize()), + 'choices': choices, + 'current': param.get('Current', '') + }) + if section_params: + grouped_params.append({ + 'section': section, + 'params': section_params + }) + + return jsonify(grouped_params) + diff --git a/src/nenuscanner/templates/camera.html b/src/nenuscanner/templates/camera.html index 9e8a02c..fa1da3a 100644 --- a/src/nenuscanner/templates/camera.html +++ b/src/nenuscanner/templates/camera.html @@ -3,54 +3,37 @@ {% block content %}
-

Configurer la camera

- -
-
- -
-
- -
+

Configurer la camera

+
-
-
- -
-
- + {% for group in grouped_params %} +
+

+ {{ group.section | replace('settings', ' Settings') | capitalize }} +

+ {% for param in group.params %} +
+ +
+
+ +
+
+
+
-
- -
-
-
- -
-
- -
-
-
- -
+ {% endfor %}
+ {% endfor %}
-
Camera Preview @@ -65,42 +48,27 @@ {% block extrajs %} {% endblock extrajs %} \ No newline at end of file