2 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __PEDOMETER_SPEED_FILTER_H__
18 #define __PEDOMETER_SPEED_FILTER_H__
20 #include "timestamp.h"
22 /************************************************************************
23 * stores pedometer speed filter state.
25 class pedometer_speed_filter {
28 pedometer_speed_filter();
30 ~pedometer_speed_filter();
32 void clear_speed(void);
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.
39 * @param step_max_duration
40 * maximum step duration in ns.
41 * 0 to disable step duration checking.
43 void set_step_max_duration(long long step_max_duration);
45 /************************************************************************
46 * called when new step detection event occurs.
49 * timestamp of step detection event in [ns].
51 * length of detected step in [m].
53 void new_step(timestamp_t timestamp, double step_length);
55 /************************************************************************
59 * timestamp of speed event in [ns].
61 * current speed in [m/s].
63 void new_speed(timestamp_t timestamp, double speed);
65 /************************************************************************
66 * returns current speed.
69 * timestamp for which speed should be calculated in [ns].
70 * @return speed for given timestamp in [m/s].
72 double get_speed(timestamp_t timestamp);
74 /************************************************************************
75 * changes current speed.
78 * current speed in [m/s].
80 void set_current_speed(double speed);
82 /************************************************************************
83 * @return estimated current speed in [m/s].
85 double get_current_speed(void);
87 /************************************************************************
89 bool is_known_timestamp(void);
91 /************************************************************************
92 * @return timestamp of last step detection event in [ns].
94 timestamp_t get_timestamp(void);
96 /************************************************************************
97 * resets filter to initial state.
102 /** timestamp of last step detection event in [ns]. */
103 timestamp_t m_last_timestamp;
105 /** estimated current speed in [m/s]. */
106 double m_current_speed;
108 /** length of last step in [m]. */
109 double m_last_step_length;
111 /** duration of last step in [s]. */
112 double m_last_step_duration;
114 /** maximum step duration in [ns]. 0 to disable step duration checking. */
115 long long m_step_max_duration;
118 #endif /* __PEDOMETER_SPEED_FILTER_H__ */