Skip to content

Instantly share code, notes, and snippets.

@Artaud
Created May 29, 2020 13:56
Show Gist options
  • Save Artaud/d530cbfb296d636823f2ccdcc52f72f4 to your computer and use it in GitHub Desktop.
Save Artaud/d530cbfb296d636823f2ccdcc52f72f4 to your computer and use it in GitHub Desktop.
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");
       }
   }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment