diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2020-12-09 23:15:14 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2020-12-09 23:15:14 -0700 |
commit | 5f1763ec87503527583cb1a7c6deb73604db0dfc (patch) | |
tree | 0892ddf94b614db2d879f7bc993961af5ac25bb2 /src/drv/ir/control.c | |
parent | a5923b21e48fcfe660c1e7d586fe0c6a5b79e421 (diff) | |
download | stm32l4-test_ir.tar.gz stm32l4-test_ir.tar.bz2 stm32l4-test_ir.zip |
Can read from the A/C remote control!test_ir
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); +} |