d9e0b7fdd6a6339b8b7d4d9f18e929d31a379c70
[platform/core/system/sensord.git] / src / sensor / pedometer / pedometer_speed_filter.h
1 /*
2  *  Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 #ifndef __PEDOMETER_SPEED_FILTER_H__
18 #define __PEDOMETER_SPEED_FILTER_H__
19
20 #include "timestamp.h"
21
22 /************************************************************************
23  * stores pedometer speed filter state.
24  */
25 class pedometer_speed_filter {
26 public:
27
28         pedometer_speed_filter();
29
30         ~pedometer_speed_filter();
31
32         void clear_speed(void);
33
34         /************************************************************************
35          * sets new maximum step duration in ns.
36          * if there is no new speed during this time current speed is cleared.
37          * 0 disables this feature.
38          *
39          * @param step_max_duration
40          *            maximum step duration in ns.
41          *            0 to disable step duration checking.
42          */
43         void set_step_max_duration(long long step_max_duration);
44
45         /************************************************************************
46          * called when new step detection event occurs.
47          *
48          * @param timestamp
49          *            timestamp of step detection event in [ns].
50          * @param steplength
51          *            length of detected step in [m].
52          */
53         void new_step(timestamp_t timestamp, double step_length);
54
55         /************************************************************************
56          * reports new speed.
57          *
58          * @param timestamp
59          *            timestamp of speed event in [ns].
60          * @param speed
61          *            current speed in [m/s].
62          */
63         void new_speed(timestamp_t timestamp, double speed);
64
65         /************************************************************************
66          * returns current speed.
67          *
68          * @param timestamp
69          *            timestamp for which speed should be calculated in [ns].
70          * @return speed for given timestamp in [m/s].
71          */
72         double get_speed(timestamp_t timestamp);
73
74         /************************************************************************
75          * changes current speed.
76          *
77          * @param speed
78          *            current speed in [m/s].
79          */
80         void set_current_speed(double speed);
81
82         /************************************************************************
83          * @return estimated current speed in [m/s].
84          */
85         double get_current_speed(void);
86
87         /************************************************************************
88          */
89         bool is_known_timestamp(void);
90
91         /************************************************************************
92          * @return timestamp of last step detection event in [ns].
93          */
94         timestamp_t get_timestamp(void);
95
96         /************************************************************************
97          * resets filter to initial state.
98          */
99         void reset(void);
100
101 private:
102         /** timestamp of last step detection event in [ns]. */
103         timestamp_t m_last_timestamp;
104
105         /** estimated current speed in [m/s]. */
106         double m_current_speed;
107
108         /** length of last step in [m]. */
109         double m_last_step_length;
110
111         /** duration of last step in [s]. */
112         double m_last_step_duration;
113
114         /** maximum step duration in [ns]. 0 to disable step duration checking. */
115         long long m_step_max_duration;
116 };
117
118 #endif /* __PEDOMETER_SPEED_FILTER_H__ */