Add door locking fuction
This commit is contained in:
		
							parent
							
								
									2146e886a0
								
							
						
					
					
						commit
						3d346863ae
					
				
					 16 changed files with 3545 additions and 3451 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| 
						 | 
				
			
			@ -20,9 +20,12 @@ class access_control:
 | 
			
		|||
                    self._read_buffer = []
 | 
			
		||||
                else:
 | 
			
		||||
                    self._read_buffer.append(in_byte)
 | 
			
		||||
            time.sleep(0.01)
 | 
			
		||||
    def _process_payload(self):
 | 
			
		||||
        while True:
 | 
			
		||||
            self._process_payload_once()
 | 
			
		||||
            time.sleep(0.01)
 | 
			
		||||
 | 
			
		||||
                                 
 | 
			
		||||
    def _process_payload_once(self):
 | 
			
		||||
        if(len(self._in_payloads)>0):
 | 
			
		||||
| 
						 | 
				
			
			@ -32,6 +35,7 @@ class access_control:
 | 
			
		|||
                    self._door_state = True
 | 
			
		||||
                elif(payload[1]==b'\01'):
 | 
			
		||||
                    self._door_state = False   
 | 
			
		||||
 | 
			
		||||
    def light_on(self):
 | 
			
		||||
        packet = bytearray()
 | 
			
		||||
        packet.append(0x00)
 | 
			
		||||
| 
						 | 
				
			
			@ -51,5 +55,19 @@ class access_control:
 | 
			
		|||
        self.serial_adapter.write(packet)
 | 
			
		||||
    def get_door_state(self) -> bool:
 | 
			
		||||
        self._request_door_state()
 | 
			
		||||
        time.sleep(0.25)
 | 
			
		||||
        return self._door_state
 | 
			
		||||
        time.sleep(0.05)
 | 
			
		||||
        return self._door_state
 | 
			
		||||
    
 | 
			
		||||
    def lock_door(self):
 | 
			
		||||
        packet = bytearray()
 | 
			
		||||
        packet.append(0x02)
 | 
			
		||||
        packet.append(0x01)
 | 
			
		||||
        packet.append(0xFF)
 | 
			
		||||
        self.serial_adapter.write(packet)
 | 
			
		||||
 | 
			
		||||
    def unlock_door(self):
 | 
			
		||||
        packet = bytearray()
 | 
			
		||||
        packet.append(0x02)
 | 
			
		||||
        packet.append(0x00)
 | 
			
		||||
        packet.append(0xFF)
 | 
			
		||||
        self.serial_adapter.write(packet)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,10 +1,18 @@
 | 
			
		|||
from access_control import access_control
 | 
			
		||||
from line_notify import LineNotify
 | 
			
		||||
import time 
 | 
			
		||||
 | 
			
		||||
stm32 = access_control("COM12")
 | 
			
		||||
time.sleep(1)
 | 
			
		||||
door_state = False
 | 
			
		||||
while True:
 | 
			
		||||
    print(stm32._in_payloads)
 | 
			
		||||
    if(door_state != stm32.get_door_state()):
 | 
			
		||||
        door_state = stm32.get_door_state()
 | 
			
		||||
        notify = LineNotify("olK1QXriiuKgfxB6xkj7SIFfj9jsXfpl2PqmjCDuBRw")
 | 
			
		||||
        notify.send(f'door is {door_state}')
 | 
			
		||||
    if(stm32.get_door_state() == True):
 | 
			
		||||
        print("Door is Closed")
 | 
			
		||||
        stm32.lock_door()
 | 
			
		||||
    else:
 | 
			
		||||
        print("Door is Openned")
 | 
			
		||||
        stm32.unlock_door()
 | 
			
		||||
    time.sleep(0.01)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1,2 @@
 | 
			
		|||
pyserial
 | 
			
		||||
pyserial
 | 
			
		||||
line_notify
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue