This commit is contained in:
Siwat Sirichai 2023-11-17 22:43:10 +07:00
parent 0bf91c38a8
commit 1d78becdd4
8 changed files with 202 additions and 134 deletions

View File

@ -6,6 +6,7 @@ import face_processing as fp
from access_control_mqtt import access_control
from database import Database, Student, Parent
from display import Display
from stm32 import stm32_distance
SERIAL_PORT_DISPLAY = "COM11"
CAMERA_INDEX = 0
@ -69,22 +70,45 @@ def door_open():
#display.set_page("scan")
SD = stm32_distance("COM13")
#start_time = time.perf_counter()
flag: bool = False
"""
while True:
state = round((perf_counter())%1)
if(flag!=state):
flag = state
print(f"change to : {state}")
print(state)
delay(0.05)
"""
while True:
while not frame_ready:
time.sleep(1)
should_restart = True
distance = SD.get_distance()
print(distance)
state = distance < 800
if state!= flag:
flag = state
if(state):
display.set_string("msg.txt","Scanning")
else:
display.set_page("scan")
if (state): # Scan state
while should_restart:
#Try to identify face
should_restart = False
#if actrl.get_scan_state():
if(True):
#print("SCAN ACTIVE!")
display.set_string("msg.txt","Scanning")
#display.set_string("msg.txt","Scanning")
faces = fp.identify_face(img, target_condidence=0.6) ## Scan student face
if(len(faces)==1):
#print("faces == 1")
@ -178,6 +202,7 @@ while True:
#parent_facefile = faces[0]['name']
#parent_info = db.get_parent_info(parent_facefile)
#if(parent_info!= None):
print("Find parent info")
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}')
@ -199,6 +224,7 @@ while True:
print("Scan inactivate!!")
'''
#is student, request another scan for parent
parent_face = fp.identify_face(img, target_condidence=0.6)

View File

@ -85,12 +85,12 @@ while True:
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:
display.set_string("msg.txt", "Alarm Active!! Please close the door"")
actrl.activate_alarm()
else:
actrl.lock_door()

View File

@ -1,13 +1,30 @@
import serial
import threading
ser = serial.Serial('COM13', 115200)
class stm32_distance():
data: int = 0
def __init__(self, serial_port: str) -> None:
self.serial_port = serial_port
self.ser = serial.Serial(self.serial_port, 115200)
self.thread = threading.Thread(target=self.__read_data)
self.thread.start()
def __read_data(self):
while True:
data = b''
while True:
byte = ser.read()
byte = self.ser.read()
if byte == b'\x03':
break
data += byte
data_str = data.decode('utf-8')
print(data_str)
try:
self.data = int(data_str)
except:
pass
def get_distance(self):
return self.data

View File

@ -1,5 +1,6 @@
from stm32 import stm32_distance
from espmega.espmega_r3 import ESPMega_standalone as ESPMega
plc = ESPMega("/facescan","192.168.0.239",1883)
SD = stm32_distance("COM13")
plc.digital_write(2,0)``
while True:
print(SD.get_distance())

View File

@ -0,0 +1,13 @@
import serial
ser = serial.Serial('COM13', 115200)
data = b''
while True:
byte = ser.read()
if byte == b'\x03':
break
data += byte
data_str = data.decode('utf-8')
print(data_str)

View File

@ -0,0 +1,11 @@
from time import perf_counter
from time import sleep as delay
flag: bool = False
while True:
state = round((perf_counter())%1)
if(flag!=state):
flag = state
print(f"change to : {state}")
print(state)
delay(0.05)