fix: ADC notifications no longer emit 'status' (prevents timer jump)
- ADC (17-byte) now emits 'adc' + 'battery' events, not 'status' - Fixes CRITICAL timer jump: remaining_ms:0 was resetting countdown - Drop ADC packets with bad XOR checksum - treating.js + index.js subscribe to 'battery' for live battery updates - onStatus only updates remaining_ms when > 0
这个提交包含在:
@@ -21,7 +21,9 @@ Page({
|
|||||||
this.setData({ devMode: config.__DEV__ || false })
|
this.setData({ devMode: config.__DEV__ || false })
|
||||||
this.checkState()
|
this.checkState()
|
||||||
this._onStatus = this.onBleStatus.bind(this)
|
this._onStatus = this.onBleStatus.bind(this)
|
||||||
|
this._onBattery = this.onBleBattery.bind(this)
|
||||||
ble.on('status', this._onStatus)
|
ble.on('status', this._onStatus)
|
||||||
|
ble.on('battery', this._onBattery)
|
||||||
},
|
},
|
||||||
|
|
||||||
_cleanup: function () {
|
_cleanup: function () {
|
||||||
@@ -29,6 +31,10 @@ Page({
|
|||||||
ble.off('status', this._onStatus)
|
ble.off('status', this._onStatus)
|
||||||
this._onStatus = null
|
this._onStatus = null
|
||||||
}
|
}
|
||||||
|
if (this._onBattery) {
|
||||||
|
ble.off('battery', this._onBattery)
|
||||||
|
this._onBattery = null
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onHide: function () {
|
onHide: function () {
|
||||||
@@ -78,6 +84,10 @@ Page({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onBleBattery: function (info) {
|
||||||
|
this.setData({ battery: info.battery, connected: true })
|
||||||
|
},
|
||||||
|
|
||||||
onConnectBle: function () {
|
onConnectBle: function () {
|
||||||
var self = this
|
var self = this
|
||||||
self.setData({ bleState: 'scanning' })
|
self.setData({ bleState: 'scanning' })
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ Page({
|
|||||||
this._onReconnectFailed = this.onReconnectFailed.bind(this)
|
this._onReconnectFailed = this.onReconnectFailed.bind(this)
|
||||||
this._sessionId = 'SESS_' + Date.now()
|
this._sessionId = 'SESS_' + Date.now()
|
||||||
|
|
||||||
|
this._onBattery = this.onBattery.bind(this)
|
||||||
ble.on('status', this._onStatus)
|
ble.on('status', this._onStatus)
|
||||||
|
ble.on('battery', this._onBattery)
|
||||||
ble.on('treatment_complete', this._onComplete)
|
ble.on('treatment_complete', this._onComplete)
|
||||||
ble.on('exception', this._onException)
|
ble.on('exception', this._onException)
|
||||||
ble.on('disconnected', this._onDisconnect)
|
ble.on('disconnected', this._onDisconnect)
|
||||||
@@ -68,6 +70,7 @@ Page({
|
|||||||
|
|
||||||
onUnload: function () {
|
onUnload: function () {
|
||||||
if (this._onStatus) ble.off('status', this._onStatus)
|
if (this._onStatus) ble.off('status', this._onStatus)
|
||||||
|
if (this._onBattery) ble.off('battery', this._onBattery)
|
||||||
if (this._onComplete) ble.off('treatment_complete', this._onComplete)
|
if (this._onComplete) ble.off('treatment_complete', this._onComplete)
|
||||||
if (this._onException) ble.off('exception', this._onException)
|
if (this._onException) ble.off('exception', this._onException)
|
||||||
if (this._onDisconnect) ble.off('disconnected', this._onDisconnect)
|
if (this._onDisconnect) ble.off('disconnected', this._onDisconnect)
|
||||||
@@ -104,16 +107,21 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onStatus: function (status) {
|
onStatus: function (status) {
|
||||||
var remaining = status.remaining_ms || 0
|
if (status.remaining_ms > 0) {
|
||||||
this.updateProgress(remaining)
|
this.updateProgress(status.remaining_ms)
|
||||||
|
}
|
||||||
this.setData({
|
this.setData({
|
||||||
battery: status.battery,
|
battery: status.battery || this.data.battery,
|
||||||
temperature: status.temperature,
|
temperature: status.temperature || this.data.temperature,
|
||||||
paused: status.mode_state === 0x03
|
paused: status.mode_state === 0x03
|
||||||
})
|
})
|
||||||
this.syncCommands()
|
this.syncCommands()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onBattery: function (info) {
|
||||||
|
this.setData({ battery: info.battery })
|
||||||
|
},
|
||||||
|
|
||||||
syncCommands: function () {
|
syncCommands: function () {
|
||||||
var app = getApp()
|
var app = getApp()
|
||||||
var device = app.globalData.currentDevice || {}
|
var device = app.globalData.currentDevice || {}
|
||||||
|
|||||||
@@ -94,20 +94,12 @@ function handleValueChange(res) {
|
|||||||
if (parsed.type === 'adc') {
|
if (parsed.type === 'adc') {
|
||||||
var vbatMv = parsed.vbat
|
var vbatMv = parsed.vbat
|
||||||
var batteryPct = Math.min(100, Math.max(0, Math.round((vbatMv - 3000) / (4200 - 3000) * 100)))
|
var batteryPct = Math.min(100, Math.max(0, Math.round((vbatMv - 3000) / (4200 - 3000) * 100)))
|
||||||
emit('status', {
|
if (!parsed.checksum_ok) {
|
||||||
mode_state: protocol.MODE_STATE.ACTIVE,
|
console.warn('[BLE] ADC checksum mismatch, dropping')
|
||||||
region_mask: protocol.REGION.FULL_FACE,
|
return
|
||||||
wavelength: 0,
|
}
|
||||||
brightness: 0,
|
emit('adc', { pd: parsed.pd, vbat: vbatMv, battery: batteryPct })
|
||||||
remaining_ms: 0,
|
emit('battery', { battery: batteryPct, vbat: vbatMv })
|
||||||
error_code: 0,
|
|
||||||
battery: batteryPct,
|
|
||||||
temperature: 0,
|
|
||||||
bind_status: 1,
|
|
||||||
subscription: 1,
|
|
||||||
pd: parsed.pd,
|
|
||||||
vbat: vbatMv
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户