feat(split): sync central & peripherals last activity timing #2459
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sync central last activity timings to all devices, by having the central emit how long it's inactive, and the peripheral(s) using it to adjust the local last activity time. Prior to this change, key presses on a peripheral keep the central awake, but not vice versa.
This is done by:
SYNC_ACTIVITY
GATT characteristic for central to sync its inactive time to the other peripheral(s).activity.c
broadcasting its inactivity time to its peripherals via 2 options:a.
ZMK_SPLIT_SYNC_LAST_ACTIVITY_TIMING_PERIODIC
- broadcasting at a regular configurable intervalb.
ZMK_SPLIT_SYNC_LAST_ACTIVITY_TIMING_ON_EVENT
- broadcasting when key press / sensors events are received, with a minimum configurable interval between each broadcastservice.c
receiving the inactivity time and sending it as an event to itsactivity.c
activity.c
determining its localactivity_last_uptime
value using the inactivity time as a relative difference.Additionally:
central.c
is updated to sync the timers upon a new BLE connection, so new devices don't need to wait for the full interval to get synced.Cons:
ZMK_ACTIVITY_SLEEP
), since BLE is turned off. However, the sync-ing can prevent peripheral(s) from going into deep sleep if the central is used.ZMK_IDLE_SLEEP_TIMEOUT
), the peripheral(s) may go into IDLE before receiving the next sync from central, which may not be desired. See Test steps - Periodic sync belowTest steps - Periodic sync
ZMK_SPLIT_SYNC_LAST_ACTIVITY_TIMING_PERIODIC
enabledTest steps - Event-based sync
ZMK_SPLIT_SYNC_LAST_ACTIVITY_TIMING_ON_EVENT
enabled. (_ON_EVENT
, not_PERIODIC
)Local test
I added log lines to check the output, that the values are sent and received correctly on both ends. However, if the sync interval is set to a low value (30 seconds), the log lines would end up spamming the console, so I opt'ed to remove them. Let me know if logs can be introduced more nicely, or if there's a better way to check that the code works for the context of reviewing this pull request!
Raised as an issue in #2408