|
| 1 | +/** |
| 2 | + * @file filter.h |
| 3 | + * @author Ajay Bhargav |
| 4 | + * @brief Filter library to use with ADC |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#ifndef INC_FILTER_H_ |
| 9 | +#define INC_FILTER_H_ |
| 10 | + |
| 11 | +#ifdef __cplusplus |
| 12 | +extern "C" |
| 13 | +{ |
| 14 | +#endif |
| 15 | + |
| 16 | +typedef void* filter_t; |
| 17 | + |
| 18 | +/** |
| 19 | + * @brief Initialize filter |
| 20 | + * |
| 21 | + * @param init_val Initial value to set or start with |
| 22 | + * @return filter handle |
| 23 | + */ |
| 24 | +filter_t filter_init(float init_val); |
| 25 | + |
| 26 | +/** |
| 27 | + * @brief Update filter and get current estimate value |
| 28 | + * |
| 29 | + * @param handle filter handle returned by filter_init() |
| 30 | + * @param val measured value |
| 31 | + * @return current estimate value |
| 32 | + */ |
| 33 | +float filter_update(filter_t handle, float val); |
| 34 | + |
| 35 | +/** |
| 36 | + * @brief Set filter level |
| 37 | + * |
| 38 | + * Level value range from 0 to 10. 0 means faster update |
| 39 | + * and 10 means slower update when filter is updated |
| 40 | + * |
| 41 | + * @param handle filter handle returned by filter_init() |
| 42 | + * @param level filter level 0 to 10 |
| 43 | + * @return 1 if filter is updated, 0 if no change is made and current level is same as set level |
| 44 | + */ |
| 45 | +int filter_setlevel(filter_t handle, int level); |
| 46 | + |
| 47 | +/** |
| 48 | + * @brief Get filter level |
| 49 | + * |
| 50 | + * The return level is from 0 to 10 for preset values of variance_q and estimate error. |
| 51 | + * when custom value is set 11 is returned. |
| 52 | + * |
| 53 | + * @param handle filter handle returned by filter_init() |
| 54 | + * @return filter level value from 0 to 11 |
| 55 | + */ |
| 56 | +int filter_getlevel(filter_t handle); |
| 57 | + |
| 58 | +/** |
| 59 | + * @brief Set custom q and estimate error values |
| 60 | + * |
| 61 | + * @param handle filter handle returned by filter_init() |
| 62 | + * @param variance_q Covariance Q value lower the value, slower the response |
| 63 | + * @param est_error Estimate error to start with |
| 64 | + * @return 1 if filter is updated, 0 if no change is made |
| 65 | + */ |
| 66 | +int filter_setconfig(filter_t handle, float variance_q, float est_error); |
| 67 | + |
| 68 | +/** |
| 69 | + * @brief Get values set for filter |
| 70 | + * |
| 71 | + * @param handle filter handle returned by filter_init() |
| 72 | + * @param variance_q Covariance Q value |
| 73 | + * @param est_error Estimate error value |
| 74 | + * @return returns 0 always |
| 75 | + */ |
| 76 | +int filter_getconfig(filter_t handle, float *variance_q, float *est_error); |
| 77 | + |
| 78 | +/** |
| 79 | + * @brief Get error estimate calculated by filter |
| 80 | + * |
| 81 | + * @param handle filter handle returned by filter_init() |
| 82 | + * @return current measured error estimate |
| 83 | + */ |
| 84 | +float filter_get_estmate_error(filter_t handle); |
| 85 | + |
| 86 | +/** |
| 87 | + * @brief Get filter gain |
| 88 | + * |
| 89 | + * @param handle filter handle returned by filter_init() |
| 90 | + * @return current filter gain |
| 91 | + */ |
| 92 | +float filter_get_gain(filter_t handle); |
| 93 | + |
| 94 | +#ifdef __cplusplus |
| 95 | +} |
| 96 | +#endif |
| 97 | + |
| 98 | +#endif /* INC_FILTER_H_ */ |
0 commit comments