zmkfirmware / zmk

ZMK Firmware Repository
https://zmk.dev/
MIT License
2.63k stars 2.69k forks source link

Synced sleep bewteen central/peripherals #2408

Open Genteure opened 1 month ago

Genteure commented 1 month ago

Would be nice to have an option to sync sleep timers. Currently key presses on a peripheral keeps the central awake but not the reverse. I imagine with a multi-peripheral setup (e.g. with a dongle) key presses on peripheral A would also not keep peripheral B awake. This leads to the peripheral side occasionally sleeping on it's own. Although wake-up and reconnect is pretty quick in my experience, there's still a few seconds of delay.

Nick-Munnich commented 1 month ago

Personally I'd say your suggested function should be how it behaves, I don't see the reason why you would want to have the option to not sync sleep timers.

angweekiat commented 1 week ago

Hi @Genteure , I took a stab at this, and shared my changes above, based on syncing the last activity timing, rather than sleep timers. One issue I realized is that in deep sleep mode, the BLE capability is turned off, so it's not possible to wake either device from either side (to my knowledge), but the changes do prevent the peripheral from going into deep sleep, if the central device is used, and the timing synced to the peripheral

angweekiat commented 1 week ago

Hmm @Genteure , I was reading through some other issues when a realisation occurred, the last activity timers are synced, but the state is not. If the central is powered by USB, it'll never go to sleep, but the last activity time is still synced, and can result in the peripheral going to idle mode, while the central is in active state.

Some users may be ok with this (saves battery on the peripheral), while some may prefer the alternative where even the states are synchronised. Maybe it would be better to explicitly sync the states rather than indirectly through the last activity timers.

Just wanted to check if this use case crossed your mind when raising the issue, and your thoughts on it?

Genteure commented 1 week ago

I don't really have a strong opinion but to me syncing time numbers feels better than completely synchronized sleep state.

I can think of four scenarios where the central is connected to USB but the peripherals are not:

  1. Using as a USB keyboard w/ wireless split.
  2. Dongle mode.
  3. Simply charging the battery.
  4. Wired split (when zmk fully supports it)

For scenario 4, users would probably not enable sleep to begin with. For the other three, the peripheral(s) should still able to sleep when all parts are not actively used, otherwise it defeats the whole purpose of having a sleep feature isn't it. If a user doesn't want to have their keyboard go to sleep they can just set CONFIG_ZMK_SLEEP=n.

Also a peripheral should still be able to sleep on it's own to save battery when it's not connected to the central.