This commit is contained in:
2026-07-16 15:24:40 +08:00
parent 22ae87f4b4
commit feed450554
32 changed files with 6634 additions and 95 deletions

View File

@ -8,11 +8,12 @@ from collections import namedtuple
import socket
DEF_CDC_SYNC_MS = 1000 #电容同步间隔
DEF_GET_CAP_MS = (30) #读取电容间隔
DEF_PRO_CYC = 100
DEF_MAX_FINGER_NUM = 5 # 需要连接的手指数量最大5个
DEF_MAX_FINGER_NUM = 1 #需要连接的手指数量最大5个
# 定义一个全局的队列,用于线程间通信
capReadQueue = queue.Queue()
@ -47,7 +48,7 @@ class ClassCapRead:
self.syncTimer = 0
self.connectStatus = EnumCh341ConnectStatus.CH341_CONNECT_INIT
self.running = True # <-- 新增这一行
self.connectDebug()
def __del__(self):
@ -176,20 +177,26 @@ class ClassCapRead:
difftime = int(capReadTime*1000-ms_capReadTime*1000)
#print(f"diffTime={difftime}")
#定时器在任务完成后重新启动
if(difftime>DEF_GET_CAP_MS):
timer = threading.Timer(DEF_GET_CAP_MS/1000, self.capRead)
else:
timer = threading.Timer((DEF_GET_CAP_MS-difftime)/1000, self.capRead)
if self.running: # 新增判断
if(difftime>DEF_GET_CAP_MS):
timer = threading.Timer(DEF_GET_CAP_MS/1000, self.capRead)
else:
timer = threading.Timer((DEF_GET_CAP_MS-difftime)/1000, self.capRead)
timer.start()
def capReadThread():
# 线程的主体功能
cap = ClassCapRead()
while True:
cap.ch341Connect()
time.sleep(DEF_PRO_CYC/1000)
try:
while True:
cap.ch341Connect()
time.sleep(DEF_PRO_CYC/1000)
except KeyboardInterrupt:
print("\nStopping sensor read...")
cap.running = False
cap.disConnectDebug()
cap.ch341.disconnect()
print("CH341 released.")
def main():
capReadThread()