You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DiFluid R2: negative TDS decoded as ~655 % (concentration field is signed int16) #980
The native DiFluid R2 driver currently decodes the concentration/TDS field as unsigned. In difluid_r2_protocol.dart, _parseTds uses _readUint16(data, 1) / 100.0.
DiFluid's protocol document (protocolR2.md) shows the concentration field as a signed 16-bit value ×100. Its own Average example contains FF F9, which represents -0.07.
Negative readings around zero are valid. With the current native decoder, FF F9 becomes 655.29 % and is exposed that way through the Sensors API.
Expected
Decode the concentration/TDS field as signed int16, so FF F9 becomes -0.07.
Do not change refractive-index signedness as part of this issue. The signed concentration behavior is supported by the protocol example; there is not equivalent justification for treating the RI field as signed.
Scope
Keep this as a minimal correctness fix for the existing native fallback:
decode concentration/TDS as signed int16;
add a protocol regression test using a negative concentration packet;
preserve existing positive TDS and RI decoding behavior.
No broader DiFluid R2 feature work should be added to the native implementation here.
Driver-runtime direction
Longer-term DiFluid R2 development is moving to the JS BLE Sensor driver runtime. #977 tracks that work, including native Average support.
The native R2 implementation remains useful as a fallback for now, so it should still decode valid readings correctly while that migration is in progress. Once the JS driver has feature parity, automated coverage and real-hardware validation, we can separately retire the native implementation.
A regression test covers the negative concentration case.
Hardware confirmation is welcome but is not required to establish this parser bug because the protocol example itself exercises the signed representation.
Maintainer direction: the minimal native fix is accepted. Please keep the change to signed int16 concentration/TDS decoding plus its regression test; do not change RI signedness in this PR. Broader R2 work is being moved to the JS BLE Sensor driver tracked in #977.
Activity
tadelv commentedon Oct 12, 2026
Maintainer direction: the minimal native fix is accepted. Please keep the change to signed int16 concentration/TDS decoding plus its regression test; do not change RI signedness in this PR. Broader R2 work is being moved to the JS BLE Sensor driver tracked in #977.