1
我想計算三星Gear S2上的加速度傳感器採樣率。 使用以下代碼作爲示例 https://developer.tizen.org/ko/community/code-snippet/native-code-snippet/simple-sensors-application-wearable?langredirect=1,我創建了該應用程序。如何提高Gear S2加速度傳感器採樣率
我註冊爲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女士)。
你知道我爲什麼不能低於那個嗎? (我的目標是每10ms 1個樣本 - 支持最低)
謝謝。
這是我的第一個問題,所以我很樂意接受改進建議。
知識:C - 初學者,Tizen - 初級
OT:在'snprintf'中生成的字符串長度至多爲n-1,使用'sizeof tempbuf'而不是'1023' –