gpt4 book ai didi

c - 如何提高 Gear S2 加速度传感器采样率

转载 作者:太空宇宙 更新时间:2023-11-04 02:36:21 26 4
gpt4 key购买 nike

我想计算 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 毫秒采样一次)。

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

谢谢。

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

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

最佳答案

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

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

希望这个解决方案能为您服务。

关于c - 如何提高 Gear S2 加速度传感器采样率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36743906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com