Hi, I have a service native app that is reading the HR every second and stores it in a file.
I use the SENSOR_OPTION_ALWAYS_ON option but I noticed that I don't get a reading every second, the readings seems to be paused from time to time.
What am I doing wrong?
Here is my callback function:
static void on_sensor_event(sensor_h sensor, sensor_event_s *event, void *data)
{
char *str = NULL;
unsigned long long timestamp;
sensor_type_e type;
size_t length = 0;
get_timestamp_ms(×tamp);
sensor_get_type(sensor, &type);
length = snprintf(ret, 0, format, event->values[0], timestamp, event->accuracy);
str = (char*)malloc(++length);
if (!str)
return ;
sprintf(str, "%.0f,%llu,%i\n", event->values[0], timestamp, event->accuracy);
store_data_in_file((t_env*)data, type, str);
free(str);
str = NULL;
}
Here is my code to create the sensor and register the listener:
sensor_type_e type = SENSOR_HRM;
sensor_is_supported(type, &is_supported);
if (!is_supported)
continue ;
if (sensor_get_default_sensor(type, &sensor) != SENSOR_ERROR_NONE)
continue ;
if (sensor_create_listener(sensor, listener) == SENSOR_ERROR_NONE)
if (sensor_listener_set_event_cb(listener, 1000, on_sensor_event, env) == SENSOR_ERROR_NONE)
if (sensor_listener_set_option(listener, SENSOR_OPTION_ALWAYS_ON) == SENSOR_ERROR_NONE)
if (sensor_listener_start(listener) == SENSOR_ERROR_NONE)
{
//INIT SOME VARIABLES
}
Thanks for your help!