from espmega.espmega_r3 import ESPMega_standalone as ESPMega from time import sleep, perf_counter from time import sleep as delay 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.digital_write(0,0) def unlock_door(self): #if door close, unlock the door. if(self.plc.digital_read(0)): self.plc.digital_write(0,1) def get_door_state(self) -> bool: return self.plc.digital_read(0) 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