Languages

Menu
Sites
Language
SENSOR_OPTION_ALWAYS_ON not working

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(&timestamp);
	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!

 

Responses

4 Replies
Armaan-Ul- Islam

First of all every sensor requires a minimum interval to response again, You can check this for your case using sensor_get_min_interval() function and use the output from the function as your interval.

 

int sensor_get_min_interval (
    sensor_h  sensor,
    int *      min_interval
    )  

 

Example Code:

int *minInterval;

if(sensor_get_min_interval(sensor,&minInterval) == SENSOR_ERROR_NONE ){
    //use *minInterval;
}

 

Link: https://developer.tizen.org/development/api-references/native-application?redirect=/dev-guide/3.0.0/org.tizen.native.wearable.apireference/group__CAPI__SYSTEM__SENSOR__MODULE.html#ga98b249ae9ac453cecf54a3687ec44cb1

 

You can use sensor_listener_set_interval() function to set specific interval.

int sensor_listener_set_interval (   
    sensor_listener_h          listener,
    unsigned int       interval_ms
    )  

 

Link: https://developer.tizen.org/development/api-references/native-application?redirect=https://developer.tizen.org/dev-guide/3.0.0/org.tizen.native.wearable.apireference/group__CAPI__SYSTEM__SENSOR__LISTENER__MODULE.html#ga32f88b4d08ae4c373dd83648a05613f6

 

Fanny Huang

Hi, thanks for your reply !


The minimum interval for the HRM is 1ms, I tried to set the interval to 1000ms and even 5000ms with sensor_listener_set_interval()
but it doesn’t seem to work: I got ~300 values over 12 hours of testing with an interval set to 5000ms.
Would it be because the device enters in sleep mode even if SENSOR_OPTION_ALWAYS_ON is set? Looks like it just stops calling the sensor callback.
Is the problem really coming from the interval? Or could it be because SENSOR_OPTION_ALWAYS_ON is not working somehow, and then how can I get it to work?


Thanks.

 

Fanny Huang

Hi, thanks for your reply !


The minimum interval for the HRM is 1ms, I tried to set the interval to 1000ms and even 5000ms with sensor_listener_set_interval()
but it doesn’t seem to work: I got ~300 values over 12 hours of testing with an interval set to 5000ms.
Would it be because the device enters in sleep mode even if SENSOR_OPTION_ALWAYS_ON is set? Looks like it just stops calling the sensor callback.
Is the problem really coming from the interval? Or could it be because SENSOR_OPTION_ALWAYS_ON is not working somehow, and then how can I get it to work?


Thanks.

 

Armaan-Ul- Islam

You can request the resource CPU to be dedicated for your application using Power API. By this way you can force the sensor to read data and hit the callback.

Don't forget to release the resource once the purpose is served.

 

int device_power_request_lock ( power_lock_e type,int timeout_ms) 	
int device_power_release_lock ( power_lock_e type )

 

Add display privilege in tizen-manifest.xml file.

<privilege>http://tizen.org/privilege/display</privilege>

 

Please check out the Tizen Naitve Power API reference for details implementation.

Link:

https://developer.tizen.org/development/api-references/native-application?redirect=/dev-guide/2.3.0/org.tizen.native.mobile.apireference/group__CAPI__SYSTEM__DEVICE__POWER__MODULE.html#gabc47c58cfcfdaaba177f6004d6395af2