feat: auto-scan 3-phase state machine with proper PD collection timing

- Phase 1 (waiting_fit): after sending control=0x01, wait for fitting=1
- Phase 2 (collecting): once fitting=1 AND run_state=1, start PD accumulation
- Phase 3 (done): run_state 1→0, calculate averages, auto-send treatment
- Check start-collecting in BOTH fitting and run_state handlers
- fitting=0 + run_state 1→0 = fitting failure, prompt retry
- Timeout 3 minutes (was 30s), auto-start treatment on completion
这个提交包含在:
Guoguo
2026-06-29 05:36:12 -07:00
父节点 b7b76a675d
当前提交 515153f134
修改 2 个文件,包含 83 行新增64 行删除
+17 -25
查看文件
@@ -2,48 +2,40 @@
<view class="page-header page-header-pink" style="padding-top: {{statusBarHeight + 24}}px;">
<view class="nav-back" bindtap="onBack"> 返回</view>
<view class="page-header-title">智能检测</view>
<view class="page-header-subtitle">{{state === 'ready' ? '准备就绪' : state === 'scanning' ? '检测中 (' + frameCount + '帧)...' : '检测完成'}}</view>
<view class="page-header-subtitle">{{phase === 'ready' ? '准备就绪' : phase === 'waiting_fit' ? '等待佩戴贴合...' : phase === 'collecting' ? '采集数据中 (' + frameCount + '帧)...' : '检测完成,正在启动...'}}</view>
</view>
<view class="page-content">
<!-- 待开始 -->
<view wx:if="{{state === 'ready'}}">
<view wx:if="{{phase === 'ready'}}">
<view class="scan-hint">设备已佩戴,点击下方按钮开始智能检测</view>
<view class="scan-hint sub-hint">检测过程请保持设备贴合</view>
<view class="scan-hint sub-hint">检测过程约需 2 分钟,请保持设备贴合</view>
<button class="btn-primary mt-30" bindtap="onStartScan">开始检测</button>
</view>
<!-- 检测中 -->
<view wx:if="{{state === 'scanning'}}">
<!-- 等待贴合 -->
<view wx:if="{{phase === 'waiting_fit'}}">
<view class="scan-container">
<view class="face-outline">
<view class="scan-line"></view>
</view>
<view class="scan-progress-bar">
<view class="scan-progress-fill" style="width: {{scanProgress}}%"></view>
</view>
<view class="scan-status">正在采集数据,已收到 {{frameCount}} 帧...</view>
</view>
<view class="scan-status">正在检测面膜贴合状态,请确保设备正确佩戴...</view>
</view>
<!-- 检测完成 -->
<view wx:if="{{state === 'done'}}">
<view class="scan-result">
<view class="result-title">PD 平均值 (共 {{frameCount}} 帧)</view>
<view class="pd-list">
<view class="pd-item" wx:for="{{pdAvg}}" wx:key="*this">
<view class="pd-region">PD{{index + 1}}</view>
<view class="pd-value">{{item}}</view>
<view class="pd-bar-bg" wx:if="{{item > 0}}">
<view class="pd-bar-fill" style="width: {{item > 4095 ? 100 : item / 40.95}}%"></view>
</view>
</view>
</view>
<view class="vbat-info" wx:if="{{vbat > 0}}">
电池电压: {{vbat}}mV ({{battery}}%)
<!-- 采集中 -->
<view wx:if="{{phase === 'collecting'}}">
<view class="scan-container">
<view class="face-outline">
<view class="scan-line"></view>
</view>
</view>
<button class="btn-primary mt-30" bindtap="onNext">开始使用</button>
<view class="scan-status">已贴合,正在采集光谱数据... 已收到 {{frameCount}} 帧</view>
</view>
<!-- 完成,自动跳转 -->
<view wx:if="{{phase === 'done'}}">
<view class="scan-status">检测完成(共 {{frameCount}} 帧),正在启动治疗...</view>
</view>
<view class="scan-error" wx:if="{{error}}">{{error}}</view>