为什么我在 Tizen Native Wearable 中获得恒定的步数?

问题描述

我正在使用 Native 在 Tizen Wearable 中运行步数监听器。我能够访问传感器数据,但它似乎永远打印相同的数据?我在这里做错了吗? 使用 API 3 和三星 galaxy Watch 3。

#include "stepcount.h"
#include "sensor.h"

void
example_sensor_callback(sensor_h sensor,sensor_event_s *event,void *user_data)
{
    /*
       If a callback is used to listen for different sensor types,it can check the sensor type
    */
    sensor_type_e type;
    sensor_get_type(sensor,&type);
    int i = 0;

    if (type == SENSOR_ACCELEROMETER) {
        unsigned long long timestamp = event->timestamp;
        int accuracy = event->accuracy;
        float x = event->values[0];
        float y = event->values[1];
        float z = event->values[2];
        dlog_print(DLOG_INFO,LOG_TAG,"ACCEL: %f %f %f",x,y,z);
    } else if (type == SENSOR_HRM) {
        unsigned long long timestamp = event->timestamp;
        int v = (int)event->values[0];
        dlog_print(DLOG_INFO,"Heart Rate: %.0f bpm",event->values[0]);
    }
    else if (type == SENSOR_HUMAN_pedometer ){
            unsigned long long timestamp = event->timestamp;
            int accuracy = event->accuracy;
            int s = (int)event->values[0];
            int b = (int)event->values[1];
            dlog_print(DLOG_INFO,"Step Count: %d",event->values[0]);
            dlog_print(DLOG_INFO,"Walking Step Count: %d",event->values[1]);

    }
}

Base GUI
------
    bool supported = false;

    sensor_is_supported(SENSOR_HUMAN_pedometer,&supported);
    if (!supported) {
        /* Accelerometer is not supported on the current device */
    }

    sensor_h sensor;
    sensor_get_default_sensor(SENSOR_HUMAN_pedometer,&sensor);

    sensor_listener_h listener;
    sensor_create_listener(sensor,&listener);

    sensor_listener_start(listener);

    /* Register callback */
    sensor_listener_set_event_cb(listener,1000,example_sensor_callback,NULL);

    sensor_listener_set_attribute_int(listener,SENSOR_ATTRIBUTE_PAUSE_POLICY,SENSOR_PAUSE_NONE);

这是我的日志

01-29 13:25:00.035 : Info / stepcount ( 8215 : 8215 ) : Step Count: 4
01-29 13:25:00.091 : Info / stepcount ( 8215 : 8215 ) : Walking Step Count: 1
01-29 13:30:16.763 : Info / stepcount ( 8215 : 8215 ) : Step Count: 4
01-29 13:30:16.763 : Info / stepcount ( 8215 : 8215 ) : Walking Step Count: 1
01-29 13:30:17.143 : Info / stepcount ( 8215 : 8215 ) : Step Count: 4
01-29 13:30:17.143 : Info / stepcount ( 8215 : 8215 ) : Walking Step Count: 1
01-29 13:30:18.439 : Info / stepcount ( 8215 : 8215 ) : Step Count: 4
01-29 13:30:18.443 : Info / stepcount ( 8215 : 8215 ) : Walking Step Count: 1
01-29 13:30:18.655 : Info / stepcount ( 8215 : 8215 ) : Step Count: 4
01-29 13:30:18.655 : Info / stepcount ( 8215 : 8215 ) : Walking Step Count: 1

我想正确读取我的实际步数。

解决方法

请改正如下。

        dlog_print(DLOG_INFO,LOG_TAG,"Step Count: %d",s);
        dlog_print(DLOG_INFO,"Walking Step Count: %d",b);

        dlog_print(DLOG_INFO,"Step Count: %f",event->values[0]);
        dlog_print(DLOG_INFO,"Walking Step Count: %f",event->values[1]);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...