diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index cc38244a4..46cb9e8dc 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -82,6 +82,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL) if (CONFIG_ZMK_BLE) target_sources(app PRIVATE src/events/ble_active_profile_changed.c) + target_sources(app PRIVATE src/events/ble_inactive_profile_changed.c) target_sources(app PRIVATE src/behaviors/behavior_bt.c) target_sources(app PRIVATE src/ble.c) target_sources(app PRIVATE src/hog.c) diff --git a/app/boards/shields/nice_view/widgets/status.c b/app/boards/shields/nice_view/widgets/status.c index 601ff546e..c7d489648 100644 --- a/app/boards/shields/nice_view/widgets/status.c +++ b/app/boards/shields/nice_view/widgets/status.c @@ -17,6 +17,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include #include +#include #include #include #include @@ -282,6 +283,7 @@ ZMK_SUBSCRIPTION(widget_output_status, zmk_usb_conn_state_changed); #endif #if defined(CONFIG_ZMK_BLE) ZMK_SUBSCRIPTION(widget_output_status, zmk_ble_active_profile_changed); +ZMK_SUBSCRIPTION(widget_output_status, zmk_ble_inactive_profile_changed); #endif static void set_layer_status(struct zmk_widget_status *widget, struct layer_status_state state) { diff --git a/app/include/zmk/events/ble_inactive_profile_changed.h b/app/include/zmk/events/ble_inactive_profile_changed.h new file mode 100644 index 000000000..f93ea164c --- /dev/null +++ b/app/include/zmk/events/ble_inactive_profile_changed.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include + +#include + +struct zmk_ble_inactive_profile_changed { + uint8_t index; + struct zmk_ble_profile *profile; +}; + +ZMK_EVENT_DECLARE(zmk_ble_inactive_profile_changed); diff --git a/app/src/ble.c b/app/src/ble.c index 94c1b2936..ab59e2461 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -36,6 +36,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include #include +#include #if IS_ENABLED(CONFIG_ZMK_BLE_PASSKEY_ENTRY) #include @@ -96,6 +97,22 @@ static void raise_profile_changed_event_callback(struct k_work *work) { K_WORK_DEFINE(raise_profile_changed_event_work, raise_profile_changed_event_callback); +static void raise_inactive_profile_changed_event(uint8_t index) { + raise_zmk_ble_inactive_profile_changed( + (struct zmk_ble_inactive_profile_changed){.index = index, .profile = &profiles[index]}); +} + +struct raise_inactive_profile_changed_event_work { + struct k_work work; + uint8_t index; +} raise_inactive_profile_changed_event_work; + +static void raise_inactive_profile_changed_event_callback(struct k_work *work) { + struct raise_inactive_profile_changed_event_work *info = + CONTAINER_OF(work, struct raise_inactive_profile_changed_event_work, work); + raise_inactive_profile_changed_event(info->index); +} + bool zmk_ble_active_profile_is_open(void) { return zmk_ble_profile_is_open(active_profile); } bool zmk_ble_profile_is_open(uint8_t index) { @@ -527,6 +544,13 @@ static void connected(struct bt_conn *conn, uint8_t err) { if (is_conn_active_profile(conn)) { LOG_DBG("Active profile connected"); k_work_submit(&raise_profile_changed_event_work); + } else { + const int profile_index = zmk_ble_profile_index(bt_conn_get_dst(conn)); + if (profile_index > -1) { + LOG_DBG("Other profile connected"); + raise_inactive_profile_changed_event_work.index = profile_index; + k_work_submit(&raise_inactive_profile_changed_event_work.work); + } } } @@ -552,6 +576,13 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) { if (is_conn_active_profile(conn)) { LOG_DBG("Active profile disconnected"); k_work_submit(&raise_profile_changed_event_work); + } else { + const int profile_index = zmk_ble_profile_index(bt_conn_get_dst(conn)); + if (profile_index > -1) { + LOG_DBG("Other profile disconnected"); + raise_inactive_profile_changed_event_work.index = profile_index; + k_work_submit(&raise_inactive_profile_changed_event_work.work); + } } } @@ -742,6 +773,8 @@ static int zmk_ble_init(void) { #if IS_ENABLED(CONFIG_SETTINGS) settings_register(&profiles_handler); k_work_init_delayable(&ble_save_work, ble_save_profile_work); + k_work_init(&raise_inactive_profile_changed_event_work.work, + raise_inactive_profile_changed_event_callback); #else zmk_ble_complete_startup(); #endif diff --git a/app/src/events/ble_inactive_profile_changed.c b/app/src/events/ble_inactive_profile_changed.c new file mode 100644 index 000000000..1a671af5a --- /dev/null +++ b/app/src/events/ble_inactive_profile_changed.c @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2025 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +ZMK_EVENT_IMPL(zmk_ble_inactive_profile_changed); \ No newline at end of file