feat: wear-check uses FFE4 fitting status instead of hardcoded ok
Listen for 'fitting' event from FFE4 Byte17 (0=not fitted, 1=fitted). 10s timeout if no fitting signal received. Removes vendor_33 bypass that always returned ok.
这个提交包含在:
@@ -1,4 +1,6 @@
|
||||
var ble = require('../../services/ble')
|
||||
var FITTING_TIMEOUT = 10000
|
||||
|
||||
Page({
|
||||
data: {
|
||||
statusBarHeight: 44,
|
||||
@@ -31,8 +33,15 @@ Page({
|
||||
this.checkWearing()
|
||||
},
|
||||
|
||||
_cleanup: function () {
|
||||
if (this._onFitting) { ble.off('fitting', this._onFitting); this._onFitting = null }
|
||||
if (this._onBattery) { ble.off('battery', this._onBattery); this._onBattery = null }
|
||||
if (this._fittingTimer) { clearTimeout(this._fittingTimer); this._fittingTimer = null }
|
||||
},
|
||||
|
||||
checkWearing: function () {
|
||||
var self = this
|
||||
self._cleanup()
|
||||
self.setData({ checking: true, result: null, error: '' })
|
||||
|
||||
if (!ble.isConnected()) {
|
||||
@@ -40,33 +49,31 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
var protocol = require('../../services/ble/protocol')
|
||||
if (protocol.PROTOCOL_MODE === 'vendor_33') {
|
||||
self.setData({ checking: false, result: 'ok', connected: true })
|
||||
return
|
||||
}
|
||||
self.setData({ connected: true })
|
||||
|
||||
if (this._onStatus) ble.off('status', this._onStatus)
|
||||
this._onStatus = function (status) {
|
||||
self.setData({ checking: false })
|
||||
if (status.battery !== undefined) {
|
||||
self.setData({ battery: status.battery, connected: true })
|
||||
}
|
||||
if (status.bind_status === 1) {
|
||||
self.setData({ result: 'ok' })
|
||||
} else {
|
||||
self.setData({ result: 'fail', error: '请确认设备已正确佩戴' })
|
||||
self._onBattery = function (info) {
|
||||
self.setData({ battery: info.battery })
|
||||
}
|
||||
ble.on('battery', self._onBattery)
|
||||
|
||||
self._onFitting = function (data) {
|
||||
console.log('[WEAR] 贴合状态:', data.fitting)
|
||||
if (data.fitting === 1) {
|
||||
self._cleanup()
|
||||
self.setData({ checking: false, result: 'ok' })
|
||||
}
|
||||
}
|
||||
ble.on('status', this._onStatus)
|
||||
ble.on('fitting', self._onFitting)
|
||||
|
||||
ble.queryStatus().catch(function (err) {
|
||||
self.setData({ checking: false, result: 'fail', error: err.error_msg || '查询失败' })
|
||||
})
|
||||
self._fittingTimer = setTimeout(function () {
|
||||
if (self.data.result) return
|
||||
self._cleanup()
|
||||
self.setData({ checking: false, result: 'fail', error: '未检测到贴合,请确认设备已正确佩戴' })
|
||||
}, FITTING_TIMEOUT)
|
||||
},
|
||||
|
||||
onUnload: function () {
|
||||
if (this._onStatus) ble.off('status', this._onStatus)
|
||||
this._cleanup()
|
||||
clearTimeout(this._reconnectTimer)
|
||||
ble.stopScan()
|
||||
},
|
||||
@@ -103,6 +110,5 @@ Page({
|
||||
self.setData({ checking: false, result: 'fail', error: '搜索超时,请确认设备已开机' })
|
||||
}, 15000)
|
||||
}, 500)
|
||||
},
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
在新工单中引用
屏蔽一个用户