From cefd0601b91fa642163c82021d454b3c17d8adf4 Mon Sep 17 00:00:00 2001 From: Jan Sucan Date: Sun, 22 Sep 2019 21:17:50 +0200 Subject: Initial commit --- FanController/fan_controller/median.h | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 FanController/fan_controller/median.h (limited to 'FanController/fan_controller/median.h') diff --git a/FanController/fan_controller/median.h b/FanController/fan_controller/median.h new file mode 100644 index 0000000..b24cec4 --- /dev/null +++ b/FanController/fan_controller/median.h @@ -0,0 +1,42 @@ +/* Autor: Ján Sučan + * + * Zdrojove kody, ich casti a subory z nich vzniknute priamo alebo nepriamo + * (objektove subory, Intel Hex, ...) prosim nepouzivajte komercne, ani ako + * sucast komercnych diel. Vsetky ostatne pripady pouzitia su dovolene. + * + * Please don't use the source codes, their parts and files created from them + * directly or indirectly, (object files, Intel Hex files, ...) for commercial + * purposes, not even as a part of commercial products. All other use cases + * are allowed. + */ + +#ifndef MEDIAN_H_ +#define MEDIAN_H_ + +#include + +/** Minimalny pocet vzoriek pre vypocet medianu. */ +#define MEDIAN_MIN_SAMPLES 3U + +/** Maximalny pocet vzoriek pre vypocet medianu. */ +#define MEDIAN_MAX_SAMPLES 16U + +/** Vzorka pre median. */ +typedef struct { + uint16_t value; /**< Hodnota vzorky. */ + uint8_t age_index; /**< Index do FIFO age v bufferi medianu. */ +} median_sample_t; + +/** Buffer pre vypocet medianu. */ +typedef struct { + uint8_t number_of_elements; /**< Pocet aktualne ulozenych vzoriek. */ + uint8_t capacity; /**< Maximalny pocet ulozenych vzoriek. */ + median_sample_t samples[MEDIAN_MAX_SAMPLES]; /**< Vzorky z ktorych sa pocita median. */ + uint8_t age[MEDIAN_MAX_SAMPLES]; /**< FIFO. Na indexe 0 je index najstarsej vzorky v poli samples, na indexe 1 je index druhej najstarsej, atd. Pouziva sa pre rychle najdenie najstarsieho prvku. */ +} median_buffer_t; + +void median_init_buffer(median_buffer_t * const buf, uint8_t capacity); +void median_save_sample(median_buffer_t * const buf, uint16_t sample); +uint16_t median_get(const median_buffer_t * const buf); + +#endif /* MEDIAN_H_ */ \ No newline at end of file -- cgit v1.2.3