This commit is contained in:
Nicolas Bertrand 2025-09-18 09:44:24 +02:00
parent 7d9360576f
commit 9d40f213be
2 changed files with 49 additions and 47 deletions

View File

@ -14,40 +14,11 @@ def get():
Returns the page showing camera configuration for all parameters in capturesettings and imgsettings, Returns the page showing camera configuration for all parameters in capturesettings and imgsettings,
grouped by section. grouped by section.
""" """
# Load configCamera.json
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
})
import pprint
pprint.pprint(grouped_params)
return render_template( return render_template(
'camera.html', 'camera.html')
grouped_params=grouped_params
)
@blueprint.route('/set', methods=['POST']) @blueprint.route('/set', methods=['POST'])
@ -68,6 +39,8 @@ def camera_feed():
return send_file('static/feed.jpg', mimetype='image/jpeg') return send_file('static/feed.jpg', mimetype='image/jpeg')
@blueprint.route('/config', methods=['GET']) @blueprint.route('/config', methods=['GET'])
def get_camera_config(): def get_camera_config():
""" """
@ -77,27 +50,30 @@ def get_camera_config():
config = json.load(f) config = json.load(f)
grouped_params = [] grouped_params = []
for section in ['capturesettings', 'imgsettings']: # Iterate over all sections in config['main']
for section, settings in config['main'].items():
section_params = [] section_params = []
settings = config['main'].get(section, {}) if isinstance(settings, dict):
for param_name, param in settings.items(): for param_name, param in settings.items():
if 'Choices' in param and isinstance(param['Choices'], list) and param['Choices']: if 'Choices' in param and isinstance(param['Choices'], list) and param['Choices']:
choices = [ choices = [
{'value': c.get('id', idx), 'label': c['label']} {'value': c.get('id', idx), 'label': c['label']}
for idx, c in enumerate(param['Choices']) for idx, c in enumerate(param['Choices'])
] ]
if len(choices) > 1:
section_params.append({ section_params.append({
'name': param_name, 'name': param_name,
'label': param.get('Label', param_name.capitalize()), 'label': param.get('Label', param_name.capitalize()),
'choices': choices, 'choices': choices,
'current': param.get('Current', '') 'current': param.get('Current', ''),
'Type': param.get('Type', 'Text'),
'Readonly': param.get('Readonly', 0)
}) })
if section_params: if section_params:
grouped_params.append({ grouped_params.append({
'section': section, 'section': section,
'params': section_params 'params': section_params
}) })
return jsonify(grouped_params) return jsonify(grouped_params)

View File

@ -10,12 +10,29 @@
<div id="camera-config-container"></div> <div id="camera-config-container"></div>
</div> </div>
<div class="column is-half has-text-centered"> <div class="column is-half has-text-centered">
{#
<figure class="image is-4by3" style="max-width: 480px; margin: auto;"> <figure class="image is-4by3" style="max-width: 480px; margin: auto;">
<img id="camera-preview" src="/camera/feed.jpg?{{ range(1000000)|random }}" alt="Camera Preview" <img id="camera-preview" src="/camera/feed.jpg?{{ range(1000000)|random }}" alt="Camera Preview"
style="border: 1px solid #ccc;"> style="border: 1px solid #ccc;">
</figure> </figure>
#}
<video id="video" controls autoplay></video>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script>
if (Hls.isSupported()) {
var video = document.getElementById('video');
var hls = new Hls({
startPosition: -1
});
hls.loadSource('/static/stream.m3u8');
hls.attachMedia(video);
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = '/static/stream.m3u8';
}
</script>
<nav class="level"> <nav class="level">
<div class="level-item has-text-centered"> <div class="level-item has-text-centered">
<div> <div>
@ -112,6 +129,13 @@
box.innerHTML = `<h2 class="subtitle has-text-weight-bold">${group.section.replace('settings', ' Settings')}</h2>`; box.innerHTML = `<h2 class="subtitle has-text-weight-bold">${group.section.replace('settings', ' Settings')}</h2>`;
group.params.forEach(param => { group.params.forEach(param => {
let field = document.createElement('div'); let field = document.createElement('div');
if (param.type == 'TEXT') {
field.className = 'text';
field.innerHTML = `
<p> ${param.name} </p>
`;
}else {
field.className = 'field'; field.className = 'field';
field.innerHTML = ` field.innerHTML = `
<label class="label" for="${param.name}">${param.label}:</label> <label class="label" for="${param.name}">${param.label}:</label>
@ -130,7 +154,9 @@
<button class="button is-small is-primary" type="button" onclick="setConfig('${param.name}')">Set</button> <button class="button is-small is-primary" type="button" onclick="setConfig('${param.name}')">Set</button>
</div> </div>
`; `;
}
box.appendChild(field); box.appendChild(field);
}); });
container.appendChild(box); container.appendChild(box);
}); });