2016-04-20 92 views
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 - 初級

+0

OT:在'snprintf'中生成的字符串長度至多爲n-1,使用'sizeof tempbuf'而不是'1023' –

回答

2

功能你指的間隔是不恰當的。 相反,你應該使用下面的函數用於此目的:

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

}

error = sensor_listener_set_interval(listener, 10); 

error = sensor_listener_set_interval(listener, 100); 

您可以通過使用下面的代碼檢查日誌希望這個解決方案能夠滿足您的需求