1

I want to calculate the acceleration sensor sample rate on a Samsung Gear S2. Using the following code as example https://developer.tizen.org/ko/community/code-snippet/native-code-snippet/simple-sensors-application-wearable?langredirect=1, I created the app.

I register the callback with 10ms

    /* Register a callback if a sensor event is detected (sensor value changed) */
    ret = sensor_listener_set_event_cb((ad->listener), 10, on_sensor_event, ad);

and I calculate the sampling rate with

unsigned long long int timestampArray[1000000];
int i = 1;
unsigned int samplingFreq = 1;

/* Callback for whenever a sensor event is detected (such as value changed). It is called whenever such an event is detected */
void on_sensor_event(sensor_h sensor, sensor_event_s *event, void *data) {
appdata_s *ad = data;

char buf[1024]={0};
char tempbuf[1024]={0};

sensor_type_e type;
sensor_get_type(sensor, &type);

//Check the sensor type of the sensor event
if(type == (ad->type)){

    timestampArray[i] = event->timestamp/1000;
    if(i == 2)
    {
        samplingFreq = timestampArray[i]-timestampArray[i-1];
    }

    i++;

    snprintf(tempbuf, 1023, "F= %d<br/>", samplingFreq);
    strcat(buf, tempbuf);

    elm_object_text_set(ad->label, buf);
}
}

With this, the acceleration sampling frequency stays at around 50Hz (so one sample every 19-20 ms).

Do you know why I can't get lower than that? (My goal would be 1 sample every 10ms - minimum supported)

Thank you.

This is my first question so I would be glad to receive improvement ideas as well.

Knowledge: C - beginner, Tizen - beginner

ossx
  • 147
  • 8

1 Answers1

2

The function you are referring for the interval is not appropriate. Rather you should use the following function for this purpose:

error = sensor_listener_set_interval(listener, 10);

or

error = sensor_listener_set_interval(listener, 100);

You can check the log by using the following code:

void on_sensor_event(sensor_h sensor, sensor_event_s * event, void * user_data) {

dlog_print(DLOG_DEBUG, LOG_TAG, "Sensor Called- %llu<br/>", event->timestamp / 1000);
// Select a specific sensor with a sensor handle

sensor_type_e type;
sensor_get_type(sensor,  & type);

switch (type) {
case SENSOR_ACCELEROMETER:
    dlog_print(DLOG_INFO, LOG_TAG, "sensor data read successfully");

    char buf[1024];
    char tempbuf[1024];
    snprintf(buf, 1023, "Sensor data read successfully detected.<br/>");

    for (int i = 0; i < event->value_count; i++) {
        snprintf(tempbuf, sizeof tempbuf, "Sensor value[%d] is - %f<br/>", i, event->values[i]);
        strcat(buf, tempbuf);
    }

    snprintf(tempbuf, sizeof tempbuf, "Sensor timestamp is - %llu<br/>", event->timestamp);
    strcat(buf, tempbuf);

    snprintf(tempbuf, sizeof tempbuf, "Sensor accuracy is - %d<br/>", event->accuracy);
    strcat(buf, tempbuf);
    elm_object_text_set(event_label, buf);

    break;
default:
    dlog_print(DLOG_ERROR, LOG_TAG, "Not an Accelerometer event");
}

}

Hope this solution will serve your purpose.

nafser33
  • 403
  • 4
  • 6