stm32-fmt-code/access_control_python/access_control_mqtt.py

52 lines
1.5 KiB
Python
Raw Normal View History

2023-11-14 11:45:43 +00:00
from espmega.espmega_r3 import ESPMega_standalone as ESPMega
2023-11-14 15:55:26 +00:00
from time import sleep, perf_counter
from time import sleep as delay
2023-11-06 06:53:10 +00:00
2023-11-13 12:12:30 +00:00
class access_control:
2023-11-06 09:10:46 +00:00
def __init__(self):
2023-11-14 11:45:43 +00:00
self.plc = ESPMega("/facescan","192.168.0.239",1883)
# def light_on(self):
# self.plc.analog_write(0,1,4095)
# def light_off(self):
# self.plc.analog_write(0,0,4095)
# def get_door_state(self) -> bool:
# return self.plc.digital_read(0)
# def get_scan_state(self) -> bool:
# return self.plc.digital_read(1)
# def lock_door(self):
# if(self.get_door_state()):
# self.plc.analog_write(1,1,4095)
# def unlock_door(self):
# self.plc.analog_write(1,0,4095)
2023-11-06 06:53:10 +00:00
def get_scan_state(self) -> bool:
2023-11-14 11:45:43 +00:00
return self.plc.digital_read(1)
def lock_door(self): #if door close, lock the door.
if(self.plc.digital_read(0)):
2023-11-14 15:55:26 +00:00
self.plc.digital_write(0,0)
2023-11-14 11:45:43 +00:00
def unlock_door(self): #if door close, unlock the door.
if(self.plc.digital_read(0)):
2023-11-14 15:55:26 +00:00
self.plc.digital_write(0,1)
2023-11-14 11:45:43 +00:00
def get_door_state(self) -> bool:
return self.plc.digital_read(0)
2023-11-14 15:55:26 +00:00
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