diff --git a/include/bluetooth/services/bas.h b/include/bluetooth/services/bas.h new file mode 100644 index 0000000000..2f5bc7279e --- /dev/null +++ b/include/bluetooth/services/bas.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018 Nordic Semiconductor ASA + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_BAS_H_ +#define ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_BAS_H_ + +/** + * @brief Battery Service (BAS) + * @defgroup bt_gatt_bas Battery Service (BAS) + * @ingroup bluetooth + * @{ + * + * [Experimental] Users should note that the APIs can change + * as a part of ongoing development. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** @brief Read battery level value. + * + * Read the characteristic value of the battery level + * + * @return The battery level in percent. + */ +u8_t bt_gatt_bas_get_battery_level(void); + +/** @brief Update battery level value. + * + * Update the characteristic value of the battery level + * This will send a GATT notification to all current subscribers. + * + * @param level The battery level in percent. + * + * @return Zero in case of success and error code in case of error. + */ +int bt_gatt_bas_set_battery_level(u8_t level); + + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_BAS_H_ */ diff --git a/samples/bluetooth/gatt/bas.c b/samples/bluetooth/gatt/bas.c deleted file mode 100644 index b1cd9810b3..0000000000 --- a/samples/bluetooth/gatt/bas.c +++ /dev/null @@ -1,70 +0,0 @@ -/** @file - * @brief BAS Service sample - */ - -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -static struct bt_gatt_ccc_cfg blvl_ccc_cfg[BT_GATT_CCC_MAX] = {}; -static u8_t simulate_blvl; -static u8_t battery = 100U; - -static void blvl_ccc_cfg_changed(const struct bt_gatt_attr *attr, - u16_t value) -{ - simulate_blvl = (value == BT_GATT_CCC_NOTIFY) ? 1 : 0; -} - -static ssize_t read_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr, - void *buf, u16_t len, u16_t offset) -{ - const char *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(*value)); -} - -/* Battery Service Declaration */ -BT_GATT_SERVICE_DEFINE(bas_svc, - BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS), - BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, - BT_GATT_PERM_READ, read_blvl, NULL, &battery), - BT_GATT_CCC(blvl_ccc_cfg, blvl_ccc_cfg_changed), -); - -void bas_init(void) -{ -} - -void bas_notify(void) -{ - if (!simulate_blvl) { - return; - } - - battery--; - if (!battery) { - /* Software eco battery charger */ - battery = 100U; - } - - bt_gatt_notify(NULL, &bas_svc.attrs[1], &battery, sizeof(battery)); -} diff --git a/samples/bluetooth/gatt/bas.h b/samples/bluetooth/gatt/bas.h deleted file mode 100644 index b1a5963702..0000000000 --- a/samples/bluetooth/gatt/bas.h +++ /dev/null @@ -1,20 +0,0 @@ -/** @file - * @brief BAS Service sample - */ - -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef __cplusplus -extern "C" { -#endif - -void bas_init(void); -void bas_notify(void); - -#ifdef __cplusplus -} -#endif diff --git a/samples/bluetooth/peripheral/CMakeLists.txt b/samples/bluetooth/peripheral/CMakeLists.txt index bf3bd2d8b0..c422689447 100644 --- a/samples/bluetooth/peripheral/CMakeLists.txt +++ b/samples/bluetooth/peripheral/CMakeLists.txt @@ -7,7 +7,6 @@ project(peripheral) target_sources(app PRIVATE src/main.c ../gatt/hrs.c - ../gatt/bas.c ../gatt/cts.c ) diff --git a/samples/bluetooth/peripheral/prj.conf b/samples/bluetooth/peripheral/prj.conf index 129c387f48..7aca9a6857 100644 --- a/samples/bluetooth/peripheral/prj.conf +++ b/samples/bluetooth/peripheral/prj.conf @@ -8,6 +8,7 @@ CONFIG_BT_SIGNING=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_GATT_DIS=y CONFIG_BT_ATT_PREPARE_COUNT=5 +CONFIG_BT_GATT_BAS=y CONFIG_BT_PRIVACY=y CONFIG_BT_DEVICE_NAME="Zephyr Peripheral Sample Long Name" CONFIG_BT_DEVICE_APPEARANCE=833 diff --git a/samples/bluetooth/peripheral/src/main.c b/samples/bluetooth/peripheral/src/main.c index 108d4533a7..8b3c3ad83c 100644 --- a/samples/bluetooth/peripheral/src/main.c +++ b/samples/bluetooth/peripheral/src/main.c @@ -21,9 +21,9 @@ #include #include #include +#include #include -#include #include /* Custom Service Variables */ @@ -294,6 +294,19 @@ static struct bt_conn_auth_cb auth_cb_display = { .cancel = auth_cancel, }; +static void bas_notify(void) +{ + u8_t battery_level = bt_gatt_bas_get_battery_level(); + + battery_level--; + + if (!battery_level) { + battery_level = 100U; + } + + bt_gatt_bas_set_battery_level(battery_level); +} + void main(void) { int err; diff --git a/samples/bluetooth/peripheral_csc/CMakeLists.txt b/samples/bluetooth/peripheral_csc/CMakeLists.txt index 61c853debf..cb77a608bc 100644 --- a/samples/bluetooth/peripheral_csc/CMakeLists.txt +++ b/samples/bluetooth/peripheral_csc/CMakeLists.txt @@ -7,7 +7,6 @@ project(peripheral_csc) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources} - ../gatt/bas.c ) zephyr_library_include_directories($ENV{ZEPHYR_BASE}/samples/bluetooth) diff --git a/samples/bluetooth/peripheral_csc/prj.conf b/samples/bluetooth/peripheral_csc/prj.conf index 4f0eb5e733..aa6ca4a3af 100644 --- a/samples/bluetooth/peripheral_csc/prj.conf +++ b/samples/bluetooth/peripheral_csc/prj.conf @@ -4,5 +4,6 @@ CONFIG_BT=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_GATT_DIS=y CONFIG_BT_GATT_DIS_PNP=n +CONFIG_BT_GATT_BAS=y CONFIG_BT_DEVICE_NAME="CSC peripheral" CONFIG_BT_DEVICE_APPEARANCE=1157 diff --git a/samples/bluetooth/peripheral_csc/src/main.c b/samples/bluetooth/peripheral_csc/src/main.c index 66270a226f..1e47f064a4 100644 --- a/samples/bluetooth/peripheral_csc/src/main.c +++ b/samples/bluetooth/peripheral_csc/src/main.c @@ -20,8 +20,7 @@ #include #include #include - -#include +#include #define CSC_SUPPORTED_LOCATIONS { CSC_LOC_OTHER, \ CSC_LOC_FRONT_WHEEL, \ @@ -375,8 +374,6 @@ static void bt_ready(int err) printk("Bluetooth initialized\n"); - bas_init(); - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); if (err) { printk("Advertising failed to start (err %d)\n", err); @@ -386,6 +383,19 @@ static void bt_ready(int err) printk("Advertising successfully started\n"); } +static void bas_notify(void) +{ + u8_t battery_level = bt_gatt_bas_get_battery_level(); + + battery_level--; + + if (!battery_level) { + battery_level = 100U; + } + + bt_gatt_bas_set_battery_level(battery_level); +} + void main(void) { int err; diff --git a/samples/bluetooth/peripheral_esp/CMakeLists.txt b/samples/bluetooth/peripheral_esp/CMakeLists.txt index 9054260c11..9c3fcb9063 100644 --- a/samples/bluetooth/peripheral_esp/CMakeLists.txt +++ b/samples/bluetooth/peripheral_esp/CMakeLists.txt @@ -6,7 +6,6 @@ project(peripheral_esp) target_sources(app PRIVATE src/main.c - ../gatt/bas.c ) zephyr_library_include_directories($ENV{ZEPHYR_BASE}/samples/bluetooth) diff --git a/samples/bluetooth/peripheral_esp/prj.conf b/samples/bluetooth/peripheral_esp/prj.conf index ce719b8b43..4c0306c3d2 100644 --- a/samples/bluetooth/peripheral_esp/prj.conf +++ b/samples/bluetooth/peripheral_esp/prj.conf @@ -5,4 +5,5 @@ CONFIG_TINYCRYPT=y CONFIG_BT_DEVICE_NAME="ESP peripheral" CONFIG_BT_GATT_DIS=y CONFIG_BT_GATT_DIS_PNP=n +CONFIG_BT_GATT_BAS=y CONFIG_BT_DEVICE_APPEARANCE=768 diff --git a/samples/bluetooth/peripheral_esp/src/main.c b/samples/bluetooth/peripheral_esp/src/main.c index 5b008abfc5..f821007608 100644 --- a/samples/bluetooth/peripheral_esp/src/main.c +++ b/samples/bluetooth/peripheral_esp/src/main.c @@ -20,8 +20,7 @@ #include #include #include - -#include +#include #define SENSOR_1_NAME "Temperature Sensor 1" #define SENSOR_2_NAME "Temperature Sensor 2" @@ -387,8 +386,6 @@ static void bt_ready(int err) printk("Bluetooth initialized\n"); - bas_init(); - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); if (err) { printk("Advertising failed to start (err %d)\n", err); @@ -422,6 +419,19 @@ static struct bt_conn_auth_cb auth_cb_display = { .cancel = auth_cancel, }; +static void bas_notify(void) +{ + u8_t battery_level = bt_gatt_bas_get_battery_level(); + + battery_level--; + + if (!battery_level) { + battery_level = 100U; + } + + bt_gatt_bas_set_battery_level(battery_level); +} + void main(void) { int err; diff --git a/samples/bluetooth/peripheral_hids/CMakeLists.txt b/samples/bluetooth/peripheral_hids/CMakeLists.txt index c72d55ae21..565ec9e380 100644 --- a/samples/bluetooth/peripheral_hids/CMakeLists.txt +++ b/samples/bluetooth/peripheral_hids/CMakeLists.txt @@ -8,7 +8,6 @@ FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources} ../gatt/hog.c - ../gatt/bas.c ) zephyr_library_include_directories($ENV{ZEPHYR_BASE}/samples/bluetooth) diff --git a/samples/bluetooth/peripheral_hids/prj.conf b/samples/bluetooth/peripheral_hids/prj.conf index bf907c5b68..b158bb8b2f 100644 --- a/samples/bluetooth/peripheral_hids/prj.conf +++ b/samples/bluetooth/peripheral_hids/prj.conf @@ -6,6 +6,7 @@ CONFIG_BT_DEBUG_LOG=y CONFIG_BT_SMP=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_GATT_DIS=y +CONFIG_BT_GATT_BAS=y CONFIG_BT_DEVICE_NAME="Test HoG mouse" CONFIG_BT_DEVICE_APPEARANCE=962 diff --git a/samples/bluetooth/peripheral_hids/src/main.c b/samples/bluetooth/peripheral_hids/src/main.c index b997828b6a..17e1cbc58d 100644 --- a/samples/bluetooth/peripheral_hids/src/main.c +++ b/samples/bluetooth/peripheral_hids/src/main.c @@ -22,7 +22,6 @@ #include #include -#include #include static const struct bt_data ad[] = { @@ -83,7 +82,6 @@ static void bt_ready(int err) printk("Bluetooth initialized\n"); - bas_init(); hog_init(); if (IS_ENABLED(CONFIG_SETTINGS)) { diff --git a/samples/bluetooth/peripheral_hr/CMakeLists.txt b/samples/bluetooth/peripheral_hr/CMakeLists.txt index 801210f2d0..06415c2076 100644 --- a/samples/bluetooth/peripheral_hr/CMakeLists.txt +++ b/samples/bluetooth/peripheral_hr/CMakeLists.txt @@ -9,7 +9,6 @@ FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources} ../gatt/hrs.c - ../gatt/bas.c ) zephyr_library_include_directories($ENV{ZEPHYR_BASE}/samples/bluetooth) diff --git a/samples/bluetooth/peripheral_hr/prj.conf b/samples/bluetooth/peripheral_hr/prj.conf index 687cd696d4..7d290e0c64 100644 --- a/samples/bluetooth/peripheral_hr/prj.conf +++ b/samples/bluetooth/peripheral_hr/prj.conf @@ -4,5 +4,6 @@ CONFIG_BT_SMP=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_GATT_DIS=y CONFIG_BT_GATT_DIS_PNP=n +CONFIG_BT_GATT_BAS=y CONFIG_BT_DEVICE_NAME="Zephyr Heartrate Sensor" CONFIG_BT_DEVICE_APPEARANCE=833 diff --git a/samples/bluetooth/peripheral_hr/src/main.c b/samples/bluetooth/peripheral_hr/src/main.c index 76f7759b63..720f4cc49a 100644 --- a/samples/bluetooth/peripheral_hr/src/main.c +++ b/samples/bluetooth/peripheral_hr/src/main.c @@ -19,9 +19,9 @@ #include #include #include +#include #include -#include struct bt_conn *default_conn; @@ -65,7 +65,6 @@ static void bt_ready(int err) printk("Bluetooth initialized\n"); hrs_init(0x01); - bas_init(); err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); if (err) { @@ -89,6 +88,19 @@ static struct bt_conn_auth_cb auth_cb_display = { .cancel = auth_cancel, }; +static void bas_notify(void) +{ + u8_t battery_level = bt_gatt_bas_get_battery_level(); + + battery_level--; + + if (!battery_level) { + battery_level = 100U; + } + + bt_gatt_bas_set_battery_level(battery_level); +} + void main(void) { int err; diff --git a/samples/bluetooth/peripheral_ht/CMakeLists.txt b/samples/bluetooth/peripheral_ht/CMakeLists.txt index 3568428436..afaa8213e6 100644 --- a/samples/bluetooth/peripheral_ht/CMakeLists.txt +++ b/samples/bluetooth/peripheral_ht/CMakeLists.txt @@ -9,7 +9,6 @@ FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources} ../gatt/hts.c - ../gatt/bas.c ) zephyr_library_include_directories($ENV{ZEPHYR_BASE}/samples/bluetooth) diff --git a/samples/bluetooth/peripheral_ht/prj.conf b/samples/bluetooth/peripheral_ht/prj.conf index b8a3baf916..3e6cdfeafa 100644 --- a/samples/bluetooth/peripheral_ht/prj.conf +++ b/samples/bluetooth/peripheral_ht/prj.conf @@ -4,6 +4,7 @@ CONFIG_BT_SMP=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_GATT_DIS=y CONFIG_BT_GATT_DIS_PNP=n +CONFIG_BT_GATT_BAS=y CONFIG_BT_DEVICE_NAME="Zephyr Health Thermometer" CONFIG_BT_DEVICE_APPEARANCE=768 CONFIG_BT_ATT_ENFORCE_FLOW=n diff --git a/samples/bluetooth/peripheral_ht/src/main.c b/samples/bluetooth/peripheral_ht/src/main.c index 03e27c0e58..c83908bef9 100644 --- a/samples/bluetooth/peripheral_ht/src/main.c +++ b/samples/bluetooth/peripheral_ht/src/main.c @@ -19,9 +19,9 @@ #include #include #include +#include #include -#include struct bt_conn *default_conn; @@ -68,7 +68,6 @@ static void bt_ready(int err) printk("Bluetooth initialized\n"); hts_init(); - bas_init(); err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); if (err) { @@ -92,6 +91,19 @@ static struct bt_conn_auth_cb auth_cb_display = { .cancel = auth_cancel, }; +static void bas_notify(void) +{ + u8_t battery_level = bt_gatt_bas_get_battery_level(); + + battery_level--; + + if (!battery_level) { + battery_level = 100U; + } + + bt_gatt_bas_set_battery_level(battery_level); +} + void main(void) { int err; diff --git a/subsys/bluetooth/services/CMakeLists.txt b/subsys/bluetooth/services/CMakeLists.txt index 4b125091d8..5e18d54988 100644 --- a/subsys/bluetooth/services/CMakeLists.txt +++ b/subsys/bluetooth/services/CMakeLists.txt @@ -2,3 +2,5 @@ zephyr_sources_ifdef(CONFIG_BT_GATT_DIS dis.c) + +zephyr_sources_ifdef(CONFIG_BT_GATT_BAS bas.c) diff --git a/subsys/bluetooth/services/Kconfig b/subsys/bluetooth/services/Kconfig index 1314f17a92..45555181fa 100644 --- a/subsys/bluetooth/services/Kconfig +++ b/subsys/bluetooth/services/Kconfig @@ -11,6 +11,8 @@ menu "GATT Services" source "subsys/bluetooth/services/Kconfig.dis" +source "subsys/bluetooth/services/Kconfig.bas" + endmenu -endif # BT_CONN +endif #BT_CONN diff --git a/subsys/bluetooth/services/Kconfig.bas b/subsys/bluetooth/services/Kconfig.bas new file mode 100644 index 0000000000..056dc05975 --- /dev/null +++ b/subsys/bluetooth/services/Kconfig.bas @@ -0,0 +1,29 @@ +# Kconfig - Bluetooth GATT Battery service +# +# Copyright (c) 2018 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +menuconfig BT_GATT_BAS + bool "Enable GATT Battery service" + select SENSOR + default n + +if BT_GATT_BAS + +config BT_GATT_BAS_LOG_LEVEL + int "Battery service log level" + depends on LOG + range 0 4 + default 0 + help + Sets log level for the Battery service. + Levels are: + 0 OFF, do not write + 1 ERROR, only write LOG_ERR + 2 WARNING, write LOG_WRN in addition to previous level + 3 INFO, write LOG_INF in addition to previous levels + 4 DEBUG, write LOG_DBG in addition to previous levels + +endif #BT_GATT_BAS diff --git a/subsys/bluetooth/services/bas.c b/subsys/bluetooth/services/bas.c new file mode 100644 index 0000000000..8b4fe65a42 --- /dev/null +++ b/subsys/bluetooth/services/bas.c @@ -0,0 +1,88 @@ +/** @file + * @brief GATT Battery Service + */ + +/* + * Copyright (c) 2018 Nordic Semiconductor ASA + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define LOG_LEVEL CONFIG_BT_GATT_BAS_LOG_LEVEL +#include +LOG_MODULE_REGISTER(bas); + +static struct bt_gatt_ccc_cfg blvl_ccc_cfg[BT_GATT_CCC_MAX] = {}; + +static u8_t battery_level = 100U; + +static void blvl_ccc_cfg_changed(const struct bt_gatt_attr *attr, + u16_t value) +{ + ARG_UNUSED(attr); + + bool notif_enabled = (value == BT_GATT_CCC_NOTIFY); + + LOG_INF("BAS Notifications %s", notif_enabled ? "enabled" : "disabled"); +} + +static ssize_t read_blvl(struct bt_conn *conn, + const struct bt_gatt_attr *attr, void *buf, + u16_t len, u16_t offset) +{ + u8_t lvl8 = battery_level; + + return bt_gatt_attr_read(conn, attr, buf, len, offset, &lvl8, + sizeof(lvl8)); +} + +BT_GATT_SERVICE_DEFINE(bas, + BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS), + BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, + BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_READ, read_blvl, NULL, + &battery_level), + BT_GATT_CCC(blvl_ccc_cfg, blvl_ccc_cfg_changed), +); + +static int bas_init(struct device *dev) +{ + ARG_UNUSED(dev); + + return 0; +} + +u8_t bt_gatt_bas_get_battery_level(void) +{ + return battery_level; +} + +int bt_gatt_bas_set_battery_level(u8_t level) +{ + int rc; + + if (level > 100U) { + return -EINVAL; + } + + battery_level = level; + + rc = bt_gatt_notify(NULL, &bas.attrs[1], &level, sizeof(level)); + + return rc == -ENOTCONN ? 0 : rc; +} + +SYS_INIT(bas_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/tests/bluetooth/bsim_bt/bsim_test_app/CMakeLists.txt b/tests/bluetooth/bsim_bt/bsim_test_app/CMakeLists.txt index 2ca0eb2189..257eac2a19 100644 --- a/tests/bluetooth/bsim_bt/bsim_test_app/CMakeLists.txt +++ b/tests/bluetooth/bsim_bt/bsim_test_app/CMakeLists.txt @@ -18,7 +18,6 @@ target_sources(app PRIVATE src/test_connect1.c src/test_connect2.c ../../../../samples/bluetooth/gatt/hrs.c - ../../../../samples/bluetooth/gatt/bas.c ) zephyr_include_directories( diff --git a/tests/bluetooth/bsim_bt/bsim_test_app/prj.conf b/tests/bluetooth/bsim_bt/bsim_test_app/prj.conf index 6d8642e324..998f1c683b 100644 --- a/tests/bluetooth/bsim_bt/bsim_test_app/prj.conf +++ b/tests/bluetooth/bsim_bt/bsim_test_app/prj.conf @@ -5,6 +5,7 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT_PRIVACY=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y +CONFIG_BT_GATT_BAS=y CONFIG_BT_ATT_PREPARE_COUNT=2 CONFIG_BT_GATT_CLIENT=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y diff --git a/tests/bluetooth/bsim_bt/bsim_test_app/prj_split.conf b/tests/bluetooth/bsim_bt/bsim_test_app/prj_split.conf index 3a06a672bb..2d8892d216 100644 --- a/tests/bluetooth/bsim_bt/bsim_test_app/prj_split.conf +++ b/tests/bluetooth/bsim_bt/bsim_test_app/prj_split.conf @@ -5,6 +5,7 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT_PRIVACY=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y +CONFIG_BT_GATT_BAS=y CONFIG_BT_ATT_PREPARE_COUNT=2 CONFIG_BT_GATT_CLIENT=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y diff --git a/tests/bluetooth/bsim_bt/bsim_test_app/src/test_connect2.c b/tests/bluetooth/bsim_bt/bsim_test_app/src/test_connect2.c index 9321dc59a4..2375096464 100644 --- a/tests/bluetooth/bsim_bt/bsim_test_app/src/test_connect2.c +++ b/tests/bluetooth/bsim_bt/bsim_test_app/src/test_connect2.c @@ -22,10 +22,10 @@ #include #include #include +#include #include #include -#include static struct bt_conn *default_conn; @@ -109,7 +109,6 @@ static void bt_ready(int err) printk("Bluetooth initialized\n"); hrs_init(0x01); - bas_init(); err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); if (err) { @@ -120,6 +119,19 @@ static void bt_ready(int err) printk("Advertising successfully started\n"); } +static void bas_notify(void) +{ + u8_t battery_level = bt_gatt_bas_get_battery_level(); + + battery_level--; + + if (!battery_level) { + battery_level = 100U; + } + + bt_gatt_bas_set_battery_level(battery_level); +} + static void test_con2_main(void) { static int notify_count;