From d1fbc918fe04de1e20dec9776b31c4285a4df44b Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Tue, 29 Mar 2022 21:20:52 +0000 Subject: [PATCH 01/22] feat: register on BAS notifications of pheriperal --- app/src/split/bluetooth/central.c | 44 ++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 7eacc675..0b171349 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -41,6 +41,7 @@ struct peripheral_slot { struct bt_conn *conn; struct bt_gatt_discover_params discover_params; struct bt_gatt_subscribe_params subscribe_params; + struct bt_gatt_subscribe_params batt_lvl_subscribe_params; struct bt_gatt_discover_params sub_discover_params; uint16_t run_behavior_handle; uint8_t position_state[POSITION_STATE_DATA_LEN]; @@ -190,14 +191,32 @@ static uint8_t split_central_notify_func(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } -static void split_central_subscribe(struct bt_conn *conn) { +static uint8_t split_central_battery_level_notify_func(struct bt_conn *conn, + struct bt_gatt_subscribe_params *params, + const void *data, uint16_t length) { struct peripheral_slot *slot = peripheral_slot_for_conn(conn); + if (slot == NULL) { LOG_ERR("No peripheral state found for connection"); - return; + return BT_GATT_ITER_CONTINUE; } - int err = bt_gatt_subscribe(conn, &slot->subscribe_params); + if (!data) { + LOG_DBG("[UNSUBSCRIBED]"); + params->value_handle = 0U; + return BT_GATT_ITER_STOP; + } + + LOG_DBG("[BATTERY LEVEL NOTIFICATION] data %p length %u", data, length); + uint8_t battery_level = ((uint8_t *)data)[0]; + LOG_DBG("Battery level: %u", battery_level); + + return BT_GATT_ITER_CONTINUE; +} + +static void split_central_subscribe(struct bt_conn *conn, + struct bt_gatt_subscribe_params *subscribe_params) { + int err = bt_gatt_subscribe(conn, subscribe_params); switch (err) { case -EALREADY: LOG_DBG("[ALREADY SUBSCRIBED]"); @@ -235,23 +254,29 @@ static uint8_t split_central_chrc_discovery_func(struct bt_conn *conn, if (!bt_uuid_cmp(((struct bt_gatt_chrc *)attr->user_data)->uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_POSITION_STATE_UUID))) { LOG_DBG("Found position state characteristic"); - slot->discover_params.uuid = NULL; - slot->discover_params.start_handle = attr->handle + 2; - slot->discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; - slot->subscribe_params.disc_params = &slot->sub_discover_params; slot->subscribe_params.end_handle = slot->discover_params.end_handle; slot->subscribe_params.value_handle = bt_gatt_attr_value_handle(attr); slot->subscribe_params.notify = split_central_notify_func; slot->subscribe_params.value = BT_GATT_CCC_NOTIFY; - split_central_subscribe(conn); + split_central_subscribe(conn, &slot->subscribe_params); } else if (!bt_uuid_cmp(((struct bt_gatt_chrc *)attr->user_data)->uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_RUN_BEHAVIOR_UUID))) { LOG_DBG("Found run behavior handle"); slot->run_behavior_handle = bt_gatt_attr_value_handle(attr); + } else if (!bt_uuid_cmp(((struct bt_gatt_chrc *)attr->user_data)->uuid, + BT_UUID_BAS_BATTERY_LEVEL)) { + LOG_DBG("Found battery level characteristics"); + slot->batt_lvl_subscribe_params.disc_params = &slot->sub_discover_params; + slot->batt_lvl_subscribe_params.end_handle = slot->discover_params.end_handle; + slot->batt_lvl_subscribe_params.value_handle = bt_gatt_attr_value_handle(attr); + slot->batt_lvl_subscribe_params.notify = split_central_battery_level_notify_func; + slot->batt_lvl_subscribe_params.value = BT_GATT_CCC_NOTIFY; + split_central_subscribe(conn, &slot->batt_lvl_subscribe_params); } - bool subscribed = (slot->run_behavior_handle && slot->subscribe_params.value_handle); + bool subscribed = (slot->run_behavior_handle && slot->subscribe_params.value_handle && + slot->batt_lvl_subscribe_params.value_handle); return subscribed ? BT_GATT_ITER_STOP : BT_GATT_ITER_CONTINUE; } @@ -281,7 +306,6 @@ static uint8_t split_central_service_discovery_func(struct bt_conn *conn, LOG_DBG("Found split service"); slot->discover_params.uuid = NULL; slot->discover_params.func = split_central_chrc_discovery_func; - slot->discover_params.start_handle = attr->handle + 1; slot->discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; int err = bt_gatt_discover(conn, &slot->discover_params); From 446399aba81ef121b14585a08fcf21a4a3973d25 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Sun, 3 Apr 2022 14:16:13 +0000 Subject: [PATCH 02/22] feat: report peripheral battery level to host --- app/CMakeLists.txt | 3 +- .../zmk/events/battery_state_changed.h | 9 +- app/src/battery_split.c | 154 ++++++++++++++++++ app/src/events/battery_state_changed.c | 4 +- app/src/split/bluetooth/central.c | 19 +++ 5 files changed, 186 insertions(+), 3 deletions(-) create mode 100644 app/src/battery_split.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index b760389f..83d1f120 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -69,13 +69,14 @@ target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/behaviors/behavior target_sources_ifdef(CONFIG_ZMK_BACKLIGHT app PRIVATE src/behaviors/behavior_backlight.c) target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/behaviors/behavior_bt.c) target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/ble.c) -target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/battery.c) if (CONFIG_ZMK_SPLIT_BLE AND (NOT CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)) target_sources(app PRIVATE src/split_listener.c) target_sources(app PRIVATE src/split/bluetooth/service.c) + target_sources(app PRIVATE src/battery.c) endif() if (CONFIG_ZMK_SPLIT_BLE AND CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) target_sources(app PRIVATE src/split/bluetooth/central.c) + target_sources(app PRIVATE src/battery_split.c) endif() target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/usb.c) target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c) diff --git a/app/include/zmk/events/battery_state_changed.h b/app/include/zmk/events/battery_state_changed.h index 6a003d8d..336faf09 100644 --- a/app/include/zmk/events/battery_state_changed.h +++ b/app/include/zmk/events/battery_state_changed.h @@ -14,4 +14,11 @@ struct zmk_battery_state_changed { uint8_t state_of_charge; }; -ZMK_EVENT_DECLARE(zmk_battery_state_changed); \ No newline at end of file +ZMK_EVENT_DECLARE(zmk_battery_state_changed); + +struct zmk_peripheral_battery_state_changed { + // TODO: Other battery channels + uint8_t state_of_charge; +}; + +ZMK_EVENT_DECLARE(zmk_peripheral_battery_state_changed); \ No newline at end of file diff --git a/app/src/battery_split.c b/app/src/battery_split.c new file mode 100644 index 00000000..271867d1 --- /dev/null +++ b/app/src/battery_split.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include +#include + +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#include +#include +#include + +static uint8_t last_state_of_charge = 0; +static uint8_t last_state_of_peripheral_charge = 41; + +static void blvl_ccc_cfg_changed(const struct bt_gatt_attr *attr, + uint16_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, + uint16_t len, uint16_t offset) +{ + uint8_t lvl8 = last_state_of_charge; + return bt_gatt_attr_read(conn, attr, buf, len, offset, &lvl8, + sizeof(lvl8)); +} + +static ssize_t read_peripheral_blvl(struct bt_conn *conn, + const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) +{ + uint8_t lvl8 = last_state_of_peripheral_charge; + 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, + &last_state_of_charge), + BT_GATT_CCC(blvl_ccc_cfg_changed, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), + BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, + BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_READ, read_peripheral_blvl, NULL, + &last_state_of_peripheral_charge), + BT_GATT_CCC(blvl_ccc_cfg_changed, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE) +); + +const struct device *battery; + +int peripheral_batt_lvl_listener(const zmk_event_t *eh) { + const struct zmk_peripheral_battery_state_changed *ev = as_zmk_peripheral_battery_state_changed(eh); + LOG_DBG("Peripheral battery level event: %u", ev->state_of_charge); + last_state_of_peripheral_charge = ev->state_of_charge; + int rc = bt_gatt_notify(NULL, &bas.attrs[3], &last_state_of_peripheral_charge, sizeof(last_state_of_peripheral_charge)); + return rc; +}; + +ZMK_LISTENER(peripheral_batt_lvl_listener, peripheral_batt_lvl_listener); +ZMK_SUBSCRIPTION(peripheral_batt_lvl_listener, zmk_peripheral_battery_state_changed); + +uint8_t zmk_battery_state_of_charge() { return last_state_of_charge; } + +static int zmk_battery_update(const struct device *battery) { + struct sensor_value state_of_charge; + + int rc = sensor_sample_fetch_chan(battery, SENSOR_CHAN_GAUGE_STATE_OF_CHARGE); + + if (rc != 0) { + LOG_DBG("Failed to fetch battery values: %d", rc); + return rc; + } + + rc = sensor_channel_get(battery, SENSOR_CHAN_GAUGE_STATE_OF_CHARGE, &state_of_charge); + + if (rc != 0) { + LOG_DBG("Failed to get battery state of charge: %d", rc); + return rc; + } + + if (last_state_of_charge != state_of_charge.val1) { + last_state_of_charge = state_of_charge.val1; + + LOG_DBG("Setting BAS GATT battery level to %d.", last_state_of_charge); + + rc = bt_gatt_notify(NULL, &bas.attrs[1], &last_state_of_charge, sizeof(last_state_of_charge)); + rc = rc == -ENOTCONN ? 0 : rc; + if (rc != 0) { + LOG_WRN("Failed to set BAS GATT battery level (err %d)", rc); + return rc; + } + + rc = ZMK_EVENT_RAISE(new_zmk_battery_state_changed( + (struct zmk_battery_state_changed){.state_of_charge = last_state_of_charge})); + } + + return rc; +} + +static void zmk_battery_work(struct k_work *work) { + int rc = zmk_battery_update(battery); + + if (rc != 0) { + LOG_DBG("Failed to update battery value: %d.", rc); + } +} + +K_WORK_DEFINE(battery_work, zmk_battery_work); + +static void zmk_battery_timer(struct k_timer *timer) { k_work_submit(&battery_work); } + +K_TIMER_DEFINE(battery_timer, zmk_battery_timer, NULL); + +static int zmk_battery_init(const struct device *_arg) { + battery = device_get_binding("BATTERY"); + + if (battery == NULL) { + LOG_DBG("No battery device labelled BATTERY found."); + return -ENODEV; + } + + int rc = zmk_battery_update(battery); + + if (rc != 0) { + LOG_DBG("Failed to update battery value: %d.", rc); + return rc; + } + + k_timer_start(&battery_timer, K_MINUTES(1), K_MINUTES(1)); + + return 0; +} + +SYS_INIT(zmk_battery_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/app/src/events/battery_state_changed.c b/app/src/events/battery_state_changed.c index 435fb24d..be3a8699 100644 --- a/app/src/events/battery_state_changed.c +++ b/app/src/events/battery_state_changed.c @@ -7,4 +7,6 @@ #include #include -ZMK_EVENT_IMPL(zmk_battery_state_changed); \ No newline at end of file +ZMK_EVENT_IMPL(zmk_battery_state_changed); + +ZMK_EVENT_IMPL(zmk_peripheral_battery_state_changed); \ No newline at end of file diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 0b171349..6f622d17 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -24,6 +24,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include #include +#include #include static int start_scan(void); @@ -55,6 +56,9 @@ static const struct bt_uuid_128 split_service_uuid = BT_UUID_INIT_128(ZMK_SPLIT_ K_MSGQ_DEFINE(peripheral_event_msgq, sizeof(struct zmk_position_state_changed), CONFIG_ZMK_SPLIT_BLE_CENTRAL_POSITION_QUEUE_SIZE, 4); +K_MSGQ_DEFINE(peripheral_batt_lvl_msgq, sizeof(struct zmk_peripheral_battery_state_changed), + CONFIG_ZMK_SPLIT_BLE_CENTRAL_POSITION_QUEUE_SIZE, 4); + int peripheral_slot_index_for_conn(struct bt_conn *conn) { for (int i = 0; i < ZMK_BLE_SPLIT_PERIPHERAL_COUNT; i++) { if (peripherals[i].conn == conn) { @@ -191,6 +195,16 @@ static uint8_t split_central_notify_func(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } +void peripheral_batt_lvl_change_callback(struct k_work *work) { + struct zmk_peripheral_battery_state_changed ev; + while (k_msgq_get(&peripheral_batt_lvl_msgq, &ev, K_NO_WAIT) == 0) { + LOG_DBG("Triggering peripheral battery level change %u", ev.state_of_charge); + ZMK_EVENT_RAISE(new_zmk_peripheral_battery_state_changed(ev)); + } +} + +K_WORK_DEFINE(peripheral_batt_lvl_work, peripheral_batt_lvl_change_callback); + static uint8_t split_central_battery_level_notify_func(struct bt_conn *conn, struct bt_gatt_subscribe_params *params, const void *data, uint16_t length) { @@ -209,6 +223,11 @@ static uint8_t split_central_battery_level_notify_func(struct bt_conn *conn, LOG_DBG("[BATTERY LEVEL NOTIFICATION] data %p length %u", data, length); uint8_t battery_level = ((uint8_t *)data)[0]; + struct zmk_peripheral_battery_state_changed ev = { + .state_of_charge = battery_level + }; + k_msgq_put(&peripheral_batt_lvl_msgq, &ev, K_NO_WAIT); + k_work_submit(&peripheral_batt_lvl_work); LOG_DBG("Battery level: %u", battery_level); return BT_GATT_ITER_CONTINUE; From fbb02e24a90665f74c108b880aa3c571737602d6 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Sun, 3 Apr 2022 20:16:54 +0000 Subject: [PATCH 03/22] chore: cleanup --- app/src/battery_split.c | 73 ++++++++++++++----------------- app/src/split/bluetooth/central.c | 4 +- 2 files changed, 33 insertions(+), 44 deletions(-) diff --git a/app/src/battery_split.c b/app/src/battery_split.c index 271867d1..4d88344e 100644 --- a/app/src/battery_split.c +++ b/app/src/battery_split.c @@ -20,59 +20,50 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include static uint8_t last_state_of_charge = 0; -static uint8_t last_state_of_peripheral_charge = 41; +static uint8_t last_state_of_peripheral_charge = 0; -static void blvl_ccc_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) -{ - ARG_UNUSED(attr); +static void blvl_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { + ARG_UNUSED(attr); - bool notif_enabled = (value == BT_GATT_CCC_NOTIFY); + bool notif_enabled = (value == BT_GATT_CCC_NOTIFY); - LOG_INF("BAS Notifications %s", notif_enabled ? "enabled" : "disabled"); + 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, - uint16_t len, uint16_t offset) -{ - uint8_t lvl8 = last_state_of_charge; - return bt_gatt_attr_read(conn, attr, buf, len, offset, &lvl8, - sizeof(lvl8)); +static ssize_t read_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { + uint8_t lvl8 = last_state_of_charge; + return bt_gatt_attr_read(conn, attr, buf, len, offset, &lvl8, sizeof(lvl8)); } -static ssize_t read_peripheral_blvl(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - uint8_t lvl8 = last_state_of_peripheral_charge; - return bt_gatt_attr_read(conn, attr, buf, len, offset, &lvl8, - sizeof(lvl8)); +static ssize_t read_peripheral_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr, + void *buf, uint16_t len, uint16_t offset) { + uint8_t lvl8 = last_state_of_peripheral_charge; + 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, - &last_state_of_charge), - BT_GATT_CCC(blvl_ccc_cfg_changed, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), - BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, - BT_GATT_PERM_READ, read_peripheral_blvl, NULL, - &last_state_of_peripheral_charge), - BT_GATT_CCC(blvl_ccc_cfg_changed, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE) -); +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, &last_state_of_charge), + BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), + BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_READ, read_peripheral_blvl, NULL, + &last_state_of_peripheral_charge), + BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE)); const struct device *battery; int peripheral_batt_lvl_listener(const zmk_event_t *eh) { - const struct zmk_peripheral_battery_state_changed *ev = as_zmk_peripheral_battery_state_changed(eh); + const struct zmk_peripheral_battery_state_changed *ev = + as_zmk_peripheral_battery_state_changed(eh); + if (ev == NULL) { + return ZMK_EV_EVENT_BUBBLE; + }; LOG_DBG("Peripheral battery level event: %u", ev->state_of_charge); last_state_of_peripheral_charge = ev->state_of_charge; - int rc = bt_gatt_notify(NULL, &bas.attrs[3], &last_state_of_peripheral_charge, sizeof(last_state_of_peripheral_charge)); + int rc = bt_gatt_notify(NULL, &bas.attrs[3], &last_state_of_peripheral_charge, + sizeof(last_state_of_peripheral_charge)); return rc; }; @@ -103,9 +94,9 @@ static int zmk_battery_update(const struct device *battery) { LOG_DBG("Setting BAS GATT battery level to %d.", last_state_of_charge); - rc = bt_gatt_notify(NULL, &bas.attrs[1], &last_state_of_charge, sizeof(last_state_of_charge)); - rc = rc == -ENOTCONN ? 0 : rc; - if (rc != 0) { + rc = bt_gatt_notify(NULL, &bas.attrs[1], &last_state_of_charge, + sizeof(last_state_of_charge)); + if (rc != 0 && rc != -ENOTCONN) { LOG_WRN("Failed to set BAS GATT battery level (err %d)", rc); return rc; } diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 6f622d17..01c42a28 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -223,9 +223,7 @@ static uint8_t split_central_battery_level_notify_func(struct bt_conn *conn, LOG_DBG("[BATTERY LEVEL NOTIFICATION] data %p length %u", data, length); uint8_t battery_level = ((uint8_t *)data)[0]; - struct zmk_peripheral_battery_state_changed ev = { - .state_of_charge = battery_level - }; + struct zmk_peripheral_battery_state_changed ev = {.state_of_charge = battery_level}; k_msgq_put(&peripheral_batt_lvl_msgq, &ev, K_NO_WAIT); k_work_submit(&peripheral_batt_lvl_work); LOG_DBG("Battery level: %u", battery_level); From ba09d2fd0185fbb8f4ee0d1d08af8166650ad9cb Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Sun, 3 Apr 2022 21:53:08 +0000 Subject: [PATCH 04/22] feat: read initial peripheral battery level --- app/src/split/bluetooth/central.c | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 01c42a28..b618d239 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -43,6 +43,7 @@ struct peripheral_slot { struct bt_gatt_discover_params discover_params; struct bt_gatt_subscribe_params subscribe_params; struct bt_gatt_subscribe_params batt_lvl_subscribe_params; + struct bt_gatt_read_params batt_lvl_read_params; struct bt_gatt_discover_params sub_discover_params; uint16_t run_behavior_handle; uint8_t position_state[POSITION_STATE_DATA_LEN]; @@ -230,6 +231,38 @@ static uint8_t split_central_battery_level_notify_func(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } +static uint8_t split_central_battery_level_read_func(struct bt_conn *conn, uint8_t err, + struct bt_gatt_read_params *params, + const void *data, uint16_t length) { + if (err > 0) { + LOG_ERR("Error during reading peripheral battery level: %u", err); + return BT_GATT_ITER_STOP; + } + + struct peripheral_slot *slot = peripheral_slot_for_conn(conn); + + if (slot == NULL) { + LOG_ERR("No peripheral state found for connection"); + return BT_GATT_ITER_CONTINUE; + } + + if (!data) { + LOG_DBG("[READ COMPLETED]"); + return BT_GATT_ITER_STOP; + } + + LOG_DBG("[BATTERY LEVEL READ] data %p length %u", data, length); + + uint8_t battery_level = ((uint8_t *)data)[0]; + + LOG_DBG("Battery level: %u", battery_level); + + struct zmk_peripheral_battery_state_changed ev = {.state_of_charge = battery_level}; + k_msgq_put(&peripheral_batt_lvl_msgq, &ev, K_NO_WAIT); + k_work_submit(&peripheral_batt_lvl_work); + + return BT_GATT_ITER_CONTINUE; +} static void split_central_subscribe(struct bt_conn *conn, struct bt_gatt_subscribe_params *subscribe_params) { @@ -290,6 +323,12 @@ static uint8_t split_central_chrc_discovery_func(struct bt_conn *conn, slot->batt_lvl_subscribe_params.notify = split_central_battery_level_notify_func; slot->batt_lvl_subscribe_params.value = BT_GATT_CCC_NOTIFY; split_central_subscribe(conn, &slot->batt_lvl_subscribe_params); + + slot->batt_lvl_read_params.func = split_central_battery_level_read_func; + slot->batt_lvl_read_params.handle_count = 1; + slot->batt_lvl_read_params.single.handle = attr->handle + 1; + slot->batt_lvl_read_params.single.offset = 0; + bt_gatt_read(conn, &slot->batt_lvl_read_params); } bool subscribed = (slot->run_behavior_handle && slot->subscribe_params.value_handle && From c16fc9e881ae0884b8dd3534ae0c2a508b76885f Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Tue, 5 Apr 2022 21:49:10 +0000 Subject: [PATCH 05/22] fix: attribute value handle --- app/src/split/bluetooth/central.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index b618d239..cae4efc9 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -326,7 +326,7 @@ static uint8_t split_central_chrc_discovery_func(struct bt_conn *conn, slot->batt_lvl_read_params.func = split_central_battery_level_read_func; slot->batt_lvl_read_params.handle_count = 1; - slot->batt_lvl_read_params.single.handle = attr->handle + 1; + slot->batt_lvl_read_params.single.handle = bt_gatt_attr_value_handle(attr); slot->batt_lvl_read_params.single.offset = 0; bt_gatt_read(conn, &slot->batt_lvl_read_params); } From 2a74eecb6f2f05aac9a76ebf84ea1c84b383ef0b Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Tue, 5 Apr 2022 21:50:23 +0000 Subject: [PATCH 06/22] feat: add characteristic user description --- app/src/battery_split.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/battery_split.c b/app/src/battery_split.c index 4d88344e..fdb94853 100644 --- a/app/src/battery_split.c +++ b/app/src/battery_split.c @@ -46,10 +46,12 @@ 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, &last_state_of_charge), + BT_GATT_CUD("Central", BT_GATT_PERM_READ), BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ, read_peripheral_blvl, NULL, &last_state_of_peripheral_charge), + BT_GATT_CUD("Peripheral", BT_GATT_PERM_READ), BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE)); const struct device *battery; From f3923c037b77e583f8716add06a4d03c6b43eaab Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Tue, 5 Apr 2022 21:50:48 +0000 Subject: [PATCH 07/22] refactor: cleanup --- app/src/split/bluetooth/central.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index cae4efc9..242dc157 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -224,10 +224,10 @@ static uint8_t split_central_battery_level_notify_func(struct bt_conn *conn, LOG_DBG("[BATTERY LEVEL NOTIFICATION] data %p length %u", data, length); uint8_t battery_level = ((uint8_t *)data)[0]; + LOG_DBG("Battery level: %u", battery_level); struct zmk_peripheral_battery_state_changed ev = {.state_of_charge = battery_level}; k_msgq_put(&peripheral_batt_lvl_msgq, &ev, K_NO_WAIT); k_work_submit(&peripheral_batt_lvl_work); - LOG_DBG("Battery level: %u", battery_level); return BT_GATT_ITER_CONTINUE; } From a8d7e2c4609acc6f46c72623eb5dbb0ea683bc7c Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Tue, 5 Apr 2022 22:08:17 +0000 Subject: [PATCH 08/22] refactor: cleanup --- app/src/battery_split.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/app/src/battery_split.c b/app/src/battery_split.c index fdb94853..0af51f46 100644 --- a/app/src/battery_split.c +++ b/app/src/battery_split.c @@ -32,27 +32,20 @@ static void blvl_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value static ssize_t read_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { - uint8_t lvl8 = last_state_of_charge; - return bt_gatt_attr_read(conn, attr, buf, len, offset, &lvl8, sizeof(lvl8)); -} - -static ssize_t read_peripheral_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) { - uint8_t lvl8 = last_state_of_peripheral_charge; - return bt_gatt_attr_read(conn, attr, buf, len, offset, &lvl8, sizeof(lvl8)); + const char *lvl8 = attr->user_data; + return bt_gatt_attr_read(conn, attr, buf, len, offset, lvl8, sizeof(uint8_t)); } 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, &last_state_of_charge), - BT_GATT_CUD("Central", BT_GATT_PERM_READ), BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), + BT_GATT_CUD("Central", BT_GATT_PERM_READ), BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, - BT_GATT_PERM_READ, read_peripheral_blvl, NULL, - &last_state_of_peripheral_charge), - BT_GATT_CUD("Peripheral", BT_GATT_PERM_READ), - BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE)); + BT_GATT_PERM_READ, read_blvl, NULL, &last_state_of_peripheral_charge), + BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), + BT_GATT_CUD("Peripheral", BT_GATT_PERM_READ)); const struct device *battery; From 73de60df5eeb9890d8113ee3cb03d92136589707 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Tue, 5 Apr 2022 22:09:08 +0000 Subject: [PATCH 09/22] refactor: disable BT_BAS for central --- app/Kconfig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Kconfig b/app/Kconfig index 5551ed31..e4208de6 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -99,7 +99,6 @@ menuconfig ZMK_BLE select BT_SMP_APP_PAIRING_ACCEPT select BT_PERIPHERAL select BT_DIS - select BT_BAS select BT_SETTINGS select SETTINGS @@ -214,6 +213,9 @@ config BT_MAX_CONN config BT_GAP_AUTO_UPDATE_CONN_PARAMS default n +config BT_BAS + default y + #!ZMK_SPLIT_BLE_ROLE_CENTRAL endif @@ -244,6 +246,9 @@ config BT_MAX_CONN config BT_MAX_PAIRED default 5 +config BT_BAS + default y + #!ZMK_SPLIT_BLE endif From 23bef8a85d863ef391e0b2c1a17fa422deffc959 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Wed, 6 Apr 2022 19:49:49 +0000 Subject: [PATCH 10/22] chore: clang-format --- app/src/split/bluetooth/central.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 242dc157..9e92db20 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -232,8 +232,8 @@ static uint8_t split_central_battery_level_notify_func(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } static uint8_t split_central_battery_level_read_func(struct bt_conn *conn, uint8_t err, - struct bt_gatt_read_params *params, - const void *data, uint16_t length) { + struct bt_gatt_read_params *params, + const void *data, uint16_t length) { if (err > 0) { LOG_ERR("Error during reading peripheral battery level: %u", err); return BT_GATT_ITER_STOP; From e24ab4e0e3e1702b61a4ca4028d91c53d62c8f5d Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Wed, 6 Apr 2022 21:23:38 +0000 Subject: [PATCH 11/22] fix: peripheral battery level notification --- app/src/battery_split.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/battery_split.c b/app/src/battery_split.c index 0af51f46..ac37d7d2 100644 --- a/app/src/battery_split.c +++ b/app/src/battery_split.c @@ -57,7 +57,9 @@ int peripheral_batt_lvl_listener(const zmk_event_t *eh) { }; LOG_DBG("Peripheral battery level event: %u", ev->state_of_charge); last_state_of_peripheral_charge = ev->state_of_charge; - int rc = bt_gatt_notify(NULL, &bas.attrs[3], &last_state_of_peripheral_charge, + + // TODO: super fragile because of hardcoded attribute index + int rc = bt_gatt_notify(NULL, &bas.attrs[5], &last_state_of_peripheral_charge, sizeof(last_state_of_peripheral_charge)); return rc; }; From c60fbe7e21800c556cd71944b62b33bdab733fd7 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Wed, 27 Apr 2022 20:51:21 +0000 Subject: [PATCH 12/22] chore: clang-format --- app/src/battery_split.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/battery_split.c b/app/src/battery_split.c index ac37d7d2..4f1d9050 100644 --- a/app/src/battery_split.c +++ b/app/src/battery_split.c @@ -57,7 +57,7 @@ int peripheral_batt_lvl_listener(const zmk_event_t *eh) { }; LOG_DBG("Peripheral battery level event: %u", ev->state_of_charge); last_state_of_peripheral_charge = ev->state_of_charge; - + // TODO: super fragile because of hardcoded attribute index int rc = bt_gatt_notify(NULL, &bas.attrs[5], &last_state_of_peripheral_charge, sizeof(last_state_of_peripheral_charge)); From 44213b7c75e36544472611587d6e7a7d8410be4c Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Fri, 24 Jun 2022 15:26:29 +0000 Subject: [PATCH 13/22] refactor: use CONFIG_ZMK_SPLIT_ROLE_CENTRAL --- app/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 9d839745..905a312f 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -70,7 +70,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL) target_sources(app PRIVATE src/behaviors/behavior_bt.c) target_sources(app PRIVATE src/ble.c) target_sources(app PRIVATE src/hog.c) - if (CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) + if (CONFIG_ZMK_SPLIT_ROLE_CENTRAL) target_sources(app PRIVATE src/battery_split.c) else() target_sources(app PRIVATE src/battery.c) From e86d5f04efbc87325aaa68d278b2db75a7a369f5 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Fri, 24 Jun 2022 15:26:58 +0000 Subject: [PATCH 14/22] refactor: use new config options --- app/Kconfig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Kconfig b/app/Kconfig index 4bcd88b0..b6cbceaf 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -102,7 +102,6 @@ menuconfig ZMK_BLE select BT_SMP_APP_PAIRING_ACCEPT select BT_PERIPHERAL select BT_DIS - select BT_BAS select BT_SETTINGS select SETTINGS @@ -157,6 +156,13 @@ config BT_PERIPHERAL_PREF_LATENCY config BT_PERIPHERAL_PREF_TIMEOUT default 400 +if ((!ZMK_SPLIT_ROLE_CENTRAL) || (!ZMK_SPLIT)) + +config BT_BAS + default y + +endif + #ZMK_BLE endif From 0f64b003a17155b07b6b6341723aff2f58503b85 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Fri, 24 Jun 2022 15:31:04 +0000 Subject: [PATCH 15/22] refactor: remove empty line --- app/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 905a312f..563953ea 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -66,7 +66,6 @@ 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/behaviors/behavior_bt.c) target_sources(app PRIVATE src/ble.c) target_sources(app PRIVATE src/hog.c) From 0d4969162674bfaaed8433fc67df89196cac4565 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Fri, 24 Jun 2022 20:55:50 +0000 Subject: [PATCH 16/22] refactor: fix conditional building --- app/CMakeLists.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 563953ea..227d6acd 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -69,11 +69,14 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL) target_sources(app PRIVATE src/behaviors/behavior_bt.c) target_sources(app PRIVATE src/ble.c) target_sources(app PRIVATE src/hog.c) - if (CONFIG_ZMK_SPLIT_ROLE_CENTRAL) - target_sources(app PRIVATE src/battery_split.c) - else() - target_sources(app PRIVATE src/battery.c) - endif() + endif() +endif() + +if (CONFIG_ZMK_BLE) + if (CONFIG_ZMK_SPLIT_ROLE_CENTRAL) + target_sources(app PRIVATE src/battery_split.c) + else() + target_sources(app PRIVATE src/battery.c) endif() endif() From 9ef105522b56c3039be44aa1ad3c109443a0cb19 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Fri, 24 Jun 2022 20:56:29 +0000 Subject: [PATCH 17/22] refactor: allow BAS only on BLE peripherals --- app/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Kconfig b/app/Kconfig index b6cbceaf..f2774230 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -156,7 +156,7 @@ config BT_PERIPHERAL_PREF_LATENCY config BT_PERIPHERAL_PREF_TIMEOUT default 400 -if ((!ZMK_SPLIT_ROLE_CENTRAL) || (!ZMK_SPLIT)) +if (CONFIG_ZMK_BLE && !CONFIG_ZMK_SPLIT_ROLE_CENTRAL) config BT_BAS default y From 0884db66e000c32cd1866f1f81ef571afdaa1054 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Sun, 3 Jul 2022 13:55:49 +0000 Subject: [PATCH 18/22] refactor: introduce special battery level value --- app/src/battery_split.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/battery_split.c b/app/src/battery_split.c index 4f1d9050..acae7f96 100644 --- a/app/src/battery_split.c +++ b/app/src/battery_split.c @@ -19,8 +19,11 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include -static uint8_t last_state_of_charge = 0; -static uint8_t last_state_of_peripheral_charge = 0; +const uint8_t NULL_BATTERY_LEVEL = 0xFF; + +// Initialize the charge level to a special value indicating no sampling has been made yet. +static uint8_t last_state_of_charge = NULL_BATTERY_LEVEL; +static uint8_t last_state_of_peripheral_charge = NULL_BATTERY_LEVEL; static void blvl_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { ARG_UNUSED(attr); From 53816539f11f413501051520c7288cca7cad214e Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Fri, 15 Jul 2022 20:01:52 +0000 Subject: [PATCH 19/22] refactor: use 'select BT_BAS if ...' syntax --- app/Kconfig | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index bc37e367..843c7db7 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -101,6 +101,7 @@ menuconfig ZMK_BLE select BT_SMP_SC_PAIR_ONLY select BT_SMP_APP_PAIRING_ACCEPT select BT_PERIPHERAL + select BT_BAS if !ZMK_SPLIT_ROLE_CENTRAL select BT_DIS select BT_SETTINGS select SETTINGS @@ -156,13 +157,6 @@ config BT_PERIPHERAL_PREF_LATENCY config BT_PERIPHERAL_PREF_TIMEOUT default 400 -if (CONFIG_ZMK_BLE && !CONFIG_ZMK_SPLIT_ROLE_CENTRAL) - -config BT_BAS - default y - -endif - #ZMK_BLE endif From 500a5bbfd95bf668785f294e80d633c81836190b Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Fri, 15 Jul 2022 21:25:47 +0000 Subject: [PATCH 20/22] refactor: change order --- app/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Kconfig b/app/Kconfig index 843c7db7..fc3ae11f 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -101,8 +101,8 @@ menuconfig ZMK_BLE select BT_SMP_SC_PAIR_ONLY select BT_SMP_APP_PAIRING_ACCEPT select BT_PERIPHERAL - select BT_BAS if !ZMK_SPLIT_ROLE_CENTRAL select BT_DIS + select BT_BAS if !ZMK_SPLIT_ROLE_CENTRAL select BT_SETTINGS select SETTINGS From 3d5700ec0255c99a1ff9fcf32d3aa97367aad1b8 Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Wed, 20 Jul 2022 19:51:26 +0000 Subject: [PATCH 21/22] fix: display battery level from battery state change event --- app/src/display/widgets/battery_status.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/display/widgets/battery_status.c b/app/src/display/widgets/battery_status.c index 3dfcdb47..ddfc3206 100644 --- a/app/src/display/widgets/battery_status.c +++ b/app/src/display/widgets/battery_status.c @@ -57,8 +57,10 @@ void battery_status_update_cb(struct battery_status_state state) { } static struct battery_status_state battery_status_get_state(const zmk_event_t *eh) { + const struct zmk_battery_state_changed *ev = + as_zmk_battery_state_changed(eh); return (struct battery_status_state) { - .level = bt_bas_get_battery_level(), + .level = ev->state_of_charge, #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) .usb_present = zmk_usb_is_powered(), #endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */ From f09976844f0417e1d1b95bfed39da88d3fdaea9b Mon Sep 17 00:00:00 2001 From: Gabor Hornyak Date: Thu, 21 Jul 2022 20:35:43 +0000 Subject: [PATCH 22/22] chore: format file --- .vscode/c_cpp_properties.json | 17 +++++++++++++++++ app/src/display/widgets/battery_status.c | 3 +-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..e41cd900 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu17", + "cppStandard": "c++17", + "intelliSenseMode": "linux-gcc-arm", + "compileCommands": "${workspaceFolder}/app/build/compile_commands.json" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/app/src/display/widgets/battery_status.c b/app/src/display/widgets/battery_status.c index ddfc3206..8b8ab479 100644 --- a/app/src/display/widgets/battery_status.c +++ b/app/src/display/widgets/battery_status.c @@ -57,8 +57,7 @@ void battery_status_update_cb(struct battery_status_state state) { } static struct battery_status_state battery_status_get_state(const zmk_event_t *eh) { - const struct zmk_battery_state_changed *ev = - as_zmk_battery_state_changed(eh); + const struct zmk_battery_state_changed *ev = as_zmk_battery_state_changed(eh); return (struct battery_status_state) { .level = ev->state_of_charge, #if IS_ENABLED(CONFIG_USB_DEVICE_STACK)