feat: implement MVP Phase 1 — full-area scan with ADC data collection
- Send scan command: all 5 regions LED on, brightness 128 - Listen for ADC notify (17 bytes) instead of broken queryStatus - Parse and display PD1-PD7 values with visual bars - Show VBAT/battery info - Store scan PD data in globalData for Phase 3 smart adjustment - 8s timeout fallback, stop LED on page unload
这个提交包含在:
@@ -1,12 +1,17 @@
|
|||||||
var ble = require('../../services/ble')
|
var ble = require('../../services/ble')
|
||||||
|
var SCAN_BRIGHTNESS = 128
|
||||||
|
var SCAN_TIMEOUT = 8000
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
statusBarHeight: 44,
|
statusBarHeight: 44,
|
||||||
scanning: true,
|
scanning: true,
|
||||||
scanProgress: 0,
|
scanProgress: 0,
|
||||||
regions: 0x7F,
|
regions: 0x1F,
|
||||||
regionData: [],
|
pdValues: [],
|
||||||
timeout: false,
|
pdRaw: [],
|
||||||
|
vbat: 0,
|
||||||
|
battery: 0,
|
||||||
error: ''
|
error: ''
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -22,72 +27,88 @@ Page({
|
|||||||
var app = getApp()
|
var app = getApp()
|
||||||
this.setData({
|
this.setData({
|
||||||
statusBarHeight: app.globalData.statusBarHeight,
|
statusBarHeight: app.globalData.statusBarHeight,
|
||||||
regions: parseInt(options.regions) || 0x7F
|
regions: parseInt(options.regions) || 0x1F
|
||||||
})
|
})
|
||||||
this.startScan()
|
this.startScan()
|
||||||
},
|
},
|
||||||
|
|
||||||
startScan: function () {
|
startScan: function () {
|
||||||
var self = this
|
var self = this
|
||||||
self.setData({ scanning: true, scanProgress: 0, timeout: false })
|
self.setData({ scanning: true, scanProgress: 0, error: '', pdValues: [] })
|
||||||
|
|
||||||
this._progressTimer = setInterval(function () {
|
this._progressTimer = setInterval(function () {
|
||||||
var p = self.data.scanProgress + 2
|
var p = self.data.scanProgress + 1
|
||||||
if (p > 98) p = 98
|
if (p > 90) p = 90
|
||||||
self.setData({ scanProgress: p })
|
self.setData({ scanProgress: p })
|
||||||
}, 100)
|
}, 80)
|
||||||
|
|
||||||
this._onStatus = function (status) {
|
this._onAdc = function (data) {
|
||||||
if (status.mode_state === 0x01) {
|
console.log('[SCAN] 收到ADC数据:', JSON.stringify(data))
|
||||||
self.setData({ scanProgress: 50 })
|
|
||||||
} else if (status.mode_state === 0x04 || status.mode_state === 0x00) {
|
|
||||||
clearInterval(self._progressTimer)
|
clearInterval(self._progressTimer)
|
||||||
|
clearTimeout(self._timeoutTimer)
|
||||||
self.setData({ scanning: false, scanProgress: 100 })
|
self.setData({ scanning: false, scanProgress: 100 })
|
||||||
var names = ble.getRegionName(status.region_mask || 0x7F)
|
self._handleAdcData(data)
|
||||||
self.setData({ regionData: self.parseScanResults(names) })
|
|
||||||
}
|
}
|
||||||
}
|
ble.on('adc', this._onAdc)
|
||||||
ble.on('status', this._onStatus)
|
|
||||||
|
|
||||||
ble.queryStatus().catch(function () {})
|
console.log('[SCAN] 下发扫描指令: 全域亮度', SCAN_BRIGHTNESS)
|
||||||
|
ble.setParams({
|
||||||
|
region_mask: 0x1F,
|
||||||
|
wavelength: 2,
|
||||||
|
brightness: SCAN_BRIGHTNESS,
|
||||||
|
hold_time: 10
|
||||||
|
}).then(function () {
|
||||||
|
console.log('[SCAN] 扫描指令发送成功,等待ADC回传...')
|
||||||
|
}).catch(function (err) {
|
||||||
|
console.error('[SCAN] 扫描指令发送失败:', err)
|
||||||
|
self.setData({ error: '扫描指令发送失败' })
|
||||||
|
})
|
||||||
|
|
||||||
setTimeout(function () {
|
this._timeoutTimer = setTimeout(function () {
|
||||||
clearInterval(self._progressTimer)
|
clearInterval(self._progressTimer)
|
||||||
if (!self.data.scanning) return
|
if (!self.data.scanning) return
|
||||||
|
console.log('[SCAN] 等待ADC超时,使用默认值')
|
||||||
self.setData({ scanning: false, scanProgress: 100 })
|
self.setData({ scanning: false, scanProgress: 100 })
|
||||||
var names = ble.getRegionName(self.data.regions || 0x7F)
|
self._handleAdcData(null)
|
||||||
self.setData({ regionData: self.parseScanResults(names) })
|
}, SCAN_TIMEOUT)
|
||||||
}, 5000)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
parseScanResults: function (regions) {
|
_handleAdcData: function (data) {
|
||||||
return regions.map(function (name) {
|
var regionNames = ['右区(IO1)', '左区(IO2)', '上区(IO3)', '中区(IO4)', '下区(IO5)']
|
||||||
return { region: name, pd: '待检测' }
|
var pdValues = []
|
||||||
})
|
|
||||||
|
if (data && data.pd && data.pd.length >= 7) {
|
||||||
|
this.setData({ pdRaw: data.pd, vbat: data.vbat || 0, battery: data.battery || 0 })
|
||||||
|
for (var i = 0; i < 5; i++) {
|
||||||
|
pdValues.push({ region: regionNames[i], pd: data.pd[i], pdText: String(data.pd[i]) })
|
||||||
|
}
|
||||||
|
pdValues.push({ region: 'PD6', pd: data.pd[5], pdText: String(data.pd[5]) })
|
||||||
|
pdValues.push({ region: 'PD7', pd: data.pd[6], pdText: String(data.pd[6]) })
|
||||||
|
|
||||||
|
getApp().globalData.lastScanPd = data.pd
|
||||||
|
getApp().globalData.lastScanVbat = data.vbat
|
||||||
|
} else {
|
||||||
|
for (var j = 0; j < 5; j++) {
|
||||||
|
pdValues.push({ region: regionNames[j], pd: 0, pdText: '未采集' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setData({ pdValues: pdValues })
|
||||||
},
|
},
|
||||||
|
|
||||||
onUnload: function () {
|
onUnload: function () {
|
||||||
if (this._progressTimer) clearInterval(this._progressTimer)
|
if (this._progressTimer) clearInterval(this._progressTimer)
|
||||||
if (this._onStatus) ble.off('status', this._onStatus)
|
if (this._timeoutTimer) clearTimeout(this._timeoutTimer)
|
||||||
|
if (this._onAdc) ble.off('adc', this._onAdc)
|
||||||
|
ble.stopTreatment().catch(function () {})
|
||||||
},
|
},
|
||||||
|
|
||||||
onNext: function () {
|
onNext: function () {
|
||||||
var mask = this.data.regions || 0x7F
|
var mask = this.data.regions || 0x1F
|
||||||
ble.setParams({
|
var pdRaw = this.data.pdRaw
|
||||||
region_mask: mask,
|
var pdParam = pdRaw.length > 0 ? '&pd=' + encodeURIComponent(JSON.stringify(pdRaw)) : ''
|
||||||
wavelength: 2,
|
|
||||||
brightness: 200,
|
|
||||||
duration_ms: 600000,
|
|
||||||
mode: 1
|
|
||||||
}).then(function () {
|
|
||||||
return ble.startTreatment(mask)
|
|
||||||
}).then(function () {
|
|
||||||
wx.redirectTo({
|
wx.redirectTo({
|
||||||
url: '/pages/treating/treating?regions=' + mask + '&wavelength=2&duration=600000&mode=1'
|
url: '/pages/treatment-setup/treatment-setup?regions=' + mask + pdParam
|
||||||
})
|
})
|
||||||
}).catch(function (err) {
|
}
|
||||||
wx.showToast({ title: err.error_msg || '启动失败', icon: 'none' })
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,30 +1,39 @@
|
|||||||
<view class="page">
|
<view class="page">
|
||||||
<view class="page-header page-header-pink" style="padding-top: {{statusBarHeight + 24}}px;">
|
<view class="page-header page-header-pink" style="padding-top: {{statusBarHeight + 24}}px;">
|
||||||
<view class="nav-back" bindtap="onBack">‹ 返回</view>
|
<view class="nav-back" bindtap="onBack">‹ 返回</view>
|
||||||
<view class="page-header-title">自动扫描</view>
|
<view class="page-header-title">区域扫描</view>
|
||||||
<view class="page-header-subtitle">正在识别区域...</view>
|
<view class="page-header-subtitle">{{scanning ? '正在采集数据...' : '扫描完成'}}</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="page-content">
|
<view class="page-content">
|
||||||
<view class="page-title">自动扫描区域</view>
|
<view class="scan-container" wx:if="{{scanning}}">
|
||||||
|
|
||||||
<view class="scan-container">
|
|
||||||
<view class="face-outline">
|
<view class="face-outline">
|
||||||
<view class="scan-line"></view>
|
<view class="scan-line"></view>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="scan-progress-bar">
|
||||||
|
<view class="scan-progress-fill" style="width: {{scanProgress}}%"></view>
|
||||||
|
</view>
|
||||||
|
<view class="scan-status">全域LED已开启,亮度 128,等待PD数据回传...</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="scan-hint">请正确佩戴设备</view>
|
<view class="scan-result" wx:if="{{!scanning && pdValues.length > 0}}">
|
||||||
<view class="scan-hint" style="font-size:24rpx;color:#999;margin-top:8rpx;">连接设备后可获取检测数据</view>
|
<view class="result-title">PD 采集结果</view>
|
||||||
|
<view class="pd-list">
|
||||||
<view class="scan-progress" wx:if="{{scanning}}">
|
<view class="pd-item" wx:for="{{pdValues}}" wx:key="region">
|
||||||
正在扫描... <text class="highlight">{{regionData.length || 3}}</text> 个区域
|
<view class="pd-region">{{item.region}}</view>
|
||||||
|
<view class="pd-value {{item.pd > 0 ? '' : 'pd-empty'}}">{{item.pdText}}</view>
|
||||||
|
<view class="pd-bar-bg" wx:if="{{item.pd > 0}}">
|
||||||
|
<view class="pd-bar-fill" style="width: {{item.pd > 4095 ? 100 : item.pd / 40.95}}%"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="vbat-info" wx:if="{{vbat > 0}}">
|
||||||
|
电池电压: {{vbat}}mV ({{battery}}%)
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="detected-tags" wx:if="{{regionData.length > 0}}">
|
<view class="scan-error" wx:if="{{error}}">{{error}}</view>
|
||||||
<text class="detected-tag" wx:for="{{regionData}}" wx:key="region">{{item.region}}</text>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<button class="btn-primary mt-30" wx:if="{{!scanning}}" bindtap="onNext">设置参数</button>
|
<button class="btn-primary mt-30" wx:if="{{!scanning}}" bindtap="onNext">下一步</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
.scan-container {
|
.scan-container {
|
||||||
position: relative;
|
display: flex;
|
||||||
width: 320rpx;
|
flex-direction: column;
|
||||||
height: 400rpx;
|
align-items: center;
|
||||||
margin: 40rpx auto;
|
padding: 20rpx 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.face-outline {
|
.face-outline {
|
||||||
width: 100%;
|
width: 320rpx;
|
||||||
height: 100%;
|
height: 400rpx;
|
||||||
border: 6rpx solid #e5e5e5;
|
border: 6rpx solid #e5e5e5;
|
||||||
border-radius: 50% 50% 45% 45%;
|
border-radius: 50% 50% 45% 45%;
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -29,49 +29,103 @@
|
|||||||
100% { top: calc(100% - 6rpx); opacity: 0.5; }
|
100% { top: calc(100% - 6rpx); opacity: 0.5; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.scan-hint {
|
.scan-progress-bar {
|
||||||
text-align: center;
|
width: 80%;
|
||||||
font-size: 26rpx;
|
height: 8rpx;
|
||||||
color: #666666;
|
background: #f0f0f0;
|
||||||
margin-bottom: 24rpx;
|
border-radius: 4rpx;
|
||||||
|
margin-top: 30rpx;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.scan-progress {
|
.scan-progress-fill {
|
||||||
text-align: center;
|
height: 100%;
|
||||||
background: #f0f9ff;
|
background: linear-gradient(90deg, #E6508C, #DCB982);
|
||||||
padding: 16rpx 28rpx;
|
border-radius: 4rpx;
|
||||||
border-radius: 24rpx;
|
transition: width 0.3s;
|
||||||
font-size: 26rpx;
|
|
||||||
color: #006699;
|
|
||||||
width: fit-content;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.highlight {
|
.scan-status {
|
||||||
color: #E6508C;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.detected-tags {
|
|
||||||
text-align: center;
|
|
||||||
margin-top: 24rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.detected-tag {
|
|
||||||
background: #fdf2f8;
|
|
||||||
border: 2rpx solid #E6508C;
|
|
||||||
color: #E6508C;
|
|
||||||
padding: 10rpx 24rpx;
|
|
||||||
border-radius: 24rpx;
|
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
display: inline-block;
|
color: #999;
|
||||||
margin: 6rpx;
|
margin-top: 16rpx;
|
||||||
animation: tagPulse 1s ease-in-out;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes tagPulse {
|
.scan-result {
|
||||||
0%, 100% { transform: scale(1); }
|
background: #fff;
|
||||||
50% { transform: scale(1.05); }
|
border-radius: 20rpx;
|
||||||
|
padding: 24rpx;
|
||||||
|
margin-top: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-title {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pd-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pd-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pd-region {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #666;
|
||||||
|
width: 160rpx;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pd-value {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #E6508C;
|
||||||
|
width: 100rpx;
|
||||||
|
flex-shrink: 0;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pd-empty {
|
||||||
|
color: #ccc;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pd-bar-bg {
|
||||||
|
flex: 1;
|
||||||
|
height: 16rpx;
|
||||||
|
background: #f5f5f5;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pd-bar-fill {
|
||||||
|
height: 100%;
|
||||||
|
background: linear-gradient(90deg, #E6508C, #DCB982);
|
||||||
|
border-radius: 8rpx;
|
||||||
|
min-width: 4rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vbat-info {
|
||||||
|
margin-top: 20rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #999;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scan-error {
|
||||||
|
text-align: center;
|
||||||
|
color: #ff4d4f;
|
||||||
|
font-size: 26rpx;
|
||||||
|
margin-top: 20rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-primary::after {
|
.btn-primary::after {
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户