Search code examples
tizentizen-wearable-sdktizen-native-app

How to implement sensor batching on Tizen


I need to get the data from accelerometer on Tizen Wearable (ideally 3.0 or below) in a batched manner for maximum battery efficiency.

The relevant apidoc is here.

My current code looks like this:

static void start_accelerometer() {
    sensor_type_e type = SENSOR_ACCELEROMETER;
    int max_batch_latency = 30000; // 300 is max queue, 100 ms is default period

    if (sensor_get_default_sensor(type, &sensor) == SENSOR_ERROR_NONE)
    {
        if (sensor_create_listener(sensor, &listener) == SENSOR_ERROR_NONE
            && sensor_listener_set_max_batch_latency(listener, max_batch_latency) == SENSOR_ERROR_NONE
            && sensor_listener_set_event_cb(listener, 100, accelerometer_sensor_event_callback, NULL) == SENSOR_ERROR_NONE
            && sensor_listener_set_option(listener, SENSOR_OPTION_ALWAYS_ON) == SENSOR_ERROR_NONE
            )
        {
            if (sensor_listener_start(listener) == SENSOR_ERROR_NONE)
            {
                dlog_print(DLOG_INFO, TAG, "Sensor started");
            }
        }
    }
}

I have tried numerous variations of the above (like settings sensor_listener_set_option to SENSOR_OPTION_DEFAULT to have it pause on display off, starting the sensor without setting event callback and reading data manually) - but in all cases I never get the batched values from the sensor (either in the callback or through sensor_listener_read_data()). I'm always getting only the most recent data.

Do you know how to get batched data from accelerometer on Tizen wearables?

P.S. I'm using Galaxy Watch Active 1 for development.


Solution

  • As far as I know, the physical sensors work in a batch manner only when the AP goes into a suspend state, it only occurs while the display is off. So, after the display turns off, wait for 10 to 30 minutes before checking. Also, please set enough intervals(about 1000ms) to avoid too much flush.

    Lastly, using sensor_listener_read_data(), you can get only the most recent data.