import serial
from threading import Thread

class access_control:
    _read_buffer = []
    serial_adapter: serial.Serial
    def __init__(self, serial_port: str):
        self.serial_adapter = serial.Serial(serial_port,baudrate=115200)
        Thread(target=self.read_serial).start()
    def read_serial(self):
        while True:
            if self.serial_adapter.in_waiting:
                data = self.serial_adapter.read(1)
                #data = data.decode("ascii").removesuffix("\r\n")
                self._read_buffer.append(data)
    def light_on(self):
        packet = bytearray()
        packet.append(0x00)
        packet.append(0x01)
        packet.append(0xFF)
        self.serial_adapter.write(packet)
    def light_off(self):
        packet = bytearray()
        packet.append(0x00)
        packet.append(0x00)
        packet.append(0xFF)
        self.serial_adapter.write(packet)
    