-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_input.py
28 lines (24 loc) · 904 Bytes
/
serial_input.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import serial
from loguru import logger
from PyQt5.QtCore import QThread, pyqtSignal
class DetectorPersonThread(QThread):
people_entry_signal = pyqtSignal()
def __init__(self, com='/dev/ttyTHS1', port=115200, timeout=2):
"""
DetectorPersonThread which carry the GPIO input
:param: input_pin
"""
super(DetectorPersonThread, self).__init__()
self.com = com
self.port = port
self.timeout = timeout
def run(self):
while True:
try:
fh_data = serial.Serial(self.com, self.port, timeout=self.timeout).read(7).hex()
if fh_data[0:2] == '01':
fh_datas = int(fh_data[6:10], 16) / 10
if fh_datas > 30 and fh_datas <= 90:
self.people_entry_signal.emit()
except Exception as e:
logger.error(e)