diff --git a/access_control_python/.vscode/c_cpp_properties.json b/access_control_python/.vscode/c_cpp_properties.json
new file mode 100644
index 0000000..cea4d3f
--- /dev/null
+++ b/access_control_python/.vscode/c_cpp_properties.json
@@ -0,0 +1,18 @@
+{
+ "configurations": [
+ {
+ "name": "windows-gcc-x64",
+ "includePath": [
+ "${workspaceFolder}/**"
+ ],
+ "compilerPath": "gcc",
+ "cStandard": "${default}",
+ "cppStandard": "${default}",
+ "intelliSenseMode": "windows-gcc-x64",
+ "compilerArgs": [
+ ""
+ ]
+ }
+ ],
+ "version": 4
+}
\ No newline at end of file
diff --git a/access_control_python/.vscode/launch.json b/access_control_python/.vscode/launch.json
new file mode 100644
index 0000000..51cad73
--- /dev/null
+++ b/access_control_python/.vscode/launch.json
@@ -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
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/access_control_python/.vscode/settings.json b/access_control_python/.vscode/settings.json
new file mode 100644
index 0000000..3e5eb95
--- /dev/null
+++ b/access_control_python/.vscode/settings.json
@@ -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
+}
\ No newline at end of file
diff --git a/access_control_python/__pycache__/access_control_mqtt.cpython-311.pyc b/access_control_python/__pycache__/access_control_mqtt.cpython-311.pyc
index 2296efc..afb72a4 100644
Binary files a/access_control_python/__pycache__/access_control_mqtt.cpython-311.pyc and b/access_control_python/__pycache__/access_control_mqtt.cpython-311.pyc differ
diff --git a/access_control_python/__pycache__/face_processing.cpython-311.pyc b/access_control_python/__pycache__/face_processing.cpython-311.pyc
index b99e133..c428e28 100644
Binary files a/access_control_python/__pycache__/face_processing.cpython-311.pyc and b/access_control_python/__pycache__/face_processing.cpython-311.pyc differ
diff --git a/access_control_python/access_control_mqtt.py b/access_control_python/access_control_mqtt.py
index 4834fd9..1a4888f 100644
--- a/access_control_python/access_control_mqtt.py
+++ b/access_control_python/access_control_mqtt.py
@@ -3,50 +3,66 @@ from time import sleep, perf_counter
from time import sleep as delay
class access_control:
+ """
+ This class provides methods to control access to a door using an ESPMega board.
+ """
+
def __init__(self):
+ """
+ Initializes an instance of the access_control class.
+ """
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:
+ """
+ Returns the state of the scan sensor.
+
+ Returns:
+ bool: True if the scan sensor is active, False otherwise.
+ """
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)):
self.plc.digital_write(0,0)
-
- def unlock_door(self): #if door close, unlock the door.
+ def unlock_door(self):
+ """
+ Unlocks the door if it is closed.
+ """
if(self.plc.digital_read(0)):
self.plc.digital_write(0,1)
-
+
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)
- def activate_alarm(self):
- self.plc.digital_write(1,1)
+ # def activate_alarm(self):
+ # """
+ # 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):
self.plc.digital_write(1,round((perf_counter()*2)%1))
print(round((perf_counter()*2)%1))
- delay(0.1)
+ delay(0.3)
if self.get_door_state():
self.lock_door()
+ self.plc.digital_write(1,0)
+ self.plc.digital_write(2,0)
break
\ No newline at end of file
diff --git a/access_control_python/import time.py b/access_control_python/import time.py
new file mode 100644
index 0000000..34f3cec
--- /dev/null
+++ b/access_control_python/import time.py
@@ -0,0 +1,7 @@
+import time
+from time import perf_counter
+
+time_count = time.perf_counter()
+endtime = time_count + 10
+
+while (time_count < endtime):
diff --git a/access_control_python/main copy.py b/access_control_python/main copy.py
index d6fe252..b79c007 100644
--- a/access_control_python/main copy.py
+++ b/access_control_python/main copy.py
@@ -1,3 +1,4 @@
+
import cv2
import threading
import time
@@ -16,6 +17,7 @@ db = Database()
global img
global frame_ready
+
frame_ready = False
def read_webcam():
@@ -37,6 +39,38 @@ faces = None
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 not frame_ready:
time.sleep(1)
@@ -57,11 +91,13 @@ while True:
facefile = faces[0]['name'] ## File name
print(facefile)
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
print("Find student info")
#db.log_access_student_file()
+ parent_info = None
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("surname_std.txt",f'Surname: {student_info.surname}')
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)"""
#DONE TODO Fill in student info Resolve
- time.sleep(1)
print(student_info)
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)
if (len(parent_face)!= 0):
parent_facefile = parent_face[0]['name']
parent_info = db.get_parent_info(parent_facefile)
- print(i)
- i += 1
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.
print("Relation is OKAY")
@@ -95,6 +129,8 @@ while True:
actrl.unlock_door() # Door open
display.set_string("msg.txt","Get your kid")
#DONE TODO Send timer to display
+ door_open()
+ """
for i in range(10):
display.set_string("msg.txt",f'Door will close in {10-i}')
time.sleep(1)
@@ -117,40 +153,46 @@ while True:
should_restart = True
break
display.set_page("scan")
+
+ """
+
+
else:
display.set_page("scan")
display.set_string("msg.txt","Wrong parent. \t Try Again")
- time.sleep(2)
+ time.sleep(1)
should_restart = True
break
#TODO Try again does not try again
- else:
- display.set_page("student")
- display.set_string("msg.txt","Cannot find parent data. \t Try Again")
- should_restart = True
+ elif(len(parent_face) == 0):
time.sleep(1)
+ display.set_string("msg.txt",f'Scan parent face ({10-i})')
+ i += 1
+
else:
pass
- else:
- #TODO is this a parent?
+ display.set_page("scan")
- parent_facefile = parent_face[0]['name']
- parent_info = db.get_parent_info(parent_facefile)
+ elif(parent_info!=None): #is parent, open door
+ #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}')
-
-
- display.set_page("student")
- display.set_string("msg.txt","Cannot find student data. \t Try Again")
+ door_open()
pass
-
- elif (len(faces)>1):
- #More than one people, error.
- print("more than one people. \t try again")
- display.set_string("msg.txt","More than one people. \t try again")
- time.sleep(2)
- pass
- print("DONE")
+
+ elif (len(faces)>1):
+ #More than one people, error.
+ print("more than one people. \t try again")
+ display.set_string("msg.txt","More than one people. \t try again")
+ time.sleep(2)
+ pass
+ #print("DONE")
else:
display.set_string("msg.txt","Move your face closer to the scanner")
diff --git a/access_control_python/main.py b/access_control_python/main.py
index feb585d..d806d1a 100644
--- a/access_control_python/main.py
+++ b/access_control_python/main.py
@@ -45,59 +45,66 @@ while True:
facefile = faces[0]['name'] ## File name
student_info = db.get_student_info(facefile)## Check is it student?
if(student_info!=None): #is student, request another scan for parent
- #db.log_access_student_file()
- time.sleep(2)
- display.set_page("student")
- display.set_string("msg.txt","Scan parent face")
- parent_face = fp.identify_face(img, target_condidence=0.6)
- parent_info = db.get_parent_info(parent_face)
- #DONE TODO Fill in student info Resolve
- display.set_page("student")
- display.set_string("name_std.txt", student_info.name)
- display.set_string("surname_std.txt", student_info.surname)
- display.set_string("id_std.txt", student_info.id)
+ time_count = time.perf_counter()
+ endtime = time_count + 10
+ while (time_count != endtime):
+ #db.log_access_student_file()
+ time_count = time.perf_counter()
+ time.sleep(1)
+ display.set_page("student")
+ display.set_string("msg.txt","Scan parent face")
+ parent_face = fp.identify_face(img, target_condidence=0.6)
+ parent_info = db.get_parent_info(parent_face)
+ #DONE TODO Fill in student info Resolve
+ display.set_page("student")
+ display.set_string("name_std.txt", student_info.name)
+ display.set_string("surname_std.txt", student_info.surname)
+ display.set_string("id_std.txt", student_info.id)
+ time_count = time.perf_counter()
- 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.
- #DONE TODO Log Access STDw/P
- db.log_access_student_with_parent(student_info, student_info)
- #DONE TODO write parrent info to display
- display.set_page("student")
- display.set_string("name_std.txt", parent_info.name)
- display.set_string("surname_std.txt", parent_info.surname)
- display.set_string("id_std.txt", parent_info.id)
- access_control.unlock_door() # Door open
- display.set_string("msg.txt","Get your kid")
- #TODO Send timer to display
- #display.set_page("student")
- i = 10
- while(i>=1):
- display.set_string("msg.txt","Door will close in {}".format(i))
- time.sleep(1)
- i -= 1
- actrl.lock_door()
-
- i = 10
- #TODO Check if door close, lock
- while(i>=0):
-
- if (not actrl.get_door_state()): # False door is left open
- display.set_string("msg.txt","Door is left open, Alram in {} sec".format(i))
+ 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.
+ #DONE TODO Log Access STDw/P
+ db.log_access_student_with_parent(student_info, student_info)
+ #DONE TODO write parrent info to display
+ display.set_page("student")
+ display.set_string("name_std.txt", parent_info.name)
+ display.set_string("surname_std.txt", parent_info.surname)
+ display.set_string("id_std.txt", parent_info.id)
+ access_control.unlock_door() # Door open
+ display.set_string("msg.txt","Get your kid")
+ #TODO Send timer to display
+ #display.set_page("student")
+ i = 10
+ while(i>=1):
+ display.set_string("msg.txt","Door will close in {}".format(i))
time.sleep(1)
i -= 1
- if i == 0:
- actrl.activate_alarm()
- else:
actrl.lock_door()
- break
+ i = 10
+ #TODO Check if door close, lock
+ while(i>=0):
+
+ if (not actrl.get_door_state()): # 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()
+ else:
+ actrl.lock_door()
+ break
+
+ else:
+ display.set_page("scan")
+ display.set_string("msg.txt","Wrong parent. \t Try Again")
+ #TODO Try again does not try again
else:
- display.set_page("scan")
- display.set_string("msg.txt","Wrong parent. \t Try Again")
- #TODO Try again does not try again
- else:
- display.set_page("student")
- display.set_string("msg.txt","Cannot find parent data. \t Try Again")
+ display.set_page("student")
+ display.set_string("msg.txt","Cannot find parent data. \t Try Again")
+ should_start = True
+
else:
display.set_page("student")
display.set_string("msg.txt","Cannot find student data. \t Try Again")
diff --git a/access_control_python/stm32.py b/access_control_python/stm32.py
new file mode 100644
index 0000000..55aa517
--- /dev/null
+++ b/access_control_python/stm32.py
@@ -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)
diff --git a/access_control_python/test.py b/access_control_python/test.py
index c66012b..22b2c18 100644
--- a/access_control_python/test.py
+++ b/access_control_python/test.py
@@ -1,27 +1,5 @@
-# from espmega.espmega_r3 import ESPMega_standalone as ESPMega
-# import time
-# import math
+from espmega.espmega_r3 import ESPMega_standalone as ESPMega
+plc = ESPMega("/facescan","192.168.0.239",1883)
-# plc = ESPMega("/facescan","192.168.0.239",1883)
-
-# 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))
\ No newline at end of file
+plc.digital_write(2,0)``
\ No newline at end of file
diff --git a/access_control_stm32/.settings/language.settings.xml b/access_control_stm32/.settings/language.settings.xml
index 4038738..3e69e4d 100644
--- a/access_control_stm32/.settings/language.settings.xml
+++ b/access_control_stm32/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
@@ -16,7 +16,7 @@
-
+
diff --git a/display/display.HMI b/display/display.HMI
index ce911d0..6c36331 100644
Binary files a/display/display.HMI and b/display/display.HMI differ