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 ble = require('../../services/ble')
|
||||||
|
var FITTING_TIMEOUT = 10000
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
statusBarHeight: 44,
|
statusBarHeight: 44,
|
||||||
@@ -31,8 +33,15 @@ Page({
|
|||||||
this.checkWearing()
|
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 () {
|
checkWearing: function () {
|
||||||
var self = this
|
var self = this
|
||||||
|
self._cleanup()
|
||||||
self.setData({ checking: true, result: null, error: '' })
|
self.setData({ checking: true, result: null, error: '' })
|
||||||
|
|
||||||
if (!ble.isConnected()) {
|
if (!ble.isConnected()) {
|
||||||
@@ -40,33 +49,31 @@ Page({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var protocol = require('../../services/ble/protocol')
|
self.setData({ connected: true })
|
||||||
if (protocol.PROTOCOL_MODE === 'vendor_33') {
|
|
||||||
self.setData({ checking: false, result: 'ok', connected: true })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._onStatus) ble.off('status', this._onStatus)
|
self._onBattery = function (info) {
|
||||||
this._onStatus = function (status) {
|
self.setData({ battery: info.battery })
|
||||||
self.setData({ checking: false })
|
|
||||||
if (status.battery !== undefined) {
|
|
||||||
self.setData({ battery: status.battery, connected: true })
|
|
||||||
}
|
}
|
||||||
if (status.bind_status === 1) {
|
ble.on('battery', self._onBattery)
|
||||||
self.setData({ result: 'ok' })
|
|
||||||
} else {
|
|
||||||
self.setData({ result: 'fail', error: '请确认设备已正确佩戴' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ble.on('status', this._onStatus)
|
|
||||||
|
|
||||||
ble.queryStatus().catch(function (err) {
|
self._onFitting = function (data) {
|
||||||
self.setData({ checking: false, result: 'fail', error: err.error_msg || '查询失败' })
|
console.log('[WEAR] 贴合状态:', data.fitting)
|
||||||
})
|
if (data.fitting === 1) {
|
||||||
|
self._cleanup()
|
||||||
|
self.setData({ checking: false, result: 'ok' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ble.on('fitting', self._onFitting)
|
||||||
|
|
||||||
|
self._fittingTimer = setTimeout(function () {
|
||||||
|
if (self.data.result) return
|
||||||
|
self._cleanup()
|
||||||
|
self.setData({ checking: false, result: 'fail', error: '未检测到贴合,请确认设备已正确佩戴' })
|
||||||
|
}, FITTING_TIMEOUT)
|
||||||
},
|
},
|
||||||
|
|
||||||
onUnload: function () {
|
onUnload: function () {
|
||||||
if (this._onStatus) ble.off('status', this._onStatus)
|
this._cleanup()
|
||||||
clearTimeout(this._reconnectTimer)
|
clearTimeout(this._reconnectTimer)
|
||||||
ble.stopScan()
|
ble.stopScan()
|
||||||
},
|
},
|
||||||
@@ -103,6 +110,5 @@ Page({
|
|||||||
self.setData({ checking: false, result: 'fail', error: '搜索超时,请确认设备已开机' })
|
self.setData({ checking: false, result: 'fail', error: '搜索超时,请确认设备已开机' })
|
||||||
}, 15000)
|
}, 15000)
|
||||||
}, 500)
|
}, 500)
|
||||||
},
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户