【问题标题】:How to improve Gear S2 Acceleration Sensor sample rate如何提高 Gear S2 加速度传感器采样率
【发布时间】:2016-04-20 12:31:39
【问题描述】:

我想计算三星 Gear S2 上的加速度传感器采样率。 使用以下代码作为示例 https://developer.tizen.org/ko/community/code-snippet/native-code-snippet/simple-sensors-application-wearable?langredirect=1,我创建了应用程序。

我用 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);

我用

计算采样率
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);
}
}

这样,加速度采样频率保持在 50Hz 左右(因此每 19-20 毫秒采样一次)。

你知道为什么我不能低于那个吗? (我的目标是每 10 毫秒 1 个样本 - 最低支持)

谢谢。

这是我的第一个问题,所以我也很高兴收到改进意见。

知识:C - 初学者,Tizen - 初学者

【问题讨论】:

  • OT:在snprintf中生成的字符串长度最多为n-1,使用sizeof tempbuf代替1023

标签: c tizen-native-app


【解决方案1】:

您为区间引用的函数不合适。 相反,您应该为此目的使用以下函数:

error = sensor_listener_set_interval(listener, 10);

error = sensor_listener_set_interval(listener, 100);

您可以使用以下代码查看日志:

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");
}

}

希望此解决方案能达到您的目的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多