Add Leds
This commit is contained in:
parent
d75427eac1
commit
e41f0b92d8
|
|
@ -1,7 +1,7 @@
|
|||
from flask import Blueprint, render_template
|
||||
|
||||
from .. import db
|
||||
from . import object, calibration, acquisition, camera
|
||||
from . import object, calibration, acquisition, camera, leds
|
||||
|
||||
blueprint = Blueprint('routes', __name__)
|
||||
|
||||
|
|
@ -21,3 +21,4 @@ blueprint.register_blueprint(object.blueprint, url_prefix='/object')
|
|||
blueprint.register_blueprint(calibration.blueprint, url_prefix='/calibration')
|
||||
blueprint.register_blueprint(acquisition.blueprint, url_prefix='/acquisition')
|
||||
blueprint.register_blueprint(camera.blueprint, url_prefix='/camera')
|
||||
blueprint.register_blueprint(leds.blueprint, url_prefix='/leds')
|
||||
|
|
|
|||
|
|
@ -34,6 +34,14 @@ def set_camera_settings():
|
|||
print(f"Received {key}: {value}")
|
||||
C.set_config(key, value)
|
||||
updated[key] = value
|
||||
|
||||
try:
|
||||
cam = C.get()
|
||||
cam.capture_preview()
|
||||
return jsonify({'status': 'ok'})
|
||||
except C.CameraException as e:
|
||||
return jsonify({'status': 'error', 'error': str(e)}), 500
|
||||
|
||||
return {'status': 'ok', **updated}
|
||||
|
||||
@blueprint.route('/feed.jpg')
|
||||
|
|
@ -48,6 +56,14 @@ def get_camera_config():
|
|||
"""
|
||||
Returns grouped camera parameters as JSON for frontend JS.
|
||||
"""
|
||||
|
||||
try:
|
||||
cam = C.get()
|
||||
cam.config()
|
||||
|
||||
except C.CameraException as e:
|
||||
return jsonify({'status': 'error', 'error': str(e)}), 500
|
||||
|
||||
with open('configCamera.json', 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
from flask import Blueprint, render_template, request, send_file, jsonify
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
from .. import camera as C
|
||||
from .. import leds
|
||||
|
||||
|
||||
blueprint = Blueprint('leds', __name__)
|
||||
|
||||
# Routes for object management
|
||||
|
||||
|
||||
@blueprint.route('/')
|
||||
def get():
|
||||
"""
|
||||
Returns the pages showing all leds.
|
||||
"""
|
||||
|
||||
return render_template(
|
||||
'leds.html')
|
||||
|
||||
@blueprint.route('/set', methods=['POST'])
|
||||
def set_led():
|
||||
"""
|
||||
Reçoit une commande pour allumer ou éteindre une LED.
|
||||
Attend un JSON : { "led": "led1", "state": "on" } ou { "led": "led2", "state": "off" }
|
||||
"""
|
||||
data = request.get_json()
|
||||
led = data.get('led')
|
||||
state = data.get('state')
|
||||
ledId=int(led[3])
|
||||
|
||||
with leds.get() as gpio_leds:
|
||||
print(gpio_leds.leds)
|
||||
gpio_led=gpio_leds.leds[ledId]
|
||||
if state == "on":
|
||||
gpio_led.on()
|
||||
else:
|
||||
gpio_led.off()
|
||||
|
||||
|
||||
print(f"Commande reçue pour {led} : {state}")
|
||||
|
||||
return jsonify({'status': 'ok', 'led': led, 'state': state})
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
.cameraSettings {
|
||||
|
||||
height: 800px;
|
||||
border: 1px solid;
|
||||
overflow: scroll;
|
||||
scrollbar-color: red orange;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
img#preview {
|
||||
width: 640px;
|
||||
height: 480px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
|
||||
.switch-slice {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5em;
|
||||
}
|
||||
.switch-slice label {
|
||||
font-weight: bold;
|
||||
}
|
||||
.switch-slice .switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 50px;
|
||||
height: 24px;
|
||||
}
|
||||
.switch-slice .switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
.switch-slice .slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0; left: 0; right: 0; bottom: 0;
|
||||
background-color: #ccc;
|
||||
transition: .4s;
|
||||
border-radius: 24px;
|
||||
}
|
||||
.switch-slice .slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
left: 3px;
|
||||
bottom: 3px;
|
||||
background-color: white;
|
||||
transition: .4s;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.switch-slice input:checked + .slider {
|
||||
background-color: #48c774;
|
||||
}
|
||||
.switch-slice input:checked + .slider:before {
|
||||
transform: translateX(26px);
|
||||
}
|
||||
|
|
@ -4,7 +4,9 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>NenuScanner</title>
|
||||
|
||||
<link rel="stylesheet" href="/static/bulma.min.css">
|
||||
<link rel="stylesheet" href="/static/custom.css">
|
||||
{% block extracss %}{% endblock extracss %}
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@
|
|||
<form id="camera-config-form">
|
||||
<div class="columns">
|
||||
<div class="column is-half">
|
||||
<div id="camera-config-container"></div>
|
||||
<div class="cameraSettings" id="camera-config-container"></div>
|
||||
</div>
|
||||
<div class="column is-half has-text-centered">
|
||||
<figure class="image is-4by3" style="max-width: 480px; margin: auto;">
|
||||
<img id="camera-preview" src="/static/feed.jpg?{{ range(1000000)|random }}" alt="Camera Preview"
|
||||
<img class="preview" id="camera-preview" src="/static/feed.jpg?{{ range(1000000)|random }}" alt="Camera Preview"
|
||||
style="border: 1px solid #ccc;">
|
||||
</figure>
|
||||
<button class="button is-small is-info mt-2" type="button" onclick="refreshPreview()">Rafraîchir
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
const url = '/static/feed.jpg?' + new Date().getTime();
|
||||
img.src = url;
|
||||
}
|
||||
//setInterval(window.refreshPreview, 1000); // Refresh every second
|
||||
setInterval(window.refreshPreview, 1000); // Refresh every second
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
fetch('/camera/config')
|
||||
|
|
|
|||
Loading…
Reference in New Issue