import os, sys, io import time import M5 from M5 import * from hardware import Pin, I2C from unit import RFIDUnit, Relay4Unit, PAHUBUnit i2c0 = None pahub_0 = None relay4_0 = None rfid_0 = None # --- CONFIGURATION DU BADGE AUTORISÉ --- UID_VALIDE_decimal = 3312376624 def setup(): global i2c0, pahub_0, relay4_0, rfid_0 M5.begin() Widgets.setRotation(1) Widgets.fillScreen(0x222222) i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000) pahub_0 = PAHUBUnit(i2c=i2c0)# Initialisation du PaHUB et des unités relay4_0 = Relay4Unit(PAHUBUnit(i2c=i2c0, channel=0)) # Canal 0 du PaHUB relay4_0.set_relay_state(2, 1)#relai fermé, porte fermée try: print("3. Tentative de liaison avec le module RFID...") rfid_0 = RFIDUnit(PAHUBUnit(i2c=i2c0, channel=1)) # Canal 1 du PaHUB print("--- REUSSITE : Le module RFID est pret ! ---") except Exception as erreur: # Un bip grave si ça plante Speaker.tone(300, 600) print("\n!!! ERREUR DE DETECTION !!!") print("Details de l'erreur :", erreur) def loop(): global i2c0, pahub_0, relay4_0, rfid_0 M5.update() if rfid_0 is not None: try: if rfid_0.is_new_card_present(): uid_scanne = rfid_0.read_card_uid() uid_scanne_decimal = int.from_bytes(uid_scanne[:4], 'big') print("-> Badge trouve ! UID :", uid_scanne) Speaker.tone(2000, 200) # --- VÉRIFICATION DU BADGE ET OUVERTURE PORTE --- except Exception as e: print("Erreur pendant la lecture du badge :", e) time.sleep(0.2) if __name__ == '__main__': try: setup() while True: loop() except (Exception, KeyboardInterrupt) as e: try: from utility import print_error_msg print_error_msg(e) except ImportError: print("please update to latest firmware")