#ifndef __FILTER_H__
#define __FILTER_H__

#ifdef __cplusplus
 extern "C" {
#endif

#include "stm32f4xx.h"

#define FILTER_SUM_LEN_GAS1    (8 * 2)
#define FILTER_SUM_LEN_GAS2    (8 * 2)
#define FILTER_SUM_LEN_GAS3    (8 * 2)
#define FILTER_SUM_LEN_GAS4    (8 * 2)

struct list_s {
    struct list_s *prev;
    struct list_s *next;
    uint32_t data;
};

struct data_filter_s {
    uint32_t input;

    uint16_t sum_len;
    uint16_t sum_idx;
    uint32_t *sum_buff;
    uint32_t sum_sum;

    uint16_t median_len;
    uint16_t median_idx;
    struct list_s head;
    struct list_s *median_buff;
    uint32_t median_output;

    uint16_t window_len;
    uint16_t window_idx;
    uint32_t *window_buff;
    uint32_t window_sum;
    uint32_t window_output;
};

extern uint32_t system_tick_cnt;

extern void filter_init(void);
extern void filter_input_data(uint8_t channel, uint32_t data);
extern void filter_sum_process(void);
extern void filter_median_process(void);
extern void filter_window_process(void);
extern void filter_output_process(void);
extern void filter_loop(void);

#ifdef __cplusplus
}
#endif

#endif /* __FILTER_H__ */
