1
0
mirror of https://github.com/rene-dev/stmbl.git synced 2024-12-20 15:42:18 +00:00
stmbl/shared/comps/avg.c

39 lines
975 B
C
Raw Permalink Normal View History

#include "avg_comp.h"
2018-09-19 19:55:23 +00:00
#include "hal.h"
#include "defines.h"
HAL_COMP(avg);
HAL_PIN(in);
HAL_PIN(out);
HAL_PIN(lpf);
HAL_PIN(mult);
2018-12-16 17:30:52 +00:00
HAL_PIN(offset);
2018-09-19 19:55:23 +00:00
2019-04-29 20:08:54 +00:00
static void nrt_init(void *ctx_ptr, hal_pin_inst_t *pin_ptr) {
2018-09-19 19:55:23 +00:00
// struct avg_ctx_t * ctx = (struct avg_ctx_t *)ctx_ptr;
struct avg_pin_ctx_t *pins = (struct avg_pin_ctx_t *)pin_ptr;
PIN(lpf) = 100;
PIN(out) = 0.0;
2018-12-16 17:30:52 +00:00
PIN(offset) = 0.0;
2018-09-19 19:55:23 +00:00
}
2019-04-29 20:08:54 +00:00
static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) {
2018-09-19 19:55:23 +00:00
struct avg_pin_ctx_t *pins = (struct avg_pin_ctx_t *)pin_ptr;
2018-12-16 17:30:52 +00:00
PIN(out) = (PIN(in) * PIN(mult) + PIN(offset)) * LP_HZ(PIN(lpf)) + (1.0 - LP_HZ(PIN(lpf))) * PIN(out);
2018-09-19 19:55:23 +00:00
}
hal_comp_t avg_comp_struct = {
.name = "avg",
.nrt = 0,
.rt = rt_func,
.frt = 0,
.nrt_init = nrt_init,
.rt_start = 0,
.frt_start = 0,
.rt_stop = 0,
.frt_stop = 0,
.ctx_size = 0,
.pin_count = sizeof(struct avg_pin_ctx_t) / sizeof(struct hal_pin_inst_t),
};