feat(ble): Add the ability to enable and disable advertising
Currently advertising cannot be disabled, In some circumstances it may be desirable to disable advertising to the host e.g. seeking consistency between an endpoint switch and percieved board behaviour.
This adds 3 new options to &bt, ADV_ON, ADV_OFF and ADV_TOG as well as the metadata and documentation for the behaviour. ble.c has been updated with a static flag that gets checked in update_advertising() and doesn't permit any adveritising state other than ZMK_ADV_NONE unless it's set. it's defaulted to true so standard board behavior shouldn't change.
The ability to get the current adverising state has also been added, it could have utility in custom display widgets.
Tested on a development board, I've noticed some hosts cache the advertising info so it still shows up as a connectible device if the switch is used whilst the bluetooth devices menu is open, but it still cannot be connected to. Using an app like nRF connect or a different host it can be seen that the device properly stops advertising
Regarding docs I think there might end up being some confusion when people see "This turns on advertising", use the behavior expecting to be able to connect a new device yet nothing happens because they haven't selected an unused profile.
I see your point, it would still advertise if it's in an occupied profile but wouldn't pair and work properly. Perhaps it would be better worded as "Permits advertising (note that other conditions must be met for the device to be visible)"?
That still sounds like it's a bit unclear to some. What would you consider to be the difference between what you've defined as BT_ADV_OFF and a hypothetical BT_OFF command?
Functionally there's not really any difference I suppose
I think renaming and rephrasing it appropriately would be both clearer and make it usable by non-tech people, then. Sometimes a user might want to just turn off BT after all.
Hmm, I'm not sure about describing it as turning off Bluetooth when it doesn't do that. My concern is users may wonder if it affects split connections if it's described as shutting off Bluetooth
Rebased and ready for review
An improvement over this that I would personally love to see would be to persist the setting across reboots, similar to how bt profiles or output switching works.
Cherry-picked on top of #3060, testing on Electronic Materials Office Ltd. Altar I's output selection SP3T switch. Can confirm that ADV_ON and ADV_OFF work exactly as expected. Thanks for working on this!