Calibrate S300 tail RPM decode

This commit is contained in:
HVBT Dev 2026-07-28 01:35:04 +05:30
parent ba578a0b69
commit c2f92db217
2 changed files with 6 additions and 4 deletions

View File

@ -45,8 +45,9 @@ SensorState parseS300(Uint8List frame, {bool validateChecksum = true}) {
final bool hasTailPayload = _hasS300TailPayload(frame);
final int rpmRaw =
hasTailPayload ? _readUint16LE(frame, 82) : _readUint16BE(frame, 2);
final double rpm =
(hasTailPayload ? rpmRaw : rpmRaw - 256).clamp(0, 12000).toDouble();
final double rpm = (hasTailPayload ? rpmRaw - 1089 : rpmRaw - 256)
.clamp(0, 12000)
.toDouble();
// VSS: bytes 5..6 little-endian pulse period.
final int vssRaw = _readUint16LE(frame, 5);

View File

@ -190,7 +190,8 @@ void main() {
expect(isS300PlaceholderFrame(frame), isTrue);
});
test('uses tail payload RPM for S300 Bluetooth prefix frames', () {
test('uses calibrated tail payload RPM for S300 Bluetooth prefix frames',
() {
final frame = Uint8List(128);
final prefix = [
0x1B,
@ -219,7 +220,7 @@ void main() {
frame[127] = calculateNeg8(frame.sublist(0, 127));
final state = parseS300(frame);
expect(state.rpm, equals(3122.0));
expect(state.rpm, equals(2033.0));
});
});
}