fak
This commit is contained in:
parent
508f39fe8d
commit
8394bf9892
89 changed files with 23652 additions and 10182 deletions
Binary file not shown.
Binary file not shown.
|
@ -5,22 +5,33 @@ from threading import Thread
|
|||
class access_control:
|
||||
_in_payloads = []
|
||||
_read_buffer = []
|
||||
_door_state: bool = 0
|
||||
_door_state: bool = False
|
||||
serial_adapter: serial.Serial
|
||||
_scan_active: bool = False
|
||||
_read_active = True
|
||||
def __init__(self, serial_port: str):
|
||||
self.serial_adapter = serial.Serial(serial_port,baudrate=9600)
|
||||
#Thread(target=self.read_serial).start()
|
||||
#Thread(target=self._process_payload).start()
|
||||
def read_serial(self):
|
||||
Thread(target=self.read_serial).start()
|
||||
Thread(target=self._process_payload).start()
|
||||
#Thread(target=self._state_requester).start()
|
||||
|
||||
def _state_requester(self):
|
||||
while True:
|
||||
if self.serial_adapter.in_waiting:
|
||||
in_byte = self.serial_adapter.read(1)
|
||||
if(in_byte==b'\xFF'):
|
||||
self._in_payloads.append(self._read_buffer)
|
||||
self._read_buffer = []
|
||||
else:
|
||||
self._read_buffer.append(in_byte)
|
||||
time.sleep(0.01)
|
||||
if self._read_active:
|
||||
self._request_door_state()
|
||||
self._request_scan_state()
|
||||
time.sleep(1)
|
||||
|
||||
def read_serial(self):
|
||||
while True:
|
||||
if self.serial_adapter.in_waiting>0:
|
||||
in_byte = self.serial_adapter.read(1)
|
||||
if(in_byte==b'\xFF'):
|
||||
self._in_payloads.append(self._read_buffer)
|
||||
self._read_buffer = []
|
||||
else:
|
||||
self._read_buffer.append(in_byte)
|
||||
time.sleep(0.01)
|
||||
def _process_payload(self):
|
||||
while True:
|
||||
self._process_payload_once()
|
||||
|
@ -30,11 +41,18 @@ class access_control:
|
|||
def _process_payload_once(self):
|
||||
if(len(self._in_payloads)>0):
|
||||
payload = self._in_payloads.pop(0)
|
||||
if(payload[0]==b'\x01'):
|
||||
if(payload[1]==b'\x00'):
|
||||
self._door_state = True
|
||||
elif(payload[1]==b'\01'):
|
||||
self._door_state = False
|
||||
if len(payload)>0:
|
||||
if(payload[0]==b'\x01'):
|
||||
if(payload[1]==b'\x00'):
|
||||
self._door_state = True
|
||||
elif(payload[1]==b'\01'):
|
||||
self._door_state = False
|
||||
elif(payload[0]==b'\x02'):
|
||||
if(payload[1]==b'\x00'):
|
||||
self._scan_active = False
|
||||
elif(payload[1]==b'\01'):
|
||||
self._scan_active = True
|
||||
|
||||
|
||||
def light_on(self):
|
||||
packet = bytearray()
|
||||
|
@ -53,11 +71,18 @@ class access_control:
|
|||
packet.append(0x01)
|
||||
packet.append(0xFF)
|
||||
self.serial_adapter.write(packet)
|
||||
|
||||
def _request_scan_state(self):
|
||||
packet = bytearray()
|
||||
packet.append(0x03)
|
||||
packet.append(0xFF)
|
||||
self.serial_adapter.write(packet)
|
||||
def get_door_state(self) -> bool:
|
||||
self._request_door_state()
|
||||
time.sleep(0.05)
|
||||
return self._door_state
|
||||
|
||||
def get_scan_state(self) -> bool:
|
||||
return self._scan_active
|
||||
|
||||
def lock_door(self):
|
||||
packet = bytearray()
|
||||
packet.append(0x02)
|
||||
|
|
|
@ -5,8 +5,8 @@ import requests
|
|||
import json
|
||||
|
||||
#api_server = "http://localhost:5000"
|
||||
#api_server = "http://192.168.0.239:5000"
|
||||
api_server = "https://racist.siwatsystem.com"
|
||||
api_server = "http://192.168.0.239"
|
||||
#api_server = "https://racist.siwatsystem.com"
|
||||
|
||||
def analyze_face(img):
|
||||
endpoint = api_server +"/process_image"
|
||||
|
|
|
@ -28,10 +28,13 @@ while True:
|
|||
time.sleep(1)
|
||||
|
||||
#Try to identify face
|
||||
faces = fp.identify_face(img, target_condidence=0.6)
|
||||
if(len(faces)>0):
|
||||
print("Door Unlocked!, Locking in 5 seconds")
|
||||
stm32.unlock_door()
|
||||
time.sleep(5)
|
||||
stm32.lock_door()
|
||||
print("Door Locked!")
|
||||
if stm32.get_scan_state():
|
||||
print("SCAN ACTIVE!")
|
||||
faces = fp.identify_face(img, target_condidence=0.6)
|
||||
if(len(faces)>0):
|
||||
print("Door Unlocked!, Locking in 5 seconds")
|
||||
stm32.unlock_door()
|
||||
time.sleep(5)
|
||||
stm32.lock_door()
|
||||
print("Door Locked!")
|
||||
print("DONE")
|
||||
|
|
|
@ -10,6 +10,10 @@ while True:
|
|||
stm32.lock_door()
|
||||
if(cmd == 'unlock'):
|
||||
stm32.unlock_door()
|
||||
if(cmd == 'scan_state'):
|
||||
print(stm32.get_scan_state())
|
||||
if(cmd == 'door_state'):
|
||||
print(stm32.get_door_state())
|
||||
#stm32.unlock_door()
|
||||
time.sleep(1)
|
||||
#door_state = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue