almost finish main
This commit is contained in:
		
							parent
							
								
									185ced388b
								
							
						
					
					
						commit
						0bf91c38a8
					
				
					 13 changed files with 289 additions and 125 deletions
				
			
		
							
								
								
									
										18
									
								
								access_control_python/.vscode/c_cpp_properties.json
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								access_control_python/.vscode/c_cpp_properties.json
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,18 @@
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "configurations": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "windows-gcc-x64",
 | 
				
			||||||
 | 
					      "includePath": [
 | 
				
			||||||
 | 
					        "${workspaceFolder}/**"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "compilerPath": "gcc",
 | 
				
			||||||
 | 
					      "cStandard": "${default}",
 | 
				
			||||||
 | 
					      "cppStandard": "${default}",
 | 
				
			||||||
 | 
					      "intelliSenseMode": "windows-gcc-x64",
 | 
				
			||||||
 | 
					      "compilerArgs": [
 | 
				
			||||||
 | 
					        ""
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "version": 4
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										24
									
								
								access_control_python/.vscode/launch.json
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								access_control_python/.vscode/launch.json
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "version": "0.2.0",
 | 
				
			||||||
 | 
					  "configurations": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "C/C++ Runner: Debug Session",
 | 
				
			||||||
 | 
					      "type": "cppdbg",
 | 
				
			||||||
 | 
					      "request": "launch",
 | 
				
			||||||
 | 
					      "args": [],
 | 
				
			||||||
 | 
					      "stopAtEntry": false,
 | 
				
			||||||
 | 
					      "externalConsole": true,
 | 
				
			||||||
 | 
					      "cwd": "c:/Users/siwat/Desktop/src",
 | 
				
			||||||
 | 
					      "program": "c:/Users/siwat/Desktop/src/build/Debug/outDebug",
 | 
				
			||||||
 | 
					      "MIMode": "gdb",
 | 
				
			||||||
 | 
					      "miDebuggerPath": "gdb",
 | 
				
			||||||
 | 
					      "setupCommands": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          "description": "Enable pretty-printing for gdb",
 | 
				
			||||||
 | 
					          "text": "-enable-pretty-printing",
 | 
				
			||||||
 | 
					          "ignoreFailures": true
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										59
									
								
								access_control_python/.vscode/settings.json
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								access_control_python/.vscode/settings.json
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,59 @@
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.cCompilerPath": "gcc",
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.cppCompilerPath": "g++",
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.debuggerPath": "gdb",
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.cStandard": "",
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.cppStandard": "",
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.msvcBatchPath": "",
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.useMsvc": false,
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.warnings": [
 | 
				
			||||||
 | 
					    "-Wall",
 | 
				
			||||||
 | 
					    "-Wextra",
 | 
				
			||||||
 | 
					    "-Wpedantic",
 | 
				
			||||||
 | 
					    "-Wshadow",
 | 
				
			||||||
 | 
					    "-Wformat=2",
 | 
				
			||||||
 | 
					    "-Wcast-align",
 | 
				
			||||||
 | 
					    "-Wconversion",
 | 
				
			||||||
 | 
					    "-Wsign-conversion",
 | 
				
			||||||
 | 
					    "-Wnull-dereference"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.msvcWarnings": [
 | 
				
			||||||
 | 
					    "/W4",
 | 
				
			||||||
 | 
					    "/permissive-",
 | 
				
			||||||
 | 
					    "/w14242",
 | 
				
			||||||
 | 
					    "/w14287",
 | 
				
			||||||
 | 
					    "/w14296",
 | 
				
			||||||
 | 
					    "/w14311",
 | 
				
			||||||
 | 
					    "/w14826",
 | 
				
			||||||
 | 
					    "/w44062",
 | 
				
			||||||
 | 
					    "/w44242",
 | 
				
			||||||
 | 
					    "/w14905",
 | 
				
			||||||
 | 
					    "/w14906",
 | 
				
			||||||
 | 
					    "/w14263",
 | 
				
			||||||
 | 
					    "/w44265",
 | 
				
			||||||
 | 
					    "/w14928"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.enableWarnings": true,
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.warningsAsError": false,
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.compilerArgs": [],
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.linkerArgs": [],
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.includePaths": [],
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.includeSearch": [
 | 
				
			||||||
 | 
					    "*",
 | 
				
			||||||
 | 
					    "**/*"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.excludeSearch": [
 | 
				
			||||||
 | 
					    "**/build",
 | 
				
			||||||
 | 
					    "**/build/**",
 | 
				
			||||||
 | 
					    "**/.*",
 | 
				
			||||||
 | 
					    "**/.*/**",
 | 
				
			||||||
 | 
					    "**/.vscode",
 | 
				
			||||||
 | 
					    "**/.vscode/**"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.useAddressSanitizer": false,
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.useUndefinedSanitizer": false,
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.useLeakSanitizer": false,
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.showCompilationTime": false,
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.useLinkTimeOptimization": false,
 | 
				
			||||||
 | 
					  "C_Cpp_Runner.msvcSecureNoWarnings": false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -3,50 +3,66 @@ from time import sleep, perf_counter
 | 
				
			||||||
from time import sleep as delay
 | 
					from time import sleep as delay
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class access_control:
 | 
					class access_control:
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    This class provides methods to control access to a door using an ESPMega board.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self):
 | 
					    def __init__(self):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Initializes an instance of the access_control class.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
        self.plc = ESPMega("/facescan","192.168.0.239",1883)
 | 
					        self.plc = ESPMega("/facescan","192.168.0.239",1883)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    # def light_on(self):
 | 
					 | 
				
			||||||
    #     self.plc.analog_write(0,1,4095)
 | 
					 | 
				
			||||||
    # def light_off(self):
 | 
					 | 
				
			||||||
    #     self.plc.analog_write(0,0,4095)
 | 
					 | 
				
			||||||
    # def get_door_state(self) -> bool:
 | 
					 | 
				
			||||||
    #     return self.plc.digital_read(0)
 | 
					 | 
				
			||||||
    # def get_scan_state(self) -> bool:
 | 
					 | 
				
			||||||
    #     return self.plc.digital_read(1)
 | 
					 | 
				
			||||||
    # def lock_door(self):
 | 
					 | 
				
			||||||
    #     if(self.get_door_state()):
 | 
					 | 
				
			||||||
    #       self.plc.analog_write(1,1,4095)  
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
    # def unlock_door(self):
 | 
					 | 
				
			||||||
    #     self.plc.analog_write(1,0,4095)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def get_scan_state(self) -> bool:
 | 
					    def get_scan_state(self) -> bool:
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Returns the state of the scan sensor.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Returns:
 | 
				
			||||||
 | 
					        bool: True if the scan sensor is active, False otherwise.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
        return self.plc.digital_read(1)
 | 
					        return self.plc.digital_read(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def lock_door(self): #if door close, lock the door.
 | 
					    def lock_door(self):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Locks the door if it is closed.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
        if(self.plc.digital_read(0)):
 | 
					        if(self.plc.digital_read(0)):
 | 
				
			||||||
            self.plc.digital_write(0,0)
 | 
					            self.plc.digital_write(0,0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					    def unlock_door(self):
 | 
				
			||||||
    def unlock_door(self): #if door close, unlock the door.
 | 
					        """
 | 
				
			||||||
 | 
					        Unlocks the door if it is closed.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
        if(self.plc.digital_read(0)):
 | 
					        if(self.plc.digital_read(0)):
 | 
				
			||||||
            self.plc.digital_write(0,1)
 | 
					            self.plc.digital_write(0,1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_door_state(self) -> bool:
 | 
					    def get_door_state(self) -> bool:
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Returns the state of the door.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Returns:
 | 
				
			||||||
 | 
					        bool: True if the door is closed, False otherwise.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
        return self.plc.digital_read(0)
 | 
					        return self.plc.digital_read(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def activate_alarm(self):
 | 
					    # def activate_alarm(self):
 | 
				
			||||||
        self.plc.digital_write(1,1)
 | 
					    #     """
 | 
				
			||||||
 | 
					    #     Activates the alarm.
 | 
				
			||||||
 | 
					    #     """
 | 
				
			||||||
 | 
					    #     self.plc.digital_write(2,1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def activate_LED_alarm(self):
 | 
					    def activate_alarm(self):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Activates the LED alarm.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        self.plc.digital_write(2,1)
 | 
				
			||||||
        while(True):
 | 
					        while(True):
 | 
				
			||||||
            self.plc.digital_write(1,round((perf_counter()*2)%1))
 | 
					            self.plc.digital_write(1,round((perf_counter()*2)%1))
 | 
				
			||||||
            print(round((perf_counter()*2)%1))
 | 
					            print(round((perf_counter()*2)%1))
 | 
				
			||||||
            delay(0.1)
 | 
					            delay(0.3)
 | 
				
			||||||
            if self.get_door_state():
 | 
					            if self.get_door_state():
 | 
				
			||||||
                self.lock_door()
 | 
					                self.lock_door()
 | 
				
			||||||
 | 
					                self.plc.digital_write(1,0)
 | 
				
			||||||
 | 
					                self.plc.digital_write(2,0)
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
							
								
								
									
										7
									
								
								access_control_python/import time.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								access_control_python/import time.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					import time
 | 
				
			||||||
 | 
					from time import perf_counter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					time_count = time.perf_counter()
 | 
				
			||||||
 | 
					endtime = time_count + 10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					while (time_count < endtime):
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import cv2
 | 
					import cv2
 | 
				
			||||||
import threading
 | 
					import threading
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
| 
						 | 
					@ -16,6 +17,7 @@ db = Database()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
global img
 | 
					global img
 | 
				
			||||||
global frame_ready
 | 
					global frame_ready
 | 
				
			||||||
 | 
					
 | 
				
			||||||
frame_ready = False
 | 
					frame_ready = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def read_webcam():
 | 
					def read_webcam():
 | 
				
			||||||
| 
						 | 
					@ -37,6 +39,38 @@ faces = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
threading.Thread(target=read_webcam).start()
 | 
					threading.Thread(target=read_webcam).start()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def door_open():
 | 
				
			||||||
 | 
					    actrl.unlock_door()
 | 
				
			||||||
 | 
					    for i in range(10):
 | 
				
			||||||
 | 
					        display.set_string("msg.txt",f'Door will close in {10-i}')
 | 
				
			||||||
 | 
					        time.sleep(1)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    i = 5
 | 
				
			||||||
 | 
					    #TODO Check if door close, lock
 | 
				
			||||||
 | 
					    alarm_active: bool = False
 | 
				
			||||||
 | 
					    display.set_page("leftopen")
 | 
				
			||||||
 | 
					    while(i>=0):
 | 
				
			||||||
 | 
					        if (not actrl.get_door_state() and not alarm_active): # False door is left open
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            display.set_string("msg.txt","Door is left open, Alram in {} sec".format(i))
 | 
				
			||||||
 | 
					            time.sleep(1)
 | 
				
			||||||
 | 
					            i -= 1
 | 
				
			||||||
 | 
					            if i == 0:
 | 
				
			||||||
 | 
					                actrl.activate_alarm()
 | 
				
			||||||
 | 
					                display.set_string("msg.txt","Alarm Active, Please Close Door.")
 | 
				
			||||||
 | 
					                #actrl.activate_LED_alarm()
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					        elif(actrl.get_door_state()):
 | 
				
			||||||
 | 
					            actrl.lock_door()
 | 
				
			||||||
 | 
					            display.set_page("scan")
 | 
				
			||||||
 | 
					            should_restart = True
 | 
				
			||||||
 | 
					            break
 | 
				
			||||||
 | 
					        #display.set_page("scan")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while True:
 | 
					while True:
 | 
				
			||||||
    while not frame_ready:
 | 
					    while not frame_ready:
 | 
				
			||||||
        time.sleep(1)
 | 
					        time.sleep(1)
 | 
				
			||||||
| 
						 | 
					@ -57,11 +91,13 @@ while True:
 | 
				
			||||||
                facefile = faces[0]['name'] ## File name
 | 
					                facefile = faces[0]['name'] ## File name
 | 
				
			||||||
                print(facefile)
 | 
					                print(facefile)
 | 
				
			||||||
                student_info = db.get_student_info(facefile)## Check is it student?
 | 
					                student_info = db.get_student_info(facefile)## Check is it student?
 | 
				
			||||||
 | 
					                parent_info = db.get_parent_info(facefile)
 | 
				
			||||||
                if(student_info!=None): #is student, request another scan for parent
 | 
					                if(student_info!=None): #is student, request another scan for parent
 | 
				
			||||||
                    print("Find student info")
 | 
					                    print("Find student info")
 | 
				
			||||||
                    #db.log_access_student_file()
 | 
					                    #db.log_access_student_file()
 | 
				
			||||||
 | 
					                    parent_info = None
 | 
				
			||||||
                    display.set_page("student")
 | 
					                    display.set_page("student")
 | 
				
			||||||
                    display.set_string("msg.txt","Scan parent face")
 | 
					                    #display.set_string("msg.txt",f'Scan parent face ({10-i})')
 | 
				
			||||||
                    display.set_string("name_std.txt", f'Name: {student_info.name}')
 | 
					                    display.set_string("name_std.txt", f'Name: {student_info.name}')
 | 
				
			||||||
                    display.set_string("surname_std.txt",f'Surname: {student_info.surname}')
 | 
					                    display.set_string("surname_std.txt",f'Surname: {student_info.surname}')
 | 
				
			||||||
                    display.set_string("id_std.txt", f'ID: {str(student_info.id)}')
 | 
					                    display.set_string("id_std.txt", f'ID: {str(student_info.id)}')
 | 
				
			||||||
| 
						 | 
					@ -70,18 +106,16 @@ while True:
 | 
				
			||||||
                    parent_info = db.get_parent_info(parent_face)"""
 | 
					                    parent_info = db.get_parent_info(parent_face)"""
 | 
				
			||||||
                    #DONE TODO Fill in student info Resolve
 | 
					                    #DONE TODO Fill in student info Resolve
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    time.sleep(1)
 | 
					 | 
				
			||||||
                    print(student_info)
 | 
					                    print(student_info)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    i = 0
 | 
					                    i = 0
 | 
				
			||||||
                    while(i <= 10):
 | 
					                    start_time = time.perf_counter()
 | 
				
			||||||
 | 
					                    while(time.perf_counter()-start_time < 10):
 | 
				
			||||||
                        parent_face = fp.identify_face(img, target_condidence=0.6)
 | 
					                        parent_face = fp.identify_face(img, target_condidence=0.6)
 | 
				
			||||||
                        
 | 
					                        
 | 
				
			||||||
                        if (len(parent_face)!= 0):
 | 
					                        if (len(parent_face)!= 0):
 | 
				
			||||||
                            parent_facefile = parent_face[0]['name']   
 | 
					                            parent_facefile = parent_face[0]['name']   
 | 
				
			||||||
                            parent_info = db.get_parent_info(parent_facefile)
 | 
					                            parent_info = db.get_parent_info(parent_facefile)
 | 
				
			||||||
                            print(i)
 | 
					 | 
				
			||||||
                            i += 1
 | 
					 | 
				
			||||||
                            if(parent_info != None): # Identified parent
 | 
					                            if(parent_info != None): # Identified parent
 | 
				
			||||||
                                if(db.check_relationship(student_info,parent_info)): # Check if the detected parent is right for the detected student.
 | 
					                                if(db.check_relationship(student_info,parent_info)): # Check if the detected parent is right for the detected student.
 | 
				
			||||||
                                    print("Relation is OKAY")
 | 
					                                    print("Relation is OKAY")
 | 
				
			||||||
| 
						 | 
					@ -95,6 +129,8 @@ while True:
 | 
				
			||||||
                                    actrl.unlock_door() # Door open
 | 
					                                    actrl.unlock_door() # Door open
 | 
				
			||||||
                                    display.set_string("msg.txt","Get your kid")
 | 
					                                    display.set_string("msg.txt","Get your kid")
 | 
				
			||||||
                                    #DONE TODO Send timer to display
 | 
					                                    #DONE TODO Send timer to display
 | 
				
			||||||
 | 
					                                    door_open()
 | 
				
			||||||
 | 
					                                    """
 | 
				
			||||||
                                    for i in range(10):
 | 
					                                    for i in range(10):
 | 
				
			||||||
                                        display.set_string("msg.txt",f'Door will close in {10-i}')
 | 
					                                        display.set_string("msg.txt",f'Door will close in {10-i}')
 | 
				
			||||||
                                        time.sleep(1)
 | 
					                                        time.sleep(1)
 | 
				
			||||||
| 
						 | 
					@ -117,31 +153,37 @@ while True:
 | 
				
			||||||
                                            should_restart = True
 | 
					                                            should_restart = True
 | 
				
			||||||
                                            break
 | 
					                                            break
 | 
				
			||||||
                                        display.set_page("scan")
 | 
					                                        display.set_page("scan")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                        """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                
 | 
				
			||||||
                                else:
 | 
					                                else:
 | 
				
			||||||
                                    display.set_page("scan")
 | 
					                                    display.set_page("scan")
 | 
				
			||||||
                                    display.set_string("msg.txt","Wrong parent. \t Try Again")
 | 
					                                    display.set_string("msg.txt","Wrong parent. \t Try Again")
 | 
				
			||||||
                                    time.sleep(2)
 | 
					                                    time.sleep(1)
 | 
				
			||||||
                                    should_restart = True
 | 
					                                    should_restart = True
 | 
				
			||||||
                                    break
 | 
					                                    break
 | 
				
			||||||
                                    #TODO Try again does not try again
 | 
					                                    #TODO Try again does not try again
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            else:
 | 
					                        elif(len(parent_face) == 0):
 | 
				
			||||||
                                display.set_page("student")
 | 
					 | 
				
			||||||
                                display.set_string("msg.txt","Cannot find parent data. \t Try Again")
 | 
					 | 
				
			||||||
                                should_restart = True
 | 
					 | 
				
			||||||
                            time.sleep(1)
 | 
					                            time.sleep(1)
 | 
				
			||||||
 | 
					                            display.set_string("msg.txt",f'Scan parent face ({10-i})')
 | 
				
			||||||
 | 
					                            i += 1
 | 
				
			||||||
 | 
					                            
 | 
				
			||||||
                        else:
 | 
					                        else:
 | 
				
			||||||
                            pass
 | 
					                            pass
 | 
				
			||||||
                else:
 | 
					                    display.set_page("scan")
 | 
				
			||||||
                    #TODO is this a parent?
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    parent_facefile = parent_face[0]['name']   
 | 
					                elif(parent_info!=None): #is parent, open door
 | 
				
			||||||
                    parent_info = db.get_parent_info(parent_facefile)
 | 
					                    #parent_facefile = faces[0]['name']   
 | 
				
			||||||
 | 
					                    #parent_info = db.get_parent_info(parent_facefile)
 | 
				
			||||||
 | 
					                    #if(parent_info!= None):
 | 
				
			||||||
 | 
					                    display.set_page("prt_wo_stu")
 | 
				
			||||||
 | 
					                    display.set_string("name_pt.txt", f'Name: {parent_info.name}')
 | 
				
			||||||
 | 
					                    display.set_string("surname_pt.txt", f'Surname: {parent_info.surname}')
 | 
				
			||||||
 | 
					                    display.set_string("id_pt.txt", f'ID: {parent_info.id}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    door_open()
 | 
				
			||||||
                    
 | 
					 | 
				
			||||||
                    display.set_page("student")
 | 
					 | 
				
			||||||
                    display.set_string("msg.txt","Cannot find student data. \t Try Again")
 | 
					 | 
				
			||||||
                    pass
 | 
					                    pass
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
        elif (len(faces)>1):
 | 
					        elif (len(faces)>1):
 | 
				
			||||||
| 
						 | 
					@ -150,7 +192,7 @@ while True:
 | 
				
			||||||
            display.set_string("msg.txt","More than one people. \t try again")
 | 
					            display.set_string("msg.txt","More than one people. \t try again")
 | 
				
			||||||
            time.sleep(2)
 | 
					            time.sleep(2)
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
            print("DONE")
 | 
					        #print("DONE")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            display.set_string("msg.txt","Move your face closer to the scanner")
 | 
					            display.set_string("msg.txt","Move your face closer to the scanner")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,8 +45,12 @@ while True:
 | 
				
			||||||
            facefile = faces[0]['name'] ## File name
 | 
					            facefile = faces[0]['name'] ## File name
 | 
				
			||||||
            student_info = db.get_student_info(facefile)## Check is it student?
 | 
					            student_info = db.get_student_info(facefile)## Check is it student?
 | 
				
			||||||
            if(student_info!=None): #is student, request another scan for parent
 | 
					            if(student_info!=None): #is student, request another scan for parent
 | 
				
			||||||
 | 
					                time_count = time.perf_counter()
 | 
				
			||||||
 | 
					                endtime = time_count + 10
 | 
				
			||||||
 | 
					                while (time_count != endtime):
 | 
				
			||||||
                    #db.log_access_student_file()
 | 
					                    #db.log_access_student_file()
 | 
				
			||||||
                time.sleep(2)
 | 
					                    time_count = time.perf_counter()
 | 
				
			||||||
 | 
					                    time.sleep(1)
 | 
				
			||||||
                    display.set_page("student")
 | 
					                    display.set_page("student")
 | 
				
			||||||
                    display.set_string("msg.txt","Scan parent face")
 | 
					                    display.set_string("msg.txt","Scan parent face")
 | 
				
			||||||
                    parent_face = fp.identify_face(img, target_condidence=0.6)   
 | 
					                    parent_face = fp.identify_face(img, target_condidence=0.6)   
 | 
				
			||||||
| 
						 | 
					@ -56,6 +60,7 @@ while True:
 | 
				
			||||||
                    display.set_string("name_std.txt", student_info.name)
 | 
					                    display.set_string("name_std.txt", student_info.name)
 | 
				
			||||||
                    display.set_string("surname_std.txt", student_info.surname)
 | 
					                    display.set_string("surname_std.txt", student_info.surname)
 | 
				
			||||||
                    display.set_string("id_std.txt", student_info.id)
 | 
					                    display.set_string("id_std.txt", student_info.id)
 | 
				
			||||||
 | 
					                    time_count = time.perf_counter()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if(parent_info != None): # Identified parent
 | 
					                    if(parent_info != None): # Identified parent
 | 
				
			||||||
                        if(db.check_relationship(student_info,parent_info)): # Check if the detected parent is right for the detected student.
 | 
					                        if(db.check_relationship(student_info,parent_info)): # Check if the detected parent is right for the detected student.
 | 
				
			||||||
| 
						 | 
					@ -98,6 +103,8 @@ while True:
 | 
				
			||||||
                    else:
 | 
					                    else:
 | 
				
			||||||
                        display.set_page("student")
 | 
					                        display.set_page("student")
 | 
				
			||||||
                        display.set_string("msg.txt","Cannot find parent data. \t Try Again")
 | 
					                        display.set_string("msg.txt","Cannot find parent data. \t Try Again")
 | 
				
			||||||
 | 
					                should_start = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                display.set_page("student")
 | 
					                display.set_page("student")
 | 
				
			||||||
                display.set_string("msg.txt","Cannot find student data. \t Try Again")
 | 
					                display.set_string("msg.txt","Cannot find student data. \t Try Again")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								access_control_python/stm32.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								access_control_python/stm32.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					import serial
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ser = serial.Serial('COM13', 115200)
 | 
				
			||||||
 | 
					while True:
 | 
				
			||||||
 | 
					    data = b''
 | 
				
			||||||
 | 
					    while True:
 | 
				
			||||||
 | 
					        byte = ser.read()
 | 
				
			||||||
 | 
					        if byte == b'\x03':
 | 
				
			||||||
 | 
					            break
 | 
				
			||||||
 | 
					        data += byte
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    data_str = data.decode('utf-8')
 | 
				
			||||||
 | 
					    print(data_str)
 | 
				
			||||||
| 
						 | 
					@ -1,27 +1,5 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# from espmega.espmega_r3 import ESPMega_standalone as ESPMega
 | 
					from espmega.espmega_r3 import ESPMega_standalone as ESPMega
 | 
				
			||||||
# import time
 | 
					plc = ESPMega("/facescan","192.168.0.239",1883)
 | 
				
			||||||
# import math
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# plc = ESPMega("/facescan","192.168.0.239",1883)
 | 
					plc.digital_write(2,0)``
 | 
				
			||||||
 | 
					 | 
				
			||||||
# i = 0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# # while True:
 | 
					 | 
				
			||||||
# #     #print(plc.digital_read(0))
 | 
					 | 
				
			||||||
# #     i= round(4095* abs(math.sin(time.perf_counter()*3.14)))
 | 
					 | 
				
			||||||
# #     print(i)
 | 
					 | 
				
			||||||
# #     plc.analog_write(1, 1,i)
 | 
					 | 
				
			||||||
# #     time.sleep(0.1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# while True:
 | 
					 | 
				
			||||||
#     plc.digital_write(1,1)
 | 
					 | 
				
			||||||
#     time.sleep(1)
 | 
					 | 
				
			||||||
#     plc.digital_write(1,0)
 | 
					 | 
				
			||||||
#     time.sleep(1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from time import perf_counter
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
while True:
 | 
					 | 
				
			||||||
    print(round((perf_counter()/2)%1))
 | 
					 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@
 | 
				
			||||||
			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 | 
								<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 | 
				
			||||||
			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 | 
								<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 | 
				
			||||||
			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
 | 
								<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
 | 
				
			||||||
			<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1659844131497362565" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
 | 
								<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1011834129611985212" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
 | 
				
			||||||
				<language-scope id="org.eclipse.cdt.core.gcc"/>
 | 
									<language-scope id="org.eclipse.cdt.core.gcc"/>
 | 
				
			||||||
				<language-scope id="org.eclipse.cdt.core.g++"/>
 | 
									<language-scope id="org.eclipse.cdt.core.g++"/>
 | 
				
			||||||
			</provider>
 | 
								</provider>
 | 
				
			||||||
| 
						 | 
					@ -16,7 +16,7 @@
 | 
				
			||||||
			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 | 
								<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 | 
				
			||||||
			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 | 
								<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 | 
				
			||||||
			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
 | 
								<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
 | 
				
			||||||
			<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1659844131497362565" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
 | 
								<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1011834129611985212" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
 | 
				
			||||||
				<language-scope id="org.eclipse.cdt.core.gcc"/>
 | 
									<language-scope id="org.eclipse.cdt.core.gcc"/>
 | 
				
			||||||
				<language-scope id="org.eclipse.cdt.core.g++"/>
 | 
									<language-scope id="org.eclipse.cdt.core.g++"/>
 | 
				
			||||||
			</provider>
 | 
								</provider>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue