From: kibak.yoon Date: Wed, 28 Dec 2016 06:38:07 +0000 (+0900) Subject: sensord: accumulate pedometer data X-Git-Tag: accepted/tizen/3.0.m2/mobile/20170104.141653^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_3.0.m2;p=platform%2Fcore%2Fsystem%2Fsensord.git sensord: accumulate pedometer data - accumulated pedometer data should be provided to client Change-Id: Ib9a4bb5325867e1e55f1e8c9b9a32609915dbd08 Signed-off-by: kibak.yoon --- diff --git a/src/sensor/sensorhub/pedometer_sensor.cpp b/src/sensor/sensorhub/pedometer_sensor.cpp index b9d5c23..c825e41 100644 --- a/src/sensor/sensorhub/pedometer_sensor.cpp +++ b/src/sensor/sensorhub/pedometer_sensor.cpp @@ -21,7 +21,32 @@ #include #include "pedometer_sensor.h" +enum value_index { + IDX_STEPS = 0, + IDX_WALK_STEPS, + IDX_RUN_STEPS, + IDX_DISTANCE, + IDX_CALORIES, + IDX_SPEED, + IDX_FREQUENCY, + IDX_STATE, + IDX_WALK_UP, + IDX_WALK_DOWN, + IDX_RUN_UP, + IDX_RUN_DOWN, + IDX_STATE_EX, +}; + pedometer_sensor::pedometer_sensor() +: m_steps(0) +, m_walk_steps(0) +, m_run_steps(0) +, m_walk_up_steps(0) +, m_walk_down_steps(0) +, m_run_up_steps(0) +, m_run_down_steps(0) +, m_distance(0) +, m_calories(0) { set_permission(SENSOR_PERMISSION_BIO); @@ -30,5 +55,38 @@ pedometer_sensor::pedometer_sensor() pedometer_sensor::~pedometer_sensor() { - _I("pedometer_sensor is destroyed : %#x", this); +} + +bool pedometer_sensor::on_event(const sensor_data_t *data, int data_len, int remains) +{ + if (data_len == sizeof(sensorhub_data_t)) + return false; + + accumulate((sensor_pedometer_data_t*)data); + return true; +} + +void pedometer_sensor::accumulate(sensor_pedometer_data_t *data) +{ + m_steps += data->values[IDX_STEPS]; + m_walk_steps += data->values[IDX_WALK_STEPS]; + m_run_steps += data->values[IDX_RUN_STEPS]; + m_distance += data->values[IDX_DISTANCE]; + m_calories += data->values[IDX_CALORIES]; + + m_walk_up_steps += data->values[IDX_WALK_UP]; + m_walk_down_steps += data->values[IDX_WALK_DOWN]; + m_run_up_steps += data->values[IDX_RUN_UP]; + m_run_down_steps += data->values[IDX_RUN_DOWN]; + + data->values[IDX_STEPS] = m_steps; + data->values[IDX_WALK_STEPS] = m_walk_steps; + data->values[IDX_RUN_STEPS] = m_run_steps; + data->values[IDX_DISTANCE] = m_distance; + data->values[IDX_CALORIES] = m_calories; + + data->values[IDX_WALK_UP] = m_walk_up_steps; + data->values[IDX_WALK_DOWN] = m_walk_down_steps; + data->values[IDX_RUN_UP] = m_run_up_steps; + data->values[IDX_RUN_DOWN] = m_run_down_steps; } diff --git a/src/sensor/sensorhub/pedometer_sensor.h b/src/sensor/sensorhub/pedometer_sensor.h index 5ae94c2..16f1ac7 100644 --- a/src/sensor/sensorhub/pedometer_sensor.h +++ b/src/sensor/sensorhub/pedometer_sensor.h @@ -26,6 +26,21 @@ class pedometer_sensor : public physical_sensor { public: pedometer_sensor(); virtual ~pedometer_sensor(); + + bool on_event(const sensor_data_t *data, int data_len, int remains); + +private: + unsigned long long m_steps; + unsigned long long m_walk_steps; + unsigned long long m_run_steps; + unsigned long long m_walk_up_steps; + unsigned long long m_walk_down_steps; + unsigned long long m_run_up_steps; + unsigned long long m_run_down_steps; + double m_distance; + double m_calories; + + void accumulate(sensor_pedometer_data_t *data); }; #endif /* _PEDOMETER_SENSOR_H_ */