diff --git a/access_control_python/__pycache__/espmega_mqtt.cpython-311.pyc b/access_control_python/__pycache__/espmega_mqtt.cpython-311.pyc new file mode 100644 index 0000000..4520db2 Binary files /dev/null and b/access_control_python/__pycache__/espmega_mqtt.cpython-311.pyc differ diff --git a/access_control_python/access_control_mqtt.py b/access_control_python/access_control_mqtt.py index 0491a3b..7bcd728 100644 --- a/access_control_python/access_control_mqtt.py +++ b/access_control_python/access_control_mqtt.py @@ -1,25 +1,20 @@ -import paho.mqtt.client as mqtt -import espmega_mqtt.ESPMegaMQTT as ESPMegaMQTT +from espmega_mqtt import ESPMegaMQTT +from time import sleep -plc = ESPMegaMQTT() - -class access_control: - def __init__(self, serial_port: str): - +class ac: + def __init__(self): + self.plc = ESPMegaMQTT() pass def light_on(self): - pass + self.plc.write_pwm(0,1,4095) def light_off(self): - pass + self.plc.write_pwm(0,0,4095) def get_door_state(self) -> bool: - pass - + return self.plc.read_digital(0) def get_scan_state(self) -> bool: - pass - + return self.plc.read_digital(1) def lock_door(self): - pass - + self.plc.write_pwm(1,1,4095) def unlock_door(self): - pass + self.plc.write_pwm(1,0,4095) \ No newline at end of file diff --git a/access_control_python/database.py b/access_control_python/database.py index 58f52d2..6ed8620 100644 --- a/access_control_python/database.py +++ b/access_control_python/database.py @@ -20,7 +20,7 @@ class Student(Person): class Parent(Person): pass -class database: +class Database: db = None cursor = None def __init__(self) -> None: diff --git a/access_control_python/main.py b/access_control_python/main.py index c5eae93..4675bab 100644 --- a/access_control_python/main.py +++ b/access_control_python/main.py @@ -2,17 +2,17 @@ import cv2 import threading import time import face_processing as fp -from access_control import access_control -from database import database, Student, Parent -from displ +from access_control_mqtt import access_control +from database import Database, Student, Parent +from display import Display -SERIAL_PORT_STM32 = "COM12" SERIAL_PORT_DISPLAY = "COM15" CAMERA_INDEX = 0 cam = cv2.VideoCapture(CAMERA_INDEX) -stm32 = access_control(SERIAL_PORT_STM32) -display = +actrl = access_control() +display = Display(SERIAL_PORT_DISPLAY) +db = Database() global img global frame_ready @@ -32,13 +32,37 @@ while True: time.sleep(1) #Try to identify face - if stm32.get_scan_state(): + if actrl.get_scan_state(): print("SCAN ACTIVE!") faces = fp.identify_face(img, target_condidence=0.6) - if(len(faces)>0): - print("Door Unlocked!, Locking in 5 seconds") - stm32.unlock_door() - time.sleep(5) - stm32.lock_door() - print("Door Locked!") + if(len(faces)==1): + facefile = faces[0] + parent_info = db.get_parent_info_file(facefile) + if(parent_info!=None): + pass + #Open Door for parent + else: + student_info = db.get_student_info(facefile) + if(student_info!=None): + #is student, request another scan for parent + parent_face = fp.identify_face(img, target_condidence=0.6) + if(len(faces)==1): + parent_info = db.get_parent_info(faces[0]) + if(parent_info!=None): + if(db.check_relationship(student_info,parent_info)): + #Student is under parent, open door. + pass + else: + #Wrong Parent, retry. + pass + else: + #Not a parent, retry + pass + + elif (len(faces)>1): + #More than one people, error. + pass + else: + #No one detected + pass print("DONE")