diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2021-10-26 00:10:06 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2021-10-26 00:10:06 -0600 |
commit | f9b12f748b557994b958115c04fd1591b322248e (patch) | |
tree | 7d80680edadf5b0018944966af64f8773bfa8f1a /src/drv/ir/control.c | |
parent | dbbe83bd8882fe18e26f6305a1f425145bfea8db (diff) | |
parent | 90eb3a0b79bfef67c70dc545b49c48928eea05f4 (diff) | |
download | stm32l4-f9b12f748b557994b958115c04fd1591b322248e.tar.gz stm32l4-f9b12f748b557994b958115c04fd1591b322248e.tar.bz2 stm32l4-f9b12f748b557994b958115c04fd1591b322248e.zip |
Merge branch 'christmas' into HEAD
Diffstat (limited to 'src/drv/ir/control.c')
-rw-r--r-- | src/drv/ir/control.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/drv/ir/control.c b/src/drv/ir/control.c new file mode 100644 index 0000000..6be2cf1 --- /dev/null +++ b/src/drv/ir/control.c @@ -0,0 +1,43 @@ +#include "drv/ir/control.h" + +#include "drv/ir/ir.h" +#include "shared/map.h" + +typedef struct { + void* closure; + void (*fn)(uint32_t code, void* closure); +} ir_code_listener_t; + +#define integer_cmp_(a, b) (a - b) +MAP_DECL(uint32_t, ir_code_listener_t); +MAP_IMPL(uint32_t, ir_code_listener_t, integer_cmp_, null_dtor); + +static map_t(uint32_t, ir_code_listener_t) * listeners; + +static void ir_callback(const ir_code_t* ir) +{ + uint32_t code; + if (ir_generic_decode(ir, &code)) { + ir_code_listener_t* l = + map_get(uint32_t, ir_code_listener_t)(listeners, code); + + if (l) { + l->fn(code, l->closure); + } + } +} + +void add_ir_code_callback_( + uint32_t code, void (*fn)(uint32_t, void*), void* closure) +{ + ir_code_listener_t l; + l.fn = fn; + l.closure = closure; + map_put(uint32_t, ir_code_listener_t)(listeners, code, l); +} + +void enable_ir_control() +{ + listeners = map_new(uint32_t, ir_code_listener_t)(); + add_ir_callback(ir_callback); +} |