feat(ble): Add event `zmk_ble_advertising_status_changed`

Add event `zmk_ble_advertising_status_changed` to notify about
advertising status changes.
New advertising status will be send within the event data.

Closes: #2872
This commit is contained in:
Tobias Adolph 2025-03-13 21:56:03 +01:00 committed by Tobias Adolph
parent c7fae18ae1
commit 0c683380c3
5 changed files with 45 additions and 6 deletions

View File

@ -81,6 +81,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_advertising_status_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)

View File

@ -19,6 +19,12 @@
#define ZMK_BLE_PROFILE_COUNT CONFIG_BT_MAX_PAIRED
#endif
enum zmk_ble_advertising_type {
ZMK_ADV_NONE,
ZMK_ADV_DIR,
ZMK_ADV_CONN,
};
void zmk_ble_clear_bonds(void);
int zmk_ble_prof_next(void);
int zmk_ble_prof_prev(void);

View File

@ -0,0 +1,19 @@
/*
* Copyright (c) 2025 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <zephyr/kernel.h>
#include <zmk/event_manager.h>
#include <zephyr/device.h>
#include <zmk/ble.h>
struct zmk_ble_advertising_status_changed {
enum zmk_ble_advertising_type advertising_status;
};
ZMK_EVENT_DECLARE(zmk_ble_advertising_status_changed);

View File

@ -36,6 +36,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/split/bluetooth/uuid.h>
#include <zmk/event_manager.h>
#include <zmk/events/ble_active_profile_changed.h>
#include <zmk/events/ble_advertising_status_changed.h>
#if IS_ENABLED(CONFIG_ZMK_BLE_PASSKEY_ENTRY)
#include <zmk/events/keycode_state_changed.h>
@ -47,11 +48,7 @@ RING_BUF_DECLARE(passkey_entries, PASSKEY_DIGITS);
#endif /* IS_ENABLED(CONFIG_ZMK_BLE_PASSKEY_ENTRY) */
enum advertising_type {
ZMK_ADV_NONE,
ZMK_ADV_DIR,
ZMK_ADV_CONN,
} advertising_status;
enum zmk_ble_advertising_type advertising_status;
#define CURR_ADV(adv) (adv << 4)
@ -179,7 +176,8 @@ int update_advertising(void) {
int err = 0;
bt_addr_le_t *addr;
struct bt_conn *conn;
enum advertising_type desired_adv = ZMK_ADV_NONE;
enum zmk_ble_advertising_type desired_adv = ZMK_ADV_NONE;
enum zmk_ble_advertising_type previous_adv = advertising_status;
if (zmk_ble_active_profile_is_open()) {
desired_adv = ZMK_ADV_CONN;
@ -217,6 +215,11 @@ int update_advertising(void) {
break;
}
if (previous_adv != advertising_status) {
raise_zmk_ble_advertising_status_changed(
(struct zmk_ble_advertising_status_changed){.advertising_status = advertising_status});
}
return 0;
};

View File

@ -0,0 +1,10 @@
/*
* Copyright (c) 2025 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#include <zephyr/kernel.h>
#include <zmk/events/ble_advertising_status_changed.h>
ZMK_EVENT_IMPL(zmk_ble_advertising_status_changed);