From 185ced388b9afa6ac4f9268ef8871c527b5b5006 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Tue, 14 Nov 2023 22:55:26 +0700 Subject: [PATCH] working_prototype_01 --- .../access_control_mqtt.cpython-311.pyc | Bin 1926 -> 2849 bytes access_control_python/access_control_mqtt.py | 21 ++++++--- access_control_python/main copy.py | 37 ++++++++++----- access_control_python/main.py | 8 +--- access_control_python/test.py | 42 +++++++++--------- 5 files changed, 65 insertions(+), 43 deletions(-) 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 ff21bb9443a173aa03af91e2a4e338d424398d8d..2296efce364d4d432abab55a18599a704e67833f 100644 GIT binary patch literal 2849 zcmc&$&2Jl35P!Sgwb$`FPLnomLzBAsAhBo+Nu;U;Lz^m9qpDb-z{NybEqE{IaT@j+54qn#{o>Fk6HYDwrfIq(lLE(e!1dl$4cIGN1eS z+%FK3TqjhzL#Vth60!?-W26GqzeHkzr#OuXZvVBV_ue&Db$zfh=F)6@=EBAJ8}Zq>OPP-XfQaY@nuxf*f|=eC zT*)%b6$|}DpIu#ebNPD4UbgJ)-0bv9)}Bu1sj=+cu~t~OKgs7hrP*7y9WSiAil$|9 z8C%neC%x<9Ed`_iu}%ZoAWsH{9=uil>KEG?NK^+BccqeY7k&pAp6h3Zy~c7LgfMoF z&;?+&$Zhf|n(|R@W6_e}lM34)-)-xb$c~tNiqjpDVOqK>&8%i@-PD+&Qx*bI0}U2N zZSSgKYX~Q1kZlx)JA(46hhWLUDIgo978xjgxgQzdi;S1wcOsM3$Ye#CWD!t$BEqEO z5!t}}lZe=`2ZdJ7g16@bvPbY13YOCnzX1=1i*|e*4|W20H{1f{3zmW6=tL!G=F^{P zG@ob1QyqY`HN)WN;3^QnA`~fI+z&8|1l-AMpjb{apPjx;S~{HrqLz0QJk|@X`6m`oTf0QJCx%d{<}YLHo2bpF<^T zx~a2lS3P>wF>ql;fj|x_YDw8wM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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