working_prototype_01
This commit is contained in:
parent
e495e951cb
commit
185ced388b
Binary file not shown.
|
@ -1,5 +1,6 @@
|
||||||
from espmega.espmega_r3 import ESPMega_standalone as ESPMega
|
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:
|
class access_control:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -27,15 +28,25 @@ class access_control:
|
||||||
|
|
||||||
def lock_door(self): #if door close, lock the door.
|
def lock_door(self): #if door close, lock the door.
|
||||||
if(self.plc.digital_read(0)):
|
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.
|
def unlock_door(self): #if door close, unlock the door.
|
||||||
if(self.plc.digital_read(0)):
|
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:
|
def get_door_state(self) -> bool:
|
||||||
return self.plc.digital_read(0)
|
return self.plc.digital_read(0)
|
||||||
|
|
||||||
def activate_alarm():
|
def activate_alarm(self):
|
||||||
self.plc.analog_write(1,1,4095)
|
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
|
||||||
|
|
|
@ -99,21 +99,28 @@ while True:
|
||||||
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)
|
||||||
|
|
||||||
i = 10
|
i = 5
|
||||||
#TODO Check if door close, lock
|
#TODO Check if door close, lock
|
||||||
while(i>=0):
|
alarm_active: bool = False
|
||||||
if (not actrl.get_door_state()): # False door is left open
|
while(i>=0):
|
||||||
display.set_string("msg.txt","Door is left open, Alram in {} sec".format(i))
|
if (not actrl.get_door_state() and not alarm_active): # False door is left open
|
||||||
time.sleep(1)
|
display.set_string("msg.txt","Door is left open, Alram in {} sec".format(i))
|
||||||
i -= 1
|
time.sleep(1)
|
||||||
if i == 0:
|
i -= 1
|
||||||
actrl.activate_alarm()
|
if i == 0:
|
||||||
else:
|
actrl.activate_LED_alarm()
|
||||||
actrl.lock_door()
|
alarm_active = True
|
||||||
break
|
|
||||||
|
elif(actrl.get_door_state()):
|
||||||
|
actrl.lock_door()
|
||||||
|
display.set_page("scan")
|
||||||
|
should_restart = True
|
||||||
|
break
|
||||||
|
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)
|
||||||
should_restart = True
|
should_restart = True
|
||||||
break
|
break
|
||||||
#TODO Try again does not try again
|
#TODO Try again does not try again
|
||||||
|
@ -127,6 +134,12 @@ while True:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
#TODO is this a parent?
|
#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_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")
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -37,7 +37,8 @@ while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
#Try to identify face
|
#Try to identify face
|
||||||
if actrl.get_scan_state():
|
#if actrl.get_scan_state():
|
||||||
|
if True:
|
||||||
print("SCAN ACTIVE!")
|
print("SCAN ACTIVE!")
|
||||||
faces = fp.identify_face(img, target_condidence=0.6) ## Scan student face
|
faces = fp.identify_face(img, target_condidence=0.6) ## Scan student face
|
||||||
if(len(faces)==1):
|
if(len(faces)==1):
|
||||||
|
@ -90,11 +91,6 @@ while True:
|
||||||
actrl.lock_door()
|
actrl.lock_door()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
#TODO If can't lock, say left open
|
|
||||||
#Countdown
|
|
||||||
# Activate Alarm
|
|
||||||
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")
|
||||||
|
|
|
@ -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()
|
# from espmega.espmega_r3 import ESPMega_standalone as ESPMega
|
||||||
#display = Display(SERIAL_PORT_DISPLAY)
|
# import time
|
||||||
db = Database()
|
# 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:
|
while True:
|
||||||
for i in range(0,16):
|
print(round((perf_counter()/2)%1))
|
||||||
plc.write_pwm(i, 0, 2000)
|
|
||||||
time.sleep(1)
|
|
||||||
for i in range(0,16):
|
|
||||||
plc.write_pwm(i, 1, 2000)
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
Loading…
Reference in New Issue