working_prototype_01

This commit is contained in:
Siwat Sirichai 2023-11-14 22:55:26 +07:00
parent e495e951cb
commit 185ced388b
5 changed files with 65 additions and 43 deletions

View File

@ -1,5 +1,6 @@
from espmega.espmega_r3 import ESPMega_standalone as ESPMega
from time import sleep
from time import sleep, perf_counter
from time import sleep as delay
class access_control:
def __init__(self):
@ -27,15 +28,25 @@ class access_control:
def lock_door(self): #if door close, lock the door.
if(self.plc.digital_read(0)):
self.plc.analog_write(0,1,4095)
self.plc.digital_write(0,0)
def unlock_door(self): #if door close, unlock the door.
if(self.plc.digital_read(0)):
self.plc.analog_write(0,0,4095)
self.plc.digital_write(0,1)
def get_door_state(self) -> bool:
return self.plc.digital_read(0)
def activate_alarm():
self.plc.analog_write(1,1,4095)
def activate_alarm(self):
self.plc.digital_write(1,1)
def activate_LED_alarm(self):
while(True):
self.plc.digital_write(1,round((perf_counter()*2)%1))
print(round((perf_counter()*2)%1))
delay(0.1)
if self.get_door_state():
self.lock_door()
break

View File

@ -99,21 +99,28 @@ while True:
display.set_string("msg.txt",f'Door will close in {10-i}')
time.sleep(1)
i = 10
i = 5
#TODO Check if door close, lock
alarm_active: bool = False
while(i>=0):
if (not actrl.get_door_state()): # False door is left open
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()
else:
actrl.activate_LED_alarm()
alarm_active = True
elif(actrl.get_door_state()):
actrl.lock_door()
display.set_page("scan")
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)
should_restart = True
break
#TODO Try again does not try again
@ -127,6 +134,12 @@ while True:
pass
else:
#TODO is this a parent?
parent_facefile = parent_face[0]['name']
parent_info = db.get_parent_info(parent_facefile)
display.set_page("student")
display.set_string("msg.txt","Cannot find student data. \t Try Again")
pass

View File

@ -37,7 +37,8 @@ while True:
time.sleep(1)
#Try to identify face
if actrl.get_scan_state():
#if actrl.get_scan_state():
if True:
print("SCAN ACTIVE!")
faces = fp.identify_face(img, target_condidence=0.6) ## Scan student face
if(len(faces)==1):
@ -90,11 +91,6 @@ while True:
actrl.lock_door()
break
#
#TODO If can't lock, say left open
#Countdown
# Activate Alarm
else:
display.set_page("scan")
display.set_string("msg.txt","Wrong parent. \t Try Again")

View File

@ -1,25 +1,27 @@
import threading
import time
import face_processing as fp
from access_control_mqtt import access_control
from database import Database, Student, Parent
from display import Display
from espmega_mqtt import ESPMegaMQTT
#SERIAL_PORT_DISPLAY = "COM26"
CAMERA_INDEX = 0
#actrl = access_control()
#display = Display(SERIAL_PORT_DISPLAY)
db = Database()
# from espmega.espmega_r3 import ESPMega_standalone as ESPMega
# import time
# import math
plc = ESPMegaMQTT()
# 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:
for i in range(0,16):
plc.write_pwm(i, 0, 2000)
time.sleep(1)
for i in range(0,16):
plc.write_pwm(i, 1, 2000)
time.sleep(1)
print(round((perf_counter()/2)%1))