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 ff21bb9..2296efc 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/access_control_mqtt.py b/access_control_python/access_control_mqtt.py index 1d1edf3..4834fd9 100644 --- a/access_control_python/access_control_mqtt.py +++ b/access_control_python/access_control_mqtt.py @@ -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) \ No newline at end of file + 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 + \ No newline at end of file diff --git a/access_control_python/main copy.py b/access_control_python/main copy.py index 71f6976..d6fe252 100644 --- a/access_control_python/main copy.py +++ b/access_control_python/main copy.py @@ -99,21 +99,28 @@ while True: display.set_string("msg.txt",f'Door will close in {10-i}') time.sleep(1) - 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 + i = 5 + #TODO Check if door close, lock + alarm_active: bool = False + 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_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 diff --git a/access_control_python/main.py b/access_control_python/main.py index ddce4be..feb585d 100644 --- a/access_control_python/main.py +++ b/access_control_python/main.py @@ -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") diff --git a/access_control_python/test.py b/access_control_python/test.py index bdc6e44..c66012b 100644 --- a/access_control_python/test.py +++ b/access_control_python/test.py @@ -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)) \ No newline at end of file