diff --git a/miniprogram/services/ble/connection.js b/miniprogram/services/ble/connection.js index 1dad359..0ef5ccf 100644 --- a/miniprogram/services/ble/connection.js +++ b/miniprogram/services/ble/connection.js @@ -98,8 +98,14 @@ function handleValueChange(res) { console.warn('[BLE] ADC checksum mismatch, dropping') return } - emit('adc', { pd: parsed.pd, vbat: vbatMv, battery: batteryPct }) + emit('adc', { pd: parsed.pd, vbat: vbatMv, battery: batteryPct, fitting: parsed.fitting, run_state: parsed.run_state }) emit('battery', { battery: batteryPct, vbat: vbatMv }) + if (parsed.fitting !== -1) { + emit('fitting', { fitting: parsed.fitting }) + } + if (parsed.run_state !== -1) { + emit('run_state', { run_state: parsed.run_state }) + } return } diff --git a/miniprogram/services/ble/protocol.js b/miniprogram/services/ble/protocol.js index b0a81c8..fc1c6b4 100644 --- a/miniprogram/services/ble/protocol.js +++ b/miniprogram/services/ble/protocol.js @@ -199,6 +199,23 @@ function parseVendorStatus(buffer) { if (bytes.length === 1) { return { type: 'heartbeat', heartbeat: bytes[0], is_heartbeat: true, raw_hex: bytesToHex(bytes) } } + if (bytes.length === 19) { + var checksum19 = xorChecksum(bytes.slice(0, 18)) + var pds19 = [] + for (var p = 0; p < 7; p++) { + pds19.push(bytes[p * 2] | (bytes[p * 2 + 1] << 8)) + } + return { + type: 'adc', + is_heartbeat: false, + pd: pds19, + vbat: bytes[14] | (bytes[15] << 8), + fitting: bytes[16], + run_state: bytes[17], + checksum_ok: checksum19 === bytes[18], + raw_hex: bytesToHex(bytes) + } + } if (bytes.length === 17) { var checksum = xorChecksum(bytes.slice(0, 16)) var pds = [] @@ -210,6 +227,8 @@ function parseVendorStatus(buffer) { is_heartbeat: false, pd: pds, vbat: bytes[14] | (bytes[15] << 8), + fitting: -1, + run_state: -1, checksum_ok: checksum === bytes[16], raw_hex: bytesToHex(bytes) }