Compare commits
2
Commits
a09b45738a
...
d96ca4d031
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d96ca4d031 | ||
|
|
ced66682ed |
@@ -136,6 +136,7 @@ def cmd_str():
|
||||
sync_system_time_from_4g()
|
||||
|
||||
# 2.1 WiFi 热点配网兜底:仅当 STA 与 4G 均不可用时起 AP + HTTP;提交后删 /boot/wifi.ap、建 wifi.sta 并 reboot
|
||||
_ota_pending_path = f"{config.APP_DIR}/ota_pending.json"
|
||||
try:
|
||||
from wifi_config_httpd import maybe_start_wifi_ap_fallback
|
||||
|
||||
@@ -286,12 +287,13 @@ def cmd_str():
|
||||
logger.info("系统准备完成...")
|
||||
|
||||
last_adc_trigger = 0
|
||||
trigger_adc_val = 0 # 触发时的气压值,气压需降回此值以下才能再次触发
|
||||
# 读取一次ADC初始值,防止开机时传感器已有压力导致误触发
|
||||
enable_check = True
|
||||
try:
|
||||
last_adc_val = hardware_manager.adc_obj.read()
|
||||
except Exception:
|
||||
last_adc_val = 0
|
||||
peak_adc_val = 0 # 当前周期内的压力峰值
|
||||
# 气压采样:减少日志频率(每 N 个点输出一条),避免 logger.debug 拖慢采样
|
||||
PRESSURE_BATCH_SIZE = 100
|
||||
|
||||
@@ -381,22 +383,16 @@ def cmd_str():
|
||||
pressure_max = adc_val
|
||||
if len(pressure_buf) >= PRESSURE_BATCH_SIZE:
|
||||
_flush_pressure_buf("batch")
|
||||
# 峰值检测:压力从峰值下降时触发,确保捕获到最大冲击时刻
|
||||
if adc_val > peak_adc_val:
|
||||
peak_adc_val = adc_val # 更新峰值
|
||||
if (peak_adc_val >= config.ADC_TRIGGER_THRESHOLD
|
||||
and adc_val < peak_adc_val
|
||||
and last_adc_val >= peak_adc_val):
|
||||
# 封顶后下降沿触发:peak是最大值,当前值开始下降,且上次值还在peak位置
|
||||
# 突变增量检测:压力增量大于300时触发
|
||||
# 触发后需等气压降到触发值以下才重新检测增量
|
||||
if adc_val < trigger_adc_val :
|
||||
enable_check = True
|
||||
if (adc_val - last_adc_val) > 250 and enable_check:
|
||||
hardware_manager.start_idle_timer() # 重新计时
|
||||
diff_ms = current_time - last_adc_trigger
|
||||
if diff_ms < 3000:
|
||||
peak_adc_val = 0 # 去抖期间重置峰值
|
||||
time.sleep_ms(5)
|
||||
continue
|
||||
last_adc_trigger = current_time
|
||||
peak_adc_val = 0 # 触发后重置峰值
|
||||
# 触发前先把缓存刷出来,避免波形被长耗时处理截断
|
||||
trigger_adc_val = adc_val # 记录触发时的气压值
|
||||
last_adc_val = adc_val # 更新基准值,防止连续增量误触发
|
||||
enable_check = False
|
||||
_flush_pressure_buf("before_trigger")
|
||||
|
||||
try:
|
||||
@@ -415,7 +411,7 @@ def cmd_str():
|
||||
camera_manager.show(camera_manager.read_frame())
|
||||
except Exception as e:
|
||||
pass
|
||||
time.sleep_ms(5)
|
||||
time.sleep_ms(1)
|
||||
last_adc_val = adc_val
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user