2023-11-14 11:45:43 +00:00
|
|
|
from espmega.espmega_r3 import ESPMega_standalone as ESPMega
|
2023-11-06 09:10:46 +00:00
|
|
|
from time import sleep
|
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)):
|
|
|
|
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)
|