1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-18 22:41:44 +02:00

Reuse Converters.fromUnsignedInt24Le() to implement getBase10Float().

From the observed data, it's not clear whether the mantissa should be
interpreted as signed or not. Since two metrics encoded as base-10 floats
(weight and resistance) cannot be negative, and the Trisa Health Vital app
interprets the mantissa as unsigned, we will treat it as unsigned here, too.
This commit is contained in:
Maks Verver
2018-10-13 14:13:02 +02:00
parent b17c1971fb
commit 303aedb4e7

View File

@@ -51,8 +51,7 @@ public class TrisaBodyAnalyzeLib {
* @throws IndexOutOfBoundsException if {@code offset < 0} or {@code offset + 4> data.length} * @throws IndexOutOfBoundsException if {@code offset < 0} or {@code offset + 4> data.length}
*/ */
public static double getBase10Float(byte[] data, int offset) { public static double getBase10Float(byte[] data, int offset) {
int mantissa = (data[offset] & 0xff) | ((data[offset + 1] & 0xff) << 8) | int mantissa = Converters.fromUnsignedInt24Le(data, offset);
((data[offset + 2] & 0xff) << 16);
int exponent = data[offset + 3]; // note: byte is signed. int exponent = data[offset + 3]; // note: byte is signed.
return mantissa * Math.pow(10, exponent); return mantissa * Math.pow(10, exponent);
} }