pref: 压力传感器添加3s只能触发一次限制

This commit is contained in:
2025-12-23 14:24:20 +08:00
parent aba991f6f7
commit d4cd2e21d6

12
main.py
View File

@@ -629,7 +629,7 @@ def tcp_main():
# 处理心跳 ACK # 处理心跳 ACK
elif logged_in and msg_type == 4: elif logged_in and msg_type == 4:
last_heartbeat_ack_time = time.ticks_ms() last_heartbeat_ack_time = time.ticks_ms()
print("✅ 收到心跳确认") # print("✅ 收到心跳确认")
# 处理业务指令 # 处理业务指令
elif logged_in and isinstance(body, dict): elif logged_in and isinstance(body, dict):
@@ -723,7 +723,7 @@ def tcp_main():
print("💔 心跳发送失败") print("💔 心跳发送失败")
break break
last_heartbeat_send_time = current_time last_heartbeat_send_time = current_time
print("💓 心跳已发送") # print("💓 心跳已发送")
# 心跳超时重连 # 心跳超时重连
if logged_in and current_time - last_heartbeat_ack_time > 6000: if logged_in and current_time - last_heartbeat_ack_time > 6000:
@@ -784,9 +784,17 @@ def cmd_str():
print("系统准备完成...") print("系统准备完成...")
last_adc_trigger = 0
# 主循环:检测扳机触发 → 拍照 → 分析 → 上报 # 主循环:检测扳机触发 → 拍照 → 分析 → 上报
while not app.need_exit(): while not app.need_exit():
current_time = time.ticks_ms()
# print("压力传感器数值: ", adc_obj.read())
if adc_obj.read() > ADC_TRIGGER_THRESHOLD: if adc_obj.read() > ADC_TRIGGER_THRESHOLD:
diff_ms = current_time-last_adc_trigger
if diff_ms<3000:
continue
last_adc_trigger = current_time
time.sleep_ms(60) # 防抖 time.sleep_ms(60) # 防抖
frame = cam.read() frame = cam.read()
x, y = laser_point x, y = laser_point