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 json
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import gpiod
|
||||||
|
|
||||||
from .. import camera as C
|
from .. import camera as C
|
||||||
from .. import leds,config
|
from .. import leds,config
|
||||||
|
|
||||||
blueprint = Blueprint('leds', __name__)
|
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():
|
def _get_gpio_leds():
|
||||||
"""Return a singleton leds controller stored in app.extensions."""
|
"""Return a singleton leds controller stored in app.extensions."""
|
||||||
app = current_app._get_current_object()
|
app = current_app._get_current_object()
|
||||||
|
|
@ -43,6 +40,21 @@ def _register_cleanup(state):
|
||||||
# Routes for object management
|
# 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('/')
|
@blueprint.route('/')
|
||||||
def get():
|
def get():
|
||||||
"""
|
"""
|
||||||
|
|
@ -81,4 +93,7 @@ def set_led():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'status': 'error', 'error': str(e)}), 400
|
return jsonify({'status': 'error', 'error': str(e)}), 400
|
||||||
|
|
||||||
|
|
||||||
|
print(f"Commande reçue pour {led} : {state}")
|
||||||
|
|
||||||
return jsonify({'status': 'ok', 'led': led, 'state': state})
|
return jsonify({'status': 'ok', 'led': led, 'state': state})
|
||||||
Loading…
Reference in New Issue