Skip to content

Commit

Permalink
fixup! Include the serial number in the Bluetooth device name
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisandreae committed Nov 19, 2023
1 parent c4d42e5 commit 35d02e6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
10 changes: 10 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ config ZMK_BLE_CLEAR_BONDS_ON_START
bool "Configuration that clears all bond information from the keyboard on startup."
default n

config ZMK_BLE_DEVICE_NAME_APPEND_SN
bool "Append the device serial number to the Bluetooth device name"
default n
select BT_DEVICE_NAME_DYNAMIC

config ZMK_BLE_DEVICE_NAME_SN_CHARS
int "Number of hexadecimal digits of serial number to append to the BT device name"
default 6
depends on ZMK_BLE_DEVICE_NAME_APPEND_SN

# HID GATT notifications sent this way are *not* picked up by Linux, and possibly others.
config BT_GATT_NOTIFY_MULTIPLE
default n
Expand Down
10 changes: 0 additions & 10 deletions app/boards/arm/glove80/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,3 @@ config BOARD_ENABLE_DCDC
select SOC_DCDC_NRF52X
default y
depends on (BOARD_GLOVE80_LH || BOARD_GLOVE80_RH)

config BT_DEVICE_NAME_APPEND_SN
bool "Append serial number to BT device name"
default n
depends on BT_DEVICE_NAME_DYNAMIC

config BT_DEVICE_NAME_SN_BYTES
int "Number of bytes of serial number to append to the BT device name"
default 4
depends on BT_DEVICE_NAME_APPEND_SN
5 changes: 1 addition & 4 deletions app/boards/arm/glove80/glove80_lh_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ CONFIG_USB_DEVICE_VID=0x16c0
CONFIG_USB_DEVICE_MANUFACTURER="MoErgo"
CONFIG_USB_DEVICE_SN="moergo.com:GLV80-0123456789ABCDEF"

CONFIG_BT_DEVICE_NAME="Glove80 "
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_APPEND_SN=y
CONFIG_BT_DEVICE_NAME_SN_BYTES=6
CONFIG_BT_DEVICE_NAME="Glove80"

CONFIG_BT_DIS_PNP_PID=0x27db
CONFIG_BT_DIS_PNP_VID=0x16c0
Expand Down
13 changes: 7 additions & 6 deletions app/src/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ enum advertising_type {
static struct zmk_ble_profile profiles[ZMK_BLE_PROFILE_COUNT];
static uint8_t active_profile;

#if IS_ENABLED(CONFIG_BT_DEVICE_NAME_APPEND_SN)
#if IS_ENABLED(CONFIG_ZMK_BLE_DEVICE_NAME_APPEND_SN)

static char bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME) + CONFIG_BT_DEVICE_NAME_SN_BYTES];
static char bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME) + CONFIG_ZMK_BLE_DEVICE_NAME_SN_CHARS + 1];

void fill_serial_number(char *buf, int length);

// configure the BT device name by appending a serial number prefix to
// CONFIG_BT_DEVICE_NAME
void init_bt_device_name() {
strncpy(bt_device_name, CONFIG_BT_DEVICE_NAME, sizeof(bt_device_name));
fill_serial_number(bt_device_name + sizeof(CONFIG_BT_DEVICE_NAME) - 1,
CONFIG_BT_DEVICE_NAME_SN_BYTES);
bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME) - 1] = ' ';
fill_serial_number(&bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME)],
CONFIG_ZMK_BLE_DEVICE_NAME_SN_CHARS);
bt_device_name[sizeof(bt_device_name) - 1] = '\0';
}

Expand Down Expand Up @@ -648,7 +649,7 @@ static void zmk_ble_ready(int err) {
}

static int zmk_ble_init(const struct device *_arg) {
#if IS_ENABLED(CONFIG_BT_DEVICE_NAME_APPEND_SN)
#if IS_ENABLED(CONFIG_ZMK_BLE_DEVICE_NAME_APPEND_SN)
init_bt_device_name();
#endif

Expand All @@ -674,7 +675,7 @@ static int zmk_ble_init(const struct device *_arg) {
settings_load_subtree("bt");
#endif

#if IS_ENABLED(CONFIG_BT_DEVICE_NAME_APPEND_SN)
#if IS_ENABLED(CONFIG_ZMK_BLE_DEVICE_NAME_APPEND_SN)
if (strcmp(bt_get_name(), bt_device_name) != 0) {
bt_set_name(bt_device_name);
}
Expand Down

0 comments on commit 35d02e6

Please sign in to comment.