Repository navigation
feat(switch2_pro): application lifecycle callbacks and control surface - #913
Merged
Merged
Conversation
Adds the integration surface an application needs to drive its own connection manager, LEDs/telemetry, and pairing-record store around the emulated controller. All additions are additive and opt-in; existing users are unaffected. - Config::callbacks (Callbacks): on_connected, on_disconnected(reason), on_paired, on_input_streaming(bool), mirroring the polling getters so an app can be notified instead of polling. on_input_streaming is edge-triggered off is_input_streaming(); all fire from the NimBLE host-task context (documented). - is_initialized(), is_advertising(), stop_advertising() (also stops the wake re-advertiser), disconnect() (terminate the link, keep the bond). - static erase_stored_bond() erases the persisted bond from NVS with no live instance; Config::start_fresh makes init() drop any stored bond and advertise for a fresh pairing instead of reconnecting. - bonded_console_address() returns the bonded console's address (or nullopt). - Pro2InputReport::set_battery_percent(pct, charging, external) quantises a 0..100 percentage to the report's 0..9 level. Builds the switch2_pro example on esp32s3. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
finger563
marked this pull request as ready for review
November 18, 2026 02:22
|
✅Static analysis result - no issues found! ✅ |
- is_advertising(): use auto for NimBLEDevice::getAdvertising() so it builds under CONFIG_BT_NIMBLE_EXT_ADV (where it returns NimBLEExtAdvertising*), not only the legacy-advertising config. - bonded_console_address(): return the stable identity (host_addr_, the 0x15 exchange address the component trusts for reconnect) instead of bond_peer_val_, which is the NimBLE connection address and may be a rotating private address (no SMP resolution here). host_addr_ is set during the handshake before paired_ flips, so this also removes the narrow FINALISE race the old getter had. - stop_advertising(): latch readvertise_suppressed_ so the disconnect callback does not auto re-advertise afterwards; a "disconnect() then stop_advertising()" go-dark sequence is now race-free regardless of when the disconnect callback runs. wake_console() clears the latch. - disconnect(): return false when the link was already gone (BLE_HS_ENOTCONN), matching the documented "true only if a connection was live". - erase_stored_bond(): document the NVS-initialised precondition; start_fresh now logs an erase failure instead of ignoring the return value. Builds the switch2_pro example on esp32s3. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
finger563
force-pushed
the
feat/switch2-pro-app-api
branch
from
November 18, 2026 15:01
219cba4 to
1304f8d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Adds the application-integration surface to
Switch2Pro, for a host that drives its own connection manager, LED/telemetry, or pairing-record store around the controller. All additions are additive and opt-in; existing users are unaffected.Config::callbacks):on_connected,on_disconnected(reason),on_paired,on_input_streaming(bool), mirroring the polling getters so an app can be notified instead of polling from its IO tick.on_input_streamingis edge-triggered offis_input_streaming(). All fire from the NimBLE host-task context (documented).is_initialized(),is_advertising(),stop_advertising()(also stops the wake re-advertiser), anddisconnect()(terminate the link, keep the bond).static erase_stored_bond()erases the persisted bond from NVS with no instance (for a host that forgets a console while the radio is up as something else), andConfig::start_freshmakesinit()drop any stored bond and advertise for a fresh pairing instead of reconnecting.bonded_console_address()returns the bonded console's address (or nullopt) so a host can name it in its own records.Pro2InputReport::set_battery_percent(pct, charging, external)quantises a 0..100 percentage to the report's 0..9 level, so hosts don't each pick their own mapping.Why
Today the class exposes only polling state and
init()brings the radio up and advertises with no public way to stop advertising, forget a bond without an instance, or learn the bonded address. These are the hooks an application needs to integrate the controller into a larger device without reaching into NimBLE.Test
Builds the
switch2_proexample on esp32s3.