Skip to content

Commit ebe60ef

Browse files
authored
Fix for Mi Scale 2 measurements not being considered (#1349)
1 parent 4b61252 commit ebe60ef

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales

android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/MiScaleHandler.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,19 @@ class MiScaleHandler : ScaleDeviceHandler() {
270270
return
271271
}
272272

273-
// Response to only last: 0x01 <count> FF FF <uniqHi> <uniqLo>
273+
// Response to "only last" or "all": 0x01 <count> 0x00 <marker/echo bytes...>
274274
if (d.size >= 6 && d[0] == 0x01.toByte()) {
275275
val count = d[1].toInt() and 0xFF
276-
// Accept FF FF and 00 00
277276
val marker = (d[2].toInt() and 0xFF) shl 8 or (d[3].toInt() and 0xFF)
278277
if (marker == 0xFFFF || marker == 0x0000) {
279278
pendingHistoryCount = count
279+
histBufReset() // Discard any stale bytes (e.g. magic-echo) before history data arrives.
280280
logI("History count announced (marker=${marker.toString(16)}): $pendingHistoryCount")
281-
return
281+
} else {
282+
// Control response (e.g. magic-echo) with unrecognized marker — discard, not history data.
283+
logD("Ignoring control response (marker=${marker.toString(16)}, len=${d.size}): ${d.toHexPreview(16)}")
282284
}
285+
return
283286
}
284287

285288
// Live frames (13B) or combined (26B)

0 commit comments

Comments
 (0)