summaryrefslogtreecommitdiff
path: root/app/src/event_manager.c
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2020-06-30 00:31:09 -0400
committerPete Johanson <peter@peterjohanson.com>2020-06-30 00:31:09 -0400
commit9a991bf019d6f723bc4230822852efa78a05be49 (patch)
tree5c6604f146502a9f4886231bb0c3b39d7646888f /app/src/event_manager.c
parent22238d24de3a25cb9242330eba568294c7937c63 (diff)
Initial event manager work, and two first events.
* Add initial event manager implementation, roughly mimicking Nordic's API. * Add `position_state_changed` and `keycode_state_changed` events. * Hook up HID and keymap to new events instead of using behaviour global event crazy.
Diffstat (limited to 'app/src/event_manager.c')
-rw-r--r--app/src/event_manager.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/src/event_manager.c b/app/src/event_manager.c
new file mode 100644
index 0000000..012d285
--- /dev/null
+++ b/app/src/event_manager.c
@@ -0,0 +1,32 @@
+
+#include <zephyr.h>
+#include <logging/log.h>
+
+LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
+
+#include <zmk/event-manager.h>
+
+extern struct zmk_event_type* __event_type_start[];
+extern struct zmk_event_type* __event_type_end[];
+
+extern struct zmk_event_subscription __event_subscriptions_start[];
+extern struct zmk_event_subscription __event_subscriptions_end[];
+
+int zmk_event_manager_raise(struct zmk_event_header *event)
+{
+ int ret;
+ struct zmk_event_subscription *ev_sub;
+ for (ev_sub = __event_subscriptions_start; ev_sub != __event_subscriptions_end; ev_sub++) {
+ if (ev_sub->event_type == event->event) {
+ ret = ev_sub->listener->callback(event);
+ if (ret) {
+ LOG_DBG("Listener returned an error: %d", ret);
+ goto release;
+ }
+ }
+ }
+
+release:
+ k_free(event);
+ return ret;
+} \ No newline at end of file