Accelerometer data format API

Hi. May I know, in what format does SleepAsAndroid expect to get data from com.urbandroid.sleep.watch.DATA_UPDATE intent?

Send movement data
Intent : com.urbandroid.sleep.watch.DATA_UPDATE
Extras:
MAX_DATA (float array): Array containing latest MAX values from the watch.
MAX_RAW_DATA (float array): Array containing a geometric average of latest MAX values from the watch.

This sentence from documentation is a bit confused:

The values to be aggregated should be changes in raw accelerometer data expressed in m/s2.

Do both MAX_DATA (float array) and MAX_RAW_DATA (float array) and x/y/z from pseudocode have to be in m/s?

  on_sensor_change() {
  
  x = sensor.x;
  y = sensor.y;
  z = sensor.z;

  max = abs(x - lastX) + abs(y - lastY) + abs(z - lastZ);
  if (max > current_max_data) {
    current_max_data = max;
  }

  max_raw = sqrt((x * x) + (y * y) + (z * z));
  if (max_raw > current_max_raw_data) {
    current_max_raw_data = max_raw;
  }

  lastX = x;
  lastY = y;
  lastZ = z;
}

According to Garmin Addon source code:
MAX_DATA has to be in milli-G-units (G * 1000)
MAX_RAW_DATA has to be in m/s2

Am I right?

Yes, your assumptions are correct.
However the max_data is actually legacy api - it will suffice to send only max_raw_data. Sleep supports both but prefers the raw format when receiving both.

1 Like

Looks like Accelerometer API documentation lacks some information.
I see Sleep-as-Android-GearSx-Addon send additional extra data to SleepAsAndroid app like:

  1. MIN_DATA
  2. AVG_DATA

May I know the purpose of this and how it affects sleep report?

Those are unused. They are leftovers in the addon from early versions of Sleep. We should get rid of them.

1 Like