언어 설정

Menu
Sites
Language
Tizen accelerometer sensor usage

Hi All,

I want to write an heathcare app on Tizen, such app looks like a steps encounter, which can record how many steps you're walked in a day. I searched on internet, seems many apps on android or ios are based on the accelerometer sensor. 

I expected a sample code!!! 

Did anyone have such experiense? Any suggestion are welcome! :)

 

Responses

13 댓글
Alex Dem

Hi,
Regarding sensors here is small tutorial only:
https://developer.tizen.org/dev-guide/2.3.0/org.tizen.tutorials/html/native/system/sensor_tutorial_n.htm
But as I remember there was for tizen  native 2.2.1 sensor sample (maybe it could be useful)
https://developer.tizen.org/dev-guide/2.2.1/org.tizen.native.appprogramming/html/tutorials/uix_tutorial/task_sensorapp.htm
Alexey.

colin Rao

Hi, Alex

Thanks!!!

I can get the accelerometer data by follow on the sample code on IDE help. Also, I find some sample code regarding of walk steps counter and port to Tizen.

but there is a new issue, because of my demo app is a UI app base on EFL. Seems the accelerometer sensor won't trigger the changed event if the screen was locked (black screen) or the UI app wasn't on the top screen. As the code, "on_sensor_event" won't be called if 1) screen was locked, 2) press Home key to hide it.

sensor_listener_set_event_cb(ad->listener, 100, on_sensor_event, data);

Is there a way to let a partial code of an UI app to executing in background? Or, package a native service app with a native UI app together?

Alex Dem

Hi,
Please check, maybe you terminate your app on press of home button ?
Also, if your app is in background  and the sensor_option_e = SENSOR_OPTION_DEFAULT 'on_sensor_event' should be called if any other app is on top, except cases when LCD is off and in the app is in power save mode ( see remark in sensor_listener_set_option api description )
Try to apply:
sensor_listener_set_option(listener, SENSOR_OPTION_ALWAYS_ON);
Alexey.

colin Rao

Hi Alex, 

Thanks! It's solved my issue via call sensor_listener_set_option(listener, SENSOR_OPTION_ALWAYS_ON); The sensor event callback will be called even though the screen is off, or the UI app was hidden by "home" key. 

colin Rao

one more question, how to set the display (screen) light always?

Alex Dem

Hi, 
For this case try to call this api periodically:
device_display_change_state (DISPLAY_STATE_NORMAL);
maybe you could try to use timer or use 
device_add_callback (device_callback_e type, device_changed_cb callback, void *user_data) with device_callback_e = DEVICE_CALLBACK_DISPLAY_STATE 
and check inside callback that display state was changed from DISPLAY_STATE_NORMAL to DISPLAY_STATE_SCREEN_DIM.
Alexey.

colin Rao

Hi, I've already do such testing,  but seems it's not working. 

Vikram

Make sure you add the display privilege in manifest. Example: <privilege>http://tizen.org/privilege/display</privilege>

colin Rao

seems device_power_wakeup works fine! Is it the right way?

static void
display_changed_cb(device_callback_e type, void *value, void *user_data){
    if(DEVICE_CALLBACK_DISPLAY_STATE == type) {
    	dlog_print(DLOG_INFO, LOG_TAG, "[device_changed_cb] display state: %d\n", (char*)value);
    	device_power_wakeup(EINA_FALSE);
    }
}

 

colin Rao

Alex & Vikram

Thanks! It's works fine! :)

static void
display_changed_cb(device_callback_e type, void *value, void *user_data){
    int error;
    if(DEVICE_CALLBACK_DISPLAY_STATE == type) {
    	dlog_print(DLOG_INFO, LOG_TAG, "[device_changed_cb] display state: %d\n", (char*)value);
    	error = device_display_change_state(DISPLAY_STATE_NORMAL);
    }
}

// register the display state changed callback
device_add_callback(DEVICE_CALLBACK_DISPLAY_STATE, display_changed_cb, NULL);

 

Alex Dem

Hi,
Ok, but just fyi;
One problem is that the 'dimmed screen' will be shown for a moment in your case.
Looks like minimum 'screen timeout' is 15 seconds (Settings ->Display), and to avoid dimmed screen you could try to set timer and set state DISPLAY_STATE_NORMAL a little frequently than minimum interval :15 sec.
Alexey.

Vikram

Hi,

As my local testing result, by call sensor_listener_set_option(listener, SENSOR_OPTION_ALWAYS_ON);

It's works fine in background (press "home" to hidden it).

But not working if I press "power" key to off the screen,  seems the sensor don't call the callback under this scenario. Anyone have encounter such issue?

Alex Dem

Hi , 
It is strange. The sensor which was configured this way works on my Z1 device always. It does not matter was screen turned off with power key or after timeout (Settings->Display->Screen Timeout).
Alexey.