Languages

Menu
Sites
Language
Reading two different sensors and logging their data

I've seen many examples where a sensor object is used to initialize a listener and its respective callback. I managed to display on a Label the raw XYZ values as well as the timestamp for each accelerometer value.

I was wondering how I can collect data simultaneously for other type of sensors too, for instance get Gyro Accelerometer data values with shared time stamp.

One other problem I'm investigating is how to save the data for long times, for example, for at least 1 hour on CSV files.

Could anyone offer any suggestions.

 

Thanks!

 

 

 

 

Edited by: Joao Sanc on 28 Mar, 2018
View Selected Answer

Responses

3 Replies
Mark as answer
Armaan-Ul- Islam

Direct two different sensor events to a single callback function at same interval.

 

I'm sharing an example Code for you here:

 

void *user_data = NULL;

sensor_type_e typeL = SENSOR_LIGHT;
sensor_type_e typeP = SENSOR_PRESSURE;

sensor_h sensorL;
sensor_h sensorP;

sensor_listener_h listenerL;
sensor_listener_h listenerP;

sensor_get_default_sensor(typeL, &sensorL);
sensor_get_default_sensor(typeP, &sensorP);

sensor_create_listener(sensorL, &listenerL);
sensor_create_listener(sensorP, &listenerP);

sensor_listener_set_event_cb(listenerL, 1000 , on_sensor_event, user_data);
sensor_listener_set_event_cb(listenerP, 1000 , on_sensor_event, user_data);

sensor_listener_start(listenerL);
sensor_listener_start(listenerP);

void on_sensor_event(sensor_h sensor, sensor_event_s *event, void *user_data)
{
    sensor_type_e type;
    sensor_get_type(sensor, &type);

    switch (type) {
    case SENSOR_PRESSURE:
        dlog_print(DLOG_DEBUG, "XYZ", "Pressure event received %.2f",event->values[0]);
        break;
    case SENSOR_LIGHT:
        dlog_print(DLOG_DEBUG, "XYZ", "Light event received  %.2f",event->values[0]);
        break;
    default:
        dlog_print(DLOG_ERROR, LOG_TAG, "Not a relevant event");
    }
}

 

Please Check out the Sensor Recorder API References to get details about Recording features Offered by Tizen.

Joao Sanc

Thanks for your reply. I'm able to call sensor readings for the Accel and Gyro sensors and store their data in separate files.

My next challenge is to sync their timestamp values and save a single file with: [timestamp, ACCEL[X,Y,Z], GYRO[X,Y,X]]. If you could point me to a possible approach it would be great!

Armaan-Ul- Islam

You're welcome.

 

As I stated, You may check Sensor Recorder API References to get details about Recording features Offered by Tizen. If you are interested to store in a txt file, you have to use C code for that. Relevant posts:

 

Write to a file in Tizen Native Application

How to access file to read and write from Internal storage

write txt file in tizen native app via c