# Class WeightMeasurement

java.lang.Object
com.codename1.health.sensors.WeightMeasurement

public final class WeightMeasurement extends Object

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 Type
  Method
  Description
  `double`
  `getBmi()`
  The body mass index the scale computed, or `Double.NaN` when absent.
  `double`
  `getHeightMeters()`
  The height in metres, or `Double.NaN` when absent.
  `long`
  `getTimestampMillis()`
  The scale's own timestamp in epoch millis, or `-1` when absent.
  `int`
  `getUserId()`
  The scale's user-profile index, or `-1` when absent.
  `double`
  `getWeightKg()`
  The weight in kilograms, converted from pounds when the scale reported Imperial units.
  `boolean`
  `hasBmiAndHeight()`
  `true` when this reading carried BMI and height.
  `boolean`
  `isImperial()`
  `true` when the scale transmitted Imperial units.
  `static WeightMeasurement`
  `parse(byte[] value)`
  Decodes a `0x2A9D` value.
  `String`
  `toString()`
  Returns a string representation of the object.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Method Details

  - ### parse

    public static WeightMeasurement parse(byte[] value)
    Decodes a `0x2A9D` value. Returns `null` for 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()
    `true` when the scale transmitted Imperial units. Useful for matching the user's own display preference; the value returned by `getWeightKg()` is already normalized either way.

  - ### getHeightMeters

    public double getHeightMeters()
    The height in metres, or `Double.NaN` when absent.

  - ### getBmi

    public double getBmi()
    The body mass index the scale computed, or `Double.NaN` when absent.

  - ### hasBmiAndHeight

    public boolean hasBmiAndHeight()

    `true` when this reading carried BMI and height.

    Both, as the name says. The two fields are optional independently -- each carries its own `0xFFFF` unavailable value and a scale that measured one but not the other sends both -- so testing only the BMI let a caller that gated on this go on to use a height of `NaN`.

  - ### getUserId

    public int getUserId()
    The scale's user-profile index, or `-1` when absent. Family scales use it to attribute a reading.

  - ### getTimestampMillis

    public long getTimestampMillis()
    The scale's own timestamp in epoch millis, or `-1` when absent.

  - ### toString

    public String toString()
    Description copied from class: `Object`
    Returns 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())
    Overrides:
      `toString` in class `Object`