restructured main

This commit is contained in:
Siwat Sirichai 2023-11-06 16:10:46 +07:00
parent 29e28b8dca
commit 4c06ea5b60
4 changed files with 49 additions and 30 deletions

View File

@ -1,25 +1,20 @@
import paho.mqtt.client as mqtt from espmega_mqtt import ESPMegaMQTT
import espmega_mqtt.ESPMegaMQTT as ESPMegaMQTT from time import sleep
plc = ESPMegaMQTT() class ac:
def __init__(self):
class access_control: self.plc = ESPMegaMQTT()
def __init__(self, serial_port: str):
pass pass
def light_on(self): def light_on(self):
pass self.plc.write_pwm(0,1,4095)
def light_off(self): def light_off(self):
pass self.plc.write_pwm(0,0,4095)
def get_door_state(self) -> bool: def get_door_state(self) -> bool:
pass return self.plc.read_digital(0)
def get_scan_state(self) -> bool: def get_scan_state(self) -> bool:
pass return self.plc.read_digital(1)
def lock_door(self): def lock_door(self):
pass self.plc.write_pwm(1,1,4095)
def unlock_door(self): def unlock_door(self):
pass self.plc.write_pwm(1,0,4095)

View File

@ -20,7 +20,7 @@ class Student(Person):
class Parent(Person): class Parent(Person):
pass pass
class database: class Database:
db = None db = None
cursor = None cursor = None
def __init__(self) -> None: def __init__(self) -> None:

View File

@ -2,17 +2,17 @@ import cv2
import threading import threading
import time import time
import face_processing as fp import face_processing as fp
from access_control import access_control from access_control_mqtt import access_control
from database import database, Student, Parent from database import Database, Student, Parent
from displ from display import Display
SERIAL_PORT_STM32 = "COM12"
SERIAL_PORT_DISPLAY = "COM15" SERIAL_PORT_DISPLAY = "COM15"
CAMERA_INDEX = 0 CAMERA_INDEX = 0
cam = cv2.VideoCapture(CAMERA_INDEX) cam = cv2.VideoCapture(CAMERA_INDEX)
stm32 = access_control(SERIAL_PORT_STM32) actrl = access_control()
display = display = Display(SERIAL_PORT_DISPLAY)
db = Database()
global img global img
global frame_ready global frame_ready
@ -32,13 +32,37 @@ while True:
time.sleep(1) time.sleep(1)
#Try to identify face #Try to identify face
if stm32.get_scan_state(): if actrl.get_scan_state():
print("SCAN ACTIVE!") print("SCAN ACTIVE!")
faces = fp.identify_face(img, target_condidence=0.6) faces = fp.identify_face(img, target_condidence=0.6)
if(len(faces)>0): if(len(faces)==1):
print("Door Unlocked!, Locking in 5 seconds") facefile = faces[0]
stm32.unlock_door() parent_info = db.get_parent_info_file(facefile)
time.sleep(5) if(parent_info!=None):
stm32.lock_door() pass
print("Door Locked!") #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") print("DONE")