stm32-fmt-code/access_control_python/access_control_mqtt.py

41 lines
1.2 KiB
Python

from espmega.espmega_r3 import ESPMega_standalone as ESPMega
from time import sleep
class access_control:
def __init__(self):
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)
def get_scan_state(self) -> bool:
return self.plc.digital_read(1)
def lock_door(self): #if door close, lock the door.
if(self.plc.digital_read(0)):
self.plc.analog_write(0,1,4095)
def unlock_door(self): #if door close, unlock the door.
if(self.plc.digital_read(0)):
self.plc.analog_write(0,0,4095)
def get_door_state(self) -> bool:
return self.plc.digital_read(0)
def activate_alarm():
self.plc.analog_write(1,1,4095)