piou
This commit is contained in:
@@ -3,11 +3,9 @@ import RPi.GPIO as GPIO
|
|||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
# ── Numérotation BCM ────────────────────────────────────────────────────────
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setwarnings(False)
|
GPIO.setwarnings(False)
|
||||||
|
|
||||||
# ── Broches ─────────────────────────────────────────────────────────────────
|
|
||||||
PIN_LED_R = 17
|
PIN_LED_R = 17
|
||||||
PIN_LED_G = 22
|
PIN_LED_G = 22
|
||||||
PIN_LED_B = 27
|
PIN_LED_B = 27
|
||||||
@@ -25,10 +23,8 @@ KEYPAD_MAP = [
|
|||||||
['*', '0', '#', 'D'],
|
['*', '0', '#', 'D'],
|
||||||
]
|
]
|
||||||
|
|
||||||
# ── Code secret (modifiable ici) ─────────────────────────────────────────────
|
|
||||||
CODE_SECRET = "1234"
|
CODE_SECRET = "1234"
|
||||||
|
|
||||||
# ── Configuration GPIO ───────────────────────────────────────────────────────
|
|
||||||
GPIO.setup(PIN_LED_R, GPIO.OUT, initial=GPIO.LOW)
|
GPIO.setup(PIN_LED_R, GPIO.OUT, initial=GPIO.LOW)
|
||||||
GPIO.setup(PIN_LED_G, GPIO.OUT, initial=GPIO.LOW)
|
GPIO.setup(PIN_LED_G, GPIO.OUT, initial=GPIO.LOW)
|
||||||
GPIO.setup(PIN_LED_B, GPIO.OUT, initial=GPIO.LOW)
|
GPIO.setup(PIN_LED_B, GPIO.OUT, initial=GPIO.LOW)
|
||||||
@@ -40,7 +36,6 @@ for row in ROWS:
|
|||||||
for col in COLS:
|
for col in COLS:
|
||||||
GPIO.setup(col, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
GPIO.setup(col, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
|
||||||
# ── État global ──────────────────────────────────────────────────────────────
|
|
||||||
etat = "desarmee"
|
etat = "desarmee"
|
||||||
etat_lock = threading.Lock()
|
etat_lock = threading.Lock()
|
||||||
|
|
||||||
@@ -48,10 +43,6 @@ _stop_buzzer = threading.Event()
|
|||||||
_thread_buzzer = None
|
_thread_buzzer = None
|
||||||
|
|
||||||
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
# LED RGB
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
|
|
||||||
def led(r=False, g=False, b=False):
|
def led(r=False, g=False, b=False):
|
||||||
"""Allume la LED RGB avec la couleur voulue."""
|
"""Allume la LED RGB avec la couleur voulue."""
|
||||||
GPIO.output(PIN_LED_R, GPIO.HIGH if r else GPIO.LOW)
|
GPIO.output(PIN_LED_R, GPIO.HIGH if r else GPIO.LOW)
|
||||||
@@ -63,11 +54,6 @@ def led_vert(): led(g=True)
|
|||||||
def led_rouge(): led(r=True)
|
def led_rouge(): led(r=True)
|
||||||
def led_off(): led()
|
def led_off(): led()
|
||||||
|
|
||||||
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
# Buzzer
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
|
|
||||||
def bip(nb=1, duree=0.08, pause=0.12):
|
def bip(nb=1, duree=0.08, pause=0.12):
|
||||||
"""Émet nb bip(s) courts."""
|
"""Émet nb bip(s) courts."""
|
||||||
for _ in range(nb):
|
for _ in range(nb):
|
||||||
@@ -86,10 +72,6 @@ def _buzzer_continu(stop_event: threading.Event):
|
|||||||
GPIO.output(PIN_BUZZER, GPIO.LOW)
|
GPIO.output(PIN_BUZZER, GPIO.LOW)
|
||||||
|
|
||||||
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
# Keypad 4x4
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
|
|
||||||
def lire_touche():
|
def lire_touche():
|
||||||
"""
|
"""
|
||||||
Scan matriciel : met chaque ligne à LOW tour à tour
|
Scan matriciel : met chaque ligne à LOW tour à tour
|
||||||
@@ -128,10 +110,6 @@ def lire_code(nb_chiffres=4, timeout=30):
|
|||||||
return saisi
|
return saisi
|
||||||
|
|
||||||
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
# Transitions d'état
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
|
|
||||||
def passer_en_desarmee():
|
def passer_en_desarmee():
|
||||||
global etat, _thread_buzzer
|
global etat, _thread_buzzer
|
||||||
_stop_buzzer.set()
|
_stop_buzzer.set()
|
||||||
@@ -163,10 +141,6 @@ def passer_en_declenchee():
|
|||||||
_thread_buzzer.start()
|
_thread_buzzer.start()
|
||||||
|
|
||||||
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
# Thread : surveillance PIR
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
|
|
||||||
def _surveiller_pir(stop_evt: threading.Event):
|
def _surveiller_pir(stop_evt: threading.Event):
|
||||||
"""Lit le PIR toutes les 100 ms. Déclenche si mouvement et armée."""
|
"""Lit le PIR toutes les 100 ms. Déclenche si mouvement et armée."""
|
||||||
print("[PIR] Surveillance démarrée")
|
print("[PIR] Surveillance démarrée")
|
||||||
@@ -179,10 +153,6 @@ def _surveiller_pir(stop_evt: threading.Event):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
# Boucle principale
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
|
|
||||||
def boucle_principale():
|
def boucle_principale():
|
||||||
global etat
|
global etat
|
||||||
|
|
||||||
@@ -204,7 +174,6 @@ def boucle_principale():
|
|||||||
with etat_lock:
|
with etat_lock:
|
||||||
etat_local = etat
|
etat_local = etat
|
||||||
|
|
||||||
# ── DÉSARMÉE : attente d'un code pour armer ──────────────────────
|
|
||||||
if etat_local == "desarmee":
|
if etat_local == "desarmee":
|
||||||
print(" → Saisir le code pour ARMER :")
|
print(" → Saisir le code pour ARMER :")
|
||||||
code = lire_code(nb_chiffres=len(CODE_SECRET))
|
code = lire_code(nb_chiffres=len(CODE_SECRET))
|
||||||
@@ -215,11 +184,9 @@ def boucle_principale():
|
|||||||
print(" ✘ Code incorrect")
|
print(" ✘ Code incorrect")
|
||||||
bip(nb=1, duree=0.4) # 1 bip long = erreur
|
bip(nb=1, duree=0.4) # 1 bip long = erreur
|
||||||
|
|
||||||
# ── ARMÉE : le thread PIR gère le déclenchement ──────────────────
|
|
||||||
elif etat_local == "armee":
|
elif etat_local == "armee":
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
# ── DÉCLENCHÉE : attente du code pour désarmer ───────────────────
|
|
||||||
elif etat_local == "declenchee":
|
elif etat_local == "declenchee":
|
||||||
print(" → Saisir le code pour DÉSARMER :")
|
print(" → Saisir le code pour DÉSARMER :")
|
||||||
code = lire_code(nb_chiffres=len(CODE_SECRET))
|
code = lire_code(nb_chiffres=len(CODE_SECRET))
|
||||||
@@ -238,6 +205,3 @@ def boucle_principale():
|
|||||||
led_off()
|
led_off()
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
print("[INFO] GPIO libérés. Fin du programme.")
|
print("[INFO] GPIO libérés. Fin du programme.")
|
||||||
|
|
||||||
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
|
||||||
|
|||||||
@@ -140,14 +140,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// 1. Écoute de la touche Entrée
|
|
||||||
["username", "password"].forEach(id => {
|
["username", "password"].forEach(id => {
|
||||||
document.getElementById(id).addEventListener("keydown", e => {
|
document.getElementById(id).addEventListener("keydown", e => {
|
||||||
if (e.key === "Enter") handleLogin();
|
if (e.key === "Enter") handleLogin();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. Fonction de connexion manuelle (Mot de passe)
|
|
||||||
async function handleLogin() {
|
async function handleLogin() {
|
||||||
const username = document.getElementById("username").value.trim();
|
const username = document.getElementById("username").value.trim();
|
||||||
const password = document.getElementById("password").value;
|
const password = document.getElementById("password").value;
|
||||||
@@ -190,7 +188,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Écoute automatique du badge (RFID) - SORTI DE LA FONCTION !
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
// Attention : Vérifie que cette route correspond bien à celle dans main.py
|
// Attention : Vérifie que cette route correspond bien à celle dans main.py
|
||||||
|
|||||||
Reference in New Issue
Block a user