From d05d7ec2d2b40ca40339b4d7cceb31974bac0e94 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 2 Aug 2021 21:44:01 -0400 Subject: [PATCH] feat(endpoints): Add endpoint select changed event. --- app/CMakeLists.txt | 1 + app/include/zmk/endpoints.h | 8 +------- app/include/zmk/endpoints_types.h | 12 ++++++++++++ .../zmk/events/endpoint_selection_changed.h | 18 ++++++++++++++++++ app/src/endpoints.c | 4 ++++ app/src/events/endpoint_selection_changed.c | 10 ++++++++++ 6 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 app/include/zmk/endpoints_types.h create mode 100644 app/include/zmk/events/endpoint_selection_changed.h create mode 100644 app/src/events/endpoint_selection_changed.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index e283487f..5092deff 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -36,6 +36,7 @@ target_sources(app PRIVATE src/events/position_state_changed.c) target_sources(app PRIVATE src/events/layer_state_changed.c) target_sources(app PRIVATE src/events/keycode_state_changed.c) target_sources(app PRIVATE src/events/modifiers_state_changed.c) +target_sources(app PRIVATE src/events/endpoint_selection_changed.c) target_sources(app PRIVATE src/events/sensor_event.c) target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/events/wpm_state_changed.c) target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/events/ble_active_profile_changed.c) diff --git a/app/include/zmk/endpoints.h b/app/include/zmk/endpoints.h index 0d2bbce0..c8860533 100644 --- a/app/include/zmk/endpoints.h +++ b/app/include/zmk/endpoints.h @@ -6,13 +6,7 @@ #pragma once -#include -#include - -enum zmk_endpoint { - ZMK_ENDPOINT_USB, - ZMK_ENDPOINT_BLE, -}; +#include int zmk_endpoints_select(enum zmk_endpoint endpoint); int zmk_endpoints_toggle(); diff --git a/app/include/zmk/endpoints_types.h b/app/include/zmk/endpoints_types.h new file mode 100644 index 00000000..70804a61 --- /dev/null +++ b/app/include/zmk/endpoints_types.h @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +enum zmk_endpoint { + ZMK_ENDPOINT_USB, + ZMK_ENDPOINT_BLE, +}; diff --git a/app/include/zmk/events/endpoint_selection_changed.h b/app/include/zmk/events/endpoint_selection_changed.h new file mode 100644 index 00000000..38a6a8e5 --- /dev/null +++ b/app/include/zmk/events/endpoint_selection_changed.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +#include +#include + +struct zmk_endpoint_selection_changed { + enum zmk_endpoint endpoint; +}; + +ZMK_EVENT_DECLARE(zmk_endpoint_selection_changed); diff --git a/app/src/endpoints.c b/app/src/endpoints.c index 93dfb817..c15aad87 100644 --- a/app/src/endpoints.c +++ b/app/src/endpoints.c @@ -16,6 +16,7 @@ #include #include #include +#include #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); @@ -242,6 +243,9 @@ static void update_current_endpoint() { current_endpoint = new_endpoint; LOG_INF("Endpoint changed: %d", current_endpoint); + + ZMK_EVENT_RAISE(new_zmk_endpoint_selection_changed( + (struct zmk_endpoint_selection_changed){.endpoint = current_endpoint})); } } diff --git a/app/src/events/endpoint_selection_changed.c b/app/src/events/endpoint_selection_changed.c new file mode 100644 index 00000000..7f9014da --- /dev/null +++ b/app/src/events/endpoint_selection_changed.c @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +ZMK_EVENT_IMPL(zmk_endpoint_selection_changed);