我想计算三星 Gear S2 上的加速度传感器采样率。使用以下代码作为示例 https://developer.tizen.org/ko/community/code-snippet/native-code-snippet/simple-sensors-application-wearable?langredirect=1,我创建了应用程序。
我用 10 毫秒注册回调
/* 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 - 初学者