1
0
mirror of https://github.com/rene-dev/stmbl.git synced 2025-01-01 21:42:14 +00:00
stmbl/shared/comps/reslimit.c

36 lines
926 B
C
Raw Permalink Normal View History

#include "reslimit_comp.h"
2017-07-01 01:18:08 +00:00
#include "commands.h"
#include "hal.h"
#include "math.h"
#include "defines.h"
#include "angle.h"
HAL_COMP(reslimit);
HAL_PIN(pos_in);
HAL_PIN(pos_out);
HAL_PIN(res);
2019-04-29 20:08:54 +00:00
static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) {
2017-09-06 02:20:06 +00:00
// struct reslimit_ctx_t * ctx = (struct reslimit_ctx_t *)ctx_ptr;
struct reslimit_pin_ctx_t *pins = (struct reslimit_pin_ctx_t *)pin_ptr;
//TODO: offset at zerocross
2017-09-06 02:20:06 +00:00
uint32_t r = ABS(PIN(res)); //TODO: div by zero
PIN(pos_out) = ((int)(PIN(pos_in) * r / 2.0 / M_PI + 0.5)) / (float)r * 2.0 * M_PI;
2017-07-01 01:18:08 +00:00
}
hal_comp_t reslimit_comp_struct = {
2017-09-06 02:20:06 +00:00
.name = "reslimit",
.nrt = 0,
.rt = rt_func,
.frt = 0,
.nrt_init = 0,
.rt_start = 0,
.frt_start = 0,
.rt_stop = 0,
.frt_stop = 0,
.ctx_size = 0,
.pin_count = sizeof(struct reslimit_pin_ctx_t) / sizeof(struct hal_pin_inst_t),
2017-07-01 01:18:08 +00:00
};