laser non-blocking flash

This commit is contained in:
gcw_4spBpAfv
2026-03-23 11:49:56 +08:00
parent 75def0ff38
commit d1ae364dbd
2 changed files with 27 additions and 14 deletions

View File

@@ -4,6 +4,7 @@
激光管理器模块 激光管理器模块
提供激光控制、校准等功能 提供激光控制、校准等功能
""" """
import _thread
import json import json
import os import os
import binascii import binascii
@@ -209,20 +210,31 @@ class LaserManager:
self.logger.warning("🔇 无回包") self.logger.warning("🔇 无回包")
self._laser_turned_on = False self._laser_turned_on = False
return resp return resp
def flash_laser(self, duration_ms=1000):
"""闪一下激光(用于射箭反馈),如果射箭前激光已亮则保持亮"""
try:
was_on = self._laser_turned_on # 记住射箭前的激光状态
self.turn_on_laser()
time.sleep_ms(duration_ms)
if not was_on:
self.turn_off_laser() # 射箭前是灭的,才关闭
else:
self.logger.info("[LASER] 射箭前激光已亮(调瞄中),保持激光开启")
except Exception as e:
self.logger.error(f"闪激光失败: {e}")
def flash_laser(self, duration_ms=1000):
"""闪一下激光(非阻塞版本)"""
try:
# 1. 先打开激光(主线程立刻执行,不等待)
was_on = self._laser_turned_on
self.turn_on_laser()
# 2. 只有之前是激光off的状态下才会启动一个子线程去处理“延时关闭”的逻辑否则就保持着
if not was_on:
_thread.start_new_thread(self._laser_delay_off, (duration_ms, was_on))
except Exception as e:
self.logger.error(f"启动闪激光线程失败: {e}")
def _laser_delay_off(self, duration_ms, was_on):
"""子线程执行的函数:等待一段时间后关闭激光"""
try:
# 这里 sleep 不会阻塞主线程了,只会阻塞这个不起眼的子线程
time.sleep_ms(duration_ms)
self.turn_off_laser()
# print("[LASER] 射箭前激光已亮(调瞄中),保持激光开启")
except Exception as e:
# print(f"子线程关闭激光异常: {e}")
pass
# def find_red_laser(self, frame, threshold=150, search_radius=50): # def find_red_laser(self, frame, threshold=150, search_radius=50):
# """ # """
# 在图像中心附近查找最亮的红色激光点(基于 RGB 阈值) # 在图像中心附近查找最亮的红色激光点(基于 RGB 阈值)

View File

@@ -4,7 +4,7 @@
应用版本号 应用版本号
每次 OTA 更新时,只需要更新这个文件中的版本号 每次 OTA 更新时,只需要更新这个文件中的版本号
""" """
VERSION = '1.2.9' VERSION = '1.2.10'
# 1.2.0 开始使用C++编译成.so替换部分代码 # 1.2.0 开始使用C++编译成.so替换部分代码
# 1.2.1 ota使用加密包 # 1.2.1 ota使用加密包
@@ -16,6 +16,7 @@ VERSION = '1.2.9'
# 1.2.7 修复OTA失败的bug, 空气压力传感器的阈值是2500 # 1.2.7 修复OTA失败的bug, 空气压力传感器的阈值是2500
# 1.2.8 1 加快 wifi 下数据传输的速度。2 调整射箭时处理的逻辑优先上报数据再存照片之类的操作。3假如是用户打开激光的射箭触发后不再关闭激光因为是调瞄阶段 # 1.2.8 1 加快 wifi 下数据传输的速度。2 调整射箭时处理的逻辑优先上报数据再存照片之类的操作。3假如是用户打开激光的射箭触发后不再关闭激光因为是调瞄阶段
# 1.2.9 增加电源板的控制和自动关机的功能 # 1.2.9 增加电源板的控制和自动关机的功能
# 1.2.10 config formal