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
import espmega_mqtt.ESPMegaMQTT as ESPMegaMQTT
plc = ESPMegaMQTT()
class access_control:
def __init__(self, serial_port: str):
from espmega_mqtt import ESPMegaMQTT
from time import sleep
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)

View File

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

View File

@ -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")