Browse Source

feat(endpoints): Add endpoint select changed event.

xmkb
Peter Johanson 3 years ago committed by Pete Johanson
parent
commit
d05d7ec2d2
  1. 1
      app/CMakeLists.txt
  2. 8
      app/include/zmk/endpoints.h
  3. 12
      app/include/zmk/endpoints_types.h
  4. 18
      app/include/zmk/events/endpoint_selection_changed.h
  5. 4
      app/src/endpoints.c
  6. 10
      app/src/events/endpoint_selection_changed.c

1
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/layer_state_changed.c)
target_sources(app PRIVATE src/events/keycode_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/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(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_WPM app PRIVATE src/events/wpm_state_changed.c)
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/events/ble_active_profile_changed.c) target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/events/ble_active_profile_changed.c)

8
app/include/zmk/endpoints.h

@ -6,13 +6,7 @@
#pragma once #pragma once
#include <zmk/keys.h> #include <zmk/endpoints_types.h>
#include <zmk/hid.h>
enum zmk_endpoint {
ZMK_ENDPOINT_USB,
ZMK_ENDPOINT_BLE,
};
int zmk_endpoints_select(enum zmk_endpoint endpoint); int zmk_endpoints_select(enum zmk_endpoint endpoint);
int zmk_endpoints_toggle(); int zmk_endpoints_toggle();

12
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,
};

18
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 <zephyr.h>
#include <zmk/endpoints_types.h>
#include <zmk/event_manager.h>
struct zmk_endpoint_selection_changed {
enum zmk_endpoint endpoint;
};
ZMK_EVENT_DECLARE(zmk_endpoint_selection_changed);

4
app/src/endpoints.c

@ -16,6 +16,7 @@
#include <zmk/event_manager.h> #include <zmk/event_manager.h>
#include <zmk/events/ble_active_profile_changed.h> #include <zmk/events/ble_active_profile_changed.h>
#include <zmk/events/usb_conn_state_changed.h> #include <zmk/events/usb_conn_state_changed.h>
#include <zmk/events/endpoint_selection_changed.h>
#include <logging/log.h> #include <logging/log.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
@ -242,6 +243,9 @@ static void update_current_endpoint() {
current_endpoint = new_endpoint; current_endpoint = new_endpoint;
LOG_INF("Endpoint changed: %d", current_endpoint); LOG_INF("Endpoint changed: %d", current_endpoint);
ZMK_EVENT_RAISE(new_zmk_endpoint_selection_changed(
(struct zmk_endpoint_selection_changed){.endpoint = current_endpoint}));
} }
} }

10
app/src/events/endpoint_selection_changed.c

@ -0,0 +1,10 @@
/*
* Copyright (c) 2021 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#include <kernel.h>
#include <zmk/events/endpoint_selection_changed.h>
ZMK_EVENT_IMPL(zmk_endpoint_selection_changed);
Loading…
Cancel
Save