feat(debug): temporary BLE debug page for on-device verification
- entry in profile menu, visible only while a device is connected - live FFE4 readout: 7x PD, VBAT, fitting, scan wave marker, run state - tap a face-map region to fire a 2s single-region treat command (verifies region-to-IO mapping on the physical mask) - wavelength selector (red/ir/uv/yellow) to verify color byte order - scan command / full-face 2s / stop buttons, hex log of every write - intentionally not i18n'd; remove page before release
这个提交包含在:
@@ -0,0 +1,130 @@
|
||||
// TEMPORARY debug page for on-device verification (region↔IO mapping, color byte
|
||||
// order, scan wave bucketing, PD polarity). Guoguo-only tooling — intentionally
|
||||
// NOT i18n'd; remove this page before any release build.
|
||||
var ble = require('../../services/ble')
|
||||
var protocol = require('../../services/ble/protocol')
|
||||
|
||||
var WAVES = [
|
||||
{ key: 'red', code: 2, label: '红光' },
|
||||
{ key: 'ir', code: 1, label: '红外' },
|
||||
{ key: 'uv', code: 3, label: '紫外' },
|
||||
{ key: 'yellow', code: 4, label: '暖黄' }
|
||||
]
|
||||
var REGION_LABELS = { 1: '左区/IO1', 2: '中上/IO2', 4: '中区/IO3', 8: '中下/IO4', 16: '右区/IO5' }
|
||||
var RUN_STATES = { 0: 'IDLE', 1: '检测', 2: '治疗', 255: '故障(0xFF)' }
|
||||
|
||||
function hex(bytes) {
|
||||
return bytes.map(function (b) { return ('0' + b.toString(16)).slice(-2).toUpperCase() }).join(' ')
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
statusBarHeight: 44,
|
||||
connected: false,
|
||||
waves: WAVES,
|
||||
selectedWave: 'red',
|
||||
// live FFE4 status
|
||||
pd: [], vbat: 0, battery: 0, fitting: -1, scanWave: '-', runState: '-', frames: 0,
|
||||
logs: []
|
||||
},
|
||||
|
||||
onLoad: function () {
|
||||
this.setData({ statusBarHeight: getApp().globalData.statusBarHeight })
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
var self = this
|
||||
self.setData({ connected: ble.isConnected() })
|
||||
self._onAdc = function (d) {
|
||||
self.setData({
|
||||
pd: d.pd || [],
|
||||
vbat: d.vbat || 0,
|
||||
battery: d.battery || 0,
|
||||
fitting: d.fitting,
|
||||
scanWave: d.scan_wave || '-',
|
||||
runState: RUN_STATES[d.run_state] !== undefined ? RUN_STATES[d.run_state] : String(d.run_state),
|
||||
frames: self.data.frames + 1
|
||||
})
|
||||
}
|
||||
ble.on('adc', self._onAdc)
|
||||
},
|
||||
|
||||
onHide: function () { this._cleanup() },
|
||||
onUnload: function () { this._cleanup() },
|
||||
_cleanup: function () {
|
||||
if (this._onAdc) { ble.off('adc', this._onAdc); this._onAdc = null }
|
||||
},
|
||||
|
||||
onBack: function () {
|
||||
wx.navigateBack({ fail: function () { wx.switchTab({ url: '/pages/profile/profile' }) } })
|
||||
},
|
||||
|
||||
_log: function (msg) {
|
||||
var logs = this.data.logs
|
||||
logs.unshift(new Date().toTimeString().slice(0, 8) + ' ' + msg)
|
||||
if (logs.length > 20) logs.pop()
|
||||
this.setData({ logs: logs })
|
||||
},
|
||||
|
||||
_send: function (label, options) {
|
||||
var self = this
|
||||
if (!ble.isConnected()) {
|
||||
self.setData({ connected: false })
|
||||
wx.showToast({ title: '设备未连接', icon: 'none' })
|
||||
return
|
||||
}
|
||||
var bytes = protocol.buildVendorCommand(options)
|
||||
self._log(label)
|
||||
self._log('→ ' + hex(bytes))
|
||||
ble.setParams(options).then(function () {
|
||||
self._log('✓ 写入成功')
|
||||
}).catch(function (err) {
|
||||
self._log('✗ 写入失败: ' + ((err && err.msg) || JSON.stringify(err)))
|
||||
})
|
||||
},
|
||||
|
||||
onSelectWave: function (e) {
|
||||
this.setData({ selectedWave: e.currentTarget.dataset.key })
|
||||
},
|
||||
|
||||
_waveCode: function () {
|
||||
var key = this.data.selectedWave
|
||||
for (var i = 0; i < WAVES.length; i++) if (WAVES[i].key === key) return WAVES[i].code
|
||||
return 2
|
||||
},
|
||||
|
||||
// 点脸型图分区:该区 2 秒治疗(验证物理位置对不对)
|
||||
onTapRegion: function (e) {
|
||||
var mask = parseInt(e.currentTarget.dataset.mask)
|
||||
this._send('治疗 2s ' + REGION_LABELS[mask] + ' ' + this.data.selectedWave, {
|
||||
region_mask: mask, wavelength: this._waveCode(), brightness: 204,
|
||||
hold_time: 2, control: 0x02
|
||||
})
|
||||
},
|
||||
|
||||
// 检测指令(与 auto-scan 同参:红光 128 全脸,设备自跑序贯扫描)
|
||||
onScanCmd: function () {
|
||||
this._send('检测指令 control=0x01', {
|
||||
region_mask: 0x1F, wavelength: 2, brightness: 128,
|
||||
hold_time: 0, control: 0x01
|
||||
})
|
||||
},
|
||||
|
||||
// 全脸当前波长 2 秒
|
||||
onTreatAll: function () {
|
||||
this._send('治疗 2s 全脸 ' + this.data.selectedWave, {
|
||||
region_mask: 0x1F, wavelength: this._waveCode(), brightness: 204,
|
||||
hold_time: 2, control: 0x02
|
||||
})
|
||||
},
|
||||
|
||||
// 停止 / IDLE
|
||||
onStop: function () {
|
||||
var self = this
|
||||
self._log('停止 → IDLE 全零帧')
|
||||
ble.stopTreatment().then(function () { self._log('✓ 已停止') })
|
||||
.catch(function (err) { self._log('✗ 停止失败: ' + ((err && err.msg) || '')) })
|
||||
},
|
||||
|
||||
onClearLog: function () { this.setData({ logs: [], frames: 0 }) }
|
||||
})
|
||||
在新工单中引用
屏蔽一个用户