restructured main
This commit is contained in:
		
							parent
							
								
									29e28b8dca
								
							
						
					
					
						commit
						4c06ea5b60
					
				
					 4 changed files with 49 additions and 30 deletions
				
			
		
							
								
								
									
										
											BIN
										
									
								
								access_control_python/__pycache__/espmega_mqtt.cpython-311.pyc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								access_control_python/__pycache__/espmega_mqtt.cpython-311.pyc
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			@ -20,7 +20,7 @@ class Student(Person):
 | 
			
		|||
class Parent(Person):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
class database:
 | 
			
		||||
class Database:
 | 
			
		||||
    db = None
 | 
			
		||||
    cursor = None
 | 
			
		||||
    def __init__(self) -> None:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue