1st version with led driver
This commit is contained in:
parent
84a51af78d
commit
80d259e519
|
|
@ -2,16 +2,13 @@ from flask import Blueprint, render_template, request, send_file, jsonify, sessi
|
|||
import json
|
||||
import subprocess
|
||||
|
||||
import gpiod
|
||||
|
||||
from .. import camera as C
|
||||
from .. import leds,config
|
||||
|
||||
blueprint = Blueprint('leds', __name__)
|
||||
|
||||
# WARNING: This is a temporary global variable to hold the state of the GPIO LEDs.
|
||||
# This is necessary because the LED state must persist across multiple requests,
|
||||
# and Flask does not maintain state between requests.
|
||||
# A better solution would be to implement a proper state management system.
|
||||
|
||||
def _get_gpio_leds():
|
||||
"""Return a singleton leds controller stored in app.extensions."""
|
||||
app = current_app._get_current_object()
|
||||
|
|
@ -43,6 +40,21 @@ def _register_cleanup(state):
|
|||
# Routes for object management
|
||||
|
||||
|
||||
# Nom du chip GPIO (sur Raspberry Pi 5, généralement "gpiochip4")
|
||||
CHIP = "gpiochip4"
|
||||
LINE = 14 # Numéro BCM du GPIO (ici GPIO14)
|
||||
|
||||
# Ouvrir le chip
|
||||
chip = gpiod.Chip(CHIP)
|
||||
|
||||
# Demander l’accès à la ligne GPIO14 en sortie
|
||||
line = chip.get_line(LINE)
|
||||
line.request(consumer="Small Led 1", type = gpiod.LINE_REQ_DIR_OUT)
|
||||
|
||||
line.set_value(1)
|
||||
|
||||
# Routes for object management
|
||||
|
||||
@blueprint.route('/')
|
||||
def get():
|
||||
"""
|
||||
|
|
@ -80,5 +92,8 @@ def set_led():
|
|||
gpio_led.off()
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'error', 'error': str(e)}), 400
|
||||
|
||||
|
||||
return jsonify({'status': 'ok', 'led': led, 'state': state})
|
||||
print(f"Commande reçue pour {led} : {state}")
|
||||
|
||||
return jsonify({'status': 'ok', 'led': led, 'state': state})
|
||||
|
|
|
|||
Loading…
Reference in New Issue