Class WeightMeasurement
java.lang.Object
com.codename1.health.sensors.WeightMeasurement
A decoded Weight Measurement, characteristic 0x2A9D.
Wire format
Byte 0 is a flags field:
| Bit | Meaning |
|---|---|
| 0 | units: 0 = SI (kg), 1 = Imperial (lb) |
| 1 | timestamp present |
| 2 | user id present |
| 3 | BMI and height present |
followed by a uint16 weight and the optional fields.
The resolution depends on the unit
The raw uint16 is scaled by 0.005 kg in SI mode and 0.01 lb
in Imperial mode -- not the same multiplier, and not a simple unit
conversion applied afterwards. Getting this wrong yields a weight that
is wrong by a factor of about two, which is exactly close enough to
look plausible. Height carries the same split: 0.001 m against 0.1 in.
Like all characteristics here this one is indicated, not notified.
-
Method Summary
Modifier and TypeMethodDescriptiondoublegetBmi()The body mass index the scale computed, orDouble.NaNwhen absent.doubleThe height in metres, orDouble.NaNwhen absent.longThe scale's own timestamp in epoch millis, or-1when absent.intThe scale's user-profile index, or-1when absent.doubleThe weight in kilograms, converted from pounds when the scale reported Imperial units.booleantruewhen this reading carried BMI and height.booleantruewhen the scale transmitted Imperial units.static WeightMeasurementparse(byte[] value) Decodes a0x2A9Dvalue.toString()Returns a string representation of the object.
-
Method Details
-
parse
Decodes a0x2A9Dvalue. Returnsnullfor a malformed or truncated payload; never throws. -
getWeightKg
public double getWeightKg()The weight in kilograms, converted from pounds when the scale reported Imperial units. -
isImperial
public boolean isImperial()truewhen the scale transmitted Imperial units. Useful for matching the user's own display preference; the value returned bygetWeightKg()is already normalized either way. -
getHeightMeters
public double getHeightMeters()The height in metres, orDouble.NaNwhen absent. -
getBmi
public double getBmi()The body mass index the scale computed, orDouble.NaNwhen absent. -
hasBmiAndHeight
public boolean hasBmiAndHeight()truewhen this reading carried BMI and height. -
getUserId
public int getUserId()The scale's user-profile index, or-1when absent. Family scales use it to attribute a reading. -
getTimestampMillis
public long getTimestampMillis()The scale's own timestamp in epoch millis, or-1when absent. -
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
-