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(sleep): Option to enter deep sleep after ble connection severed #2669

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mdkul22
Copy link

@mdkul22 mdkul22 commented Nov 25, 2024

Introduce a new Kconfig flag to enable enter SLEEP mode on device if BT connection severed from main active profile, added with some logic changes to enable this modality. This addresses issue #2198

[00:01:34.235,137] <dbg> zmk: disconnected: Disconnected from <BT_ADDR> (public) (reason 0x13)
[00:01:34.235,168] <dbg> zmk: disconnected: Active profile disconnected
[00:01:34.235,351] <dbg> zmk: split_central_disconnected: Disconnected: <BT_ADDR> (public) (reason 19)
[00:01:34.235,382] <dbg> zmk: update_advertising: advertising from 0 to 2
[00:01:34.236,022] <dbg> zmk: zmk_usb_get_conn_state: state: 3
[00:01:34.236,022] <dbg> zmk: get_selected_transport: Only USB is ready.
[00:01:34.248,809] <inf> bas: BAS Notifications enabled
[00:01:34.250,091] <dbg> zmk: connected: Connected thread: 0x20005aa8
[00:01:34.250,305] <dbg> zmk: connected: Connected 0C:53:B7:7A:18:00 (public)
[00:01:34.250,335] <dbg> zmk: update_advertising: advertising from 0 to 2
[00:01:34.251,068] <dbg> zmk: split_central_connected: SKIPPING FOR ROLE 1
[00:01:34.434,783] <dbg> zmk: security_changed: Security changed: <BT_ADDR> (public) level 4
[00:01:35.092,773] <dbg> zmk: le_param_updated: <BT_ADDR> (public): interval 12 latency 0 timeout 72
[00:01:39.214,050] <dbg> zmk: vddh_sample_fetch: ADC raw 3023 ~ 4425 mV => 100%
[00:01:39.265,045] <dbg> zmk: le_param_updated:<BT_ADDR> (public): interval 12 latency 0 timeout 72

🔝 main device logs

[00:01:39.835,266] <dbg> zmk: zmk_physical_layouts_kscan_process_msgq: Row: 3, col: 0, position: 39, pressed: true
[00:01:39.835,266] <dbg> zmk: split_listener:
[00:01:39.889,129] <dbg> zmk: kscan_matrix_read: Sending event at 3,0 state off
[00:01:39.889,251] <dbg> zmk: zmk_physical_layouts_kscan_process_msgq: Row: 3, col: 0, position: 39, pressed: false
[00:01:39.889,282] <dbg> zmk: split_listener:
[00:01:59.285,888] <dbg> zmk: split_svc_pos_state_ccc: value 0
[00:01:59.286,041] <dbg> zmk: disconnected: Disconnected from <BT_ADDR> (random) (reason 0x08)
[00:01:59.286,102] <dbg> zmk: set_status_symbol: connected? false
[00:02:00.567,077] <dbg> zmk: set_status_symbol: connected? false

🔝 peripheral logs

Currently the feature testing done as such:

  1. Set to Kconfig flags in my config

    • CONFIG_ZMK_SLEEP_ON_BLE_DISCONNECT=y
    • CONFIG_ZMK_SLEEP_DISCONNECT_TIMER=10000
  2. Built using the following west commands:

    • west build -p -d build/right -b nice_nano_v2 -S zmk-usb-logging -- -DSHIELD=corne_right
    • west build -p -d build/left -b nice_nano_v2 -S zmk-usb-logging -- -DSHIELD=corne_left
  3. Connected to the central split and tested by disconnecting Bluetooth to the active device the split keyboard is connected to, logs attached above.

  4. Connected to the peripheral split and tested it by disconnecting Bluetooth to the active device which led to the main device entering sleep, and subsequently after losing connection to the active device, the peripheral device automatically entered sleep.

Haven't done testing on non-split keyboard as I do not have access to such systems.

PR check-list

  • Branch has a clean commit history
  • Additional tests are included, if changing behaviors/core code that is testable.
  • Proper Copyright + License headers added to applicable files (Generally, we stick to "The ZMK Contributors" for copyrights to help avoid churn when files get edited)
  • Pre-commit used to check formatting of files, commit messages, etc.

@mdkul22 mdkul22 requested a review from a team as a code owner November 25, 2024 02:36
@mdkul22 mdkul22 changed the title feat(sleep): Option to disable sleep while BT connection is active feat(sleep): Option to enter deep sleep after ble connection severed Nov 25, 2024
Introduce a new Kconfig flag to enable enter SLEEP mode on device if BT connection severed from main active profile
@caksoylar
Copy link
Contributor

Related: #2205

@caksoylar caksoylar added core Core functionality/behavior of ZMK bluetooth Bluetooth related items labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bluetooth Bluetooth related items core Core functionality/behavior of ZMK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants