Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ble): Allow disabling BLE BAS reporting #1973

Merged
merged 10 commits into from
Nov 15, 2023
2 changes: 1 addition & 1 deletion app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ config ZMK_BATTERY_REPORTING
bool "Battery level detection/reporting"
default n
select SENSOR
select BT_BAS if ZMK_BLE
imply BT_BAS if ZMK_BLE

config ZMK_IDLE_TIMEOUT
int "Milliseconds of inactivity before entering idle state (OLED shutoff, etc)"
Expand Down
4 changes: 2 additions & 2 deletions app/src/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static int zmk_battery_update(const struct device *battery) {

if (last_state_of_charge != state_of_charge.val1) {
last_state_of_charge = state_of_charge.val1;

#if IS_ENABLED(CONFIG_BT_BAS)
LOG_DBG("Setting BAS GATT battery level to %d.", last_state_of_charge);

rc = bt_bas_set_battery_level(last_state_of_charge);
Expand All @@ -60,7 +60,7 @@ static int zmk_battery_update(const struct device *battery) {
LOG_WRN("Failed to set BAS GATT battery level (err %d)", rc);
return rc;
}

#endif
rc = ZMK_EVENT_RAISE(new_zmk_battery_state_changed(
(struct zmk_battery_state_changed){.state_of_charge = last_state_of_charge}));
}
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/config/battery.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ While `CONFIG_ZMK_BATTERY_REPORTING` is disabled by default it is implied by `CO

:::

:::note BLE reporting on MacOS

On macOS the BLE battery reporting packets can cause the computer to wakeup from sleep. To prevent this, the battery _reporting_ service can be disabled by setting `CONFIG_BT_BAS=n`. This setting is independent of battery _monitoring_, for instance the battery level can still be indicated on a display.

:::

### Devicetree

Applies to: [`/chosen` node](https://docs.zephyrproject.org/latest/guides/dts/intro.html#aliases-and-chosen-nodes)
Expand Down
1 change: 1 addition & 0 deletions docs/docs/config/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ for more information on configuring Bluetooth.
| Config | Type | Description | Default |
| ------------------------------------------- | ---- | --------------------------------------------------------------------- | ------- |
| `CONFIG_BT` | bool | Enable Bluetooth support | |
| `CONFIG_BT_BAS` | bool | Enable the Bluetooth BAS (battery reporting service) | y |
| `CONFIG_BT_MAX_CONN` | int | Maximum number of simultaneous Bluetooth connections | 5 |
| `CONFIG_BT_MAX_PAIRED` | int | Maximum number of paired Bluetooth devices | 5 |
| `CONFIG_ZMK_BLE` | bool | Enable ZMK as a Bluetooth keyboard | |
Expand Down
Loading