我想计算Samsung 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 ms一次采样)。
你知道为什么我不能低于这个吗? (我的目标是每10毫秒一个样本 - 最低支持)
谢谢。
这是我的第一个问题,所以我很乐意收到改进意见。
知识:C - 初学者,Tizen - 初学者
答案 0 :(得分:2)
您在间隔中引用的功能不合适。 相反,您应该为此目的使用以下功能:
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");
}
}
希望此解决方案能满足您的目的。