ECE4180
Dependencies: mbed PulseSensor mbed-rtos LSM9DS1_Library_cal
stepcounter.h@7:88d71c228407, 2021-12-01 (annotated)
- Committer:
- yutation
- Date:
- Wed Dec 01 00:20:32 2021 +0000
- Revision:
- 7:88d71c228407
- Child:
- 8:2d43385e7784
4180;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yutation | 7:88d71c228407 | 1 | #ifndef __STEPCOUNTER_H__ |
yutation | 7:88d71c228407 | 2 | #define __STEPCOUNTER_H__ |
yutation | 7:88d71c228407 | 3 | |
yutation | 7:88d71c228407 | 4 | #include "stdint.h" |
yutation | 7:88d71c228407 | 5 | #include "math.h" |
yutation | 7:88d71c228407 | 6 | |
yutation | 7:88d71c228407 | 7 | #define FILTER_CNT 3 |
yutation | 7:88d71c228407 | 8 | |
yutation | 7:88d71c228407 | 9 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
yutation | 7:88d71c228407 | 10 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
yutation | 7:88d71c228407 | 11 | #define SAMPLE_SIZE 10 |
yutation | 7:88d71c228407 | 12 | |
yutation | 7:88d71c228407 | 13 | #define ABS(a) (0 - (a)) > 0 ? (-(a)) : (a) |
yutation | 7:88d71c228407 | 14 | #define DYNAMIC_PRECISION 30 |
yutation | 7:88d71c228407 | 15 | |
yutation | 7:88d71c228407 | 16 | #define MOST_ACTIVE_NULL 0 |
yutation | 7:88d71c228407 | 17 | #define MOST_ACTIVE_X 1 |
yutation | 7:88d71c228407 | 18 | #define MOST_ACTIVE_Y 2 |
yutation | 7:88d71c228407 | 19 | #define MOST_ACTIVE_Z 3 |
yutation | 7:88d71c228407 | 20 | |
yutation | 7:88d71c228407 | 21 | #define ACTIVE_PRECISION 6 |
yutation | 7:88d71c228407 | 22 | |
yutation | 7:88d71c228407 | 23 | #define DATA_FACTOR 1000 |
yutation | 7:88d71c228407 | 24 | |
yutation | 7:88d71c228407 | 25 | typedef struct |
yutation | 7:88d71c228407 | 26 | { |
yutation | 7:88d71c228407 | 27 | short x; |
yutation | 7:88d71c228407 | 28 | short y; |
yutation | 7:88d71c228407 | 29 | short z; |
yutation | 7:88d71c228407 | 30 | } axis_info_t; |
yutation | 7:88d71c228407 | 31 | |
yutation | 7:88d71c228407 | 32 | typedef struct |
yutation | 7:88d71c228407 | 33 | { |
yutation | 7:88d71c228407 | 34 | axis_info_t newmax; |
yutation | 7:88d71c228407 | 35 | axis_info_t newmin; |
yutation | 7:88d71c228407 | 36 | axis_info_t oldmax; |
yutation | 7:88d71c228407 | 37 | axis_info_t oldmin; |
yutation | 7:88d71c228407 | 38 | } peak_value_t; |
yutation | 7:88d71c228407 | 39 | |
yutation | 7:88d71c228407 | 40 | typedef struct filter_avg |
yutation | 7:88d71c228407 | 41 | { |
yutation | 7:88d71c228407 | 42 | axis_info_t info[FILTER_CNT]; |
yutation | 7:88d71c228407 | 43 | unsigned char count; |
yutation | 7:88d71c228407 | 44 | } filter_avg_t; |
yutation | 7:88d71c228407 | 45 | |
yutation | 7:88d71c228407 | 46 | |
yutation | 7:88d71c228407 | 47 | |
yutation | 7:88d71c228407 | 48 | typedef struct slid_reg |
yutation | 7:88d71c228407 | 49 | { |
yutation | 7:88d71c228407 | 50 | axis_info_t new_sample; |
yutation | 7:88d71c228407 | 51 | axis_info_t old_sample; |
yutation | 7:88d71c228407 | 52 | } slid_reg_t; |
yutation | 7:88d71c228407 | 53 | |
yutation | 7:88d71c228407 | 54 | extern filter_avg_t acc_data; |
yutation | 7:88d71c228407 | 55 | extern axis_info_t acc_sample; |
yutation | 7:88d71c228407 | 56 | extern peak_value_t acc_peak; |
yutation | 7:88d71c228407 | 57 | extern slid_reg_t acc_slid; |
yutation | 7:88d71c228407 | 58 | extern uint8_t step_cnt; |
yutation | 7:88d71c228407 | 59 | |
yutation | 7:88d71c228407 | 60 | void filter_calculate(filter_avg_t *filter, axis_info_t *sample); |
yutation | 7:88d71c228407 | 61 | void peak_value_init(peak_value_t *peak); |
yutation | 7:88d71c228407 | 62 | void peak_update(peak_value_t *peak, axis_info_t *cur_sample); |
yutation | 7:88d71c228407 | 63 | char slid_update(slid_reg_t *slid, axis_info_t *cur_sample); |
yutation | 7:88d71c228407 | 64 | char is_most_active(peak_value_t *peak); |
yutation | 7:88d71c228407 | 65 | void detect_step(peak_value_t *peak, slid_reg_t *slid, axis_info_t *cur_sample); |
yutation | 7:88d71c228407 | 66 | |
yutation | 7:88d71c228407 | 67 | #endif |