Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/src/miscale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
//
// STORED HISTORY (both scales) — on [kMiScaleHistoryChar], notify + write:
// host `01 <user id u32 LE>` how many records for this user
// scale `01 <count u16 LE>`
// scale `01 <count u16 LE>` (the XMTZC05HM appends four more bytes,
// seen as `01 00 00 00` after a request for
// user 1; their meaning is not established)
// host `02` send them (skipped when count is 0)
// scale records: 10-byte Scale 2 records, or 13-byte frames laid out as
// 0x2A9C on the composition scale; a notification of one byte or
Expand Down Expand Up @@ -144,9 +146,14 @@ List<int> miScaleHistoryRequest(int userId) => [
(userId >> 24) & 0xff,
];

/// The record count in the scale's `01 <count u16 LE>` answer, or null.
/// The record count in the scale's `01 <count u16 LE>` answer, or null. The
/// Mi Body Composition Scale 2 (XMTZC05HM) answers with 7 bytes: the same
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
/// three, then four more (seen as `01 00 00 00` after a request for user 1;
/// whether that is the user id is not established, so it is not validated).
int? miScaleHistoryCount(List<int> b) =>
b.length == 3 && b[0] == 0x01 ? b[1] | (b[2] << 8) : null;
(b.length == 3 || b.length == 7) && b[0] == 0x01
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
? b[1] | (b[2] << 8)
: null;

const List<int> kMiScaleHistorySend = [0x02];

Expand Down
5 changes: 5 additions & 0 deletions test/thermometer_scale_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ void main() {
expect(miScaleHistoryRequest(0x01020304), [1, 4, 3, 2, 1]);
expect(miScaleHistoryCount([0x01, 0x02, 0x01]), 258);
expect(miScaleHistoryCount([0x01, 0x02]), isNull);
// Captured from a real XMTZC05HM: counts 2, 3 and 4 (tail 01 00 00 00).
expect(miScaleHistoryCount([1, 2, 0, 1, 0, 0, 0]), 2);
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
expect(miScaleHistoryCount([1, 3, 0, 1, 0, 0, 0]), 3);
expect(miScaleHistoryCount([1, 4, 0, 1, 0, 0, 0]), 4);
expect(miScaleHistoryCount([1, 2, 0, 1, 0]), isNull);
expect(miScaleHistoryDone([0x03]), isTrue);
expect(miScaleHistoryDone([]), isTrue);
expect(miScaleHistoryDone([0x03, 0]), isFalse);
Expand Down
Loading