Add MainBoard::pollButton() hook + correct SenseCAP Solar button naming#2622
Open
AtlavoxDev wants to merge 2 commits into
Open
Add MainBoard::pollButton() hook + correct SenseCAP Solar button naming#2622AtlavoxDev wants to merge 2 commits into
AtlavoxDev wants to merge 2 commits into
Conversation
Adds `virtual void pollButton()` as a no-op extension point on `mesh::MainBoard`, following the same pattern as `onBootComplete()`. Every example's `loop()` now calls `board.pollButton()` unconditionally once per iteration. Boards with physical buttons override this hook to poll for user input (e.g., hold-to-power-off); boards without buttons inherit the no-op default. Removes the device-specific `#if defined(_SEEED_SENSECAP_SOLAR_H_)` blocks from `examples/simple_repeater/main.cpp` and moves the equivalent hold-1.5s-to-power-off logic into `SenseCapSolarBoard::pollButton()` as an override. Net behavior for SenseCAP Solar is unchanged; the only difference is where the code lives. Files: - src/MeshCore.h: add virtual pollButton() no-op - examples/simple_repeater/main.cpp: remove SenseCAP #ifdef blocks; add unconditional board.pollButton() - examples/companion_radio/main.cpp: add unconditional board.pollButton() - examples/simple_room_server/main.cpp: add unconditional board.pollButton() - examples/kiss_modem/main.cpp: add unconditional board.pollButton() - variants/sensecap_solar/SenseCapSolarBoard.h: add pollButton() override (moved from main.cpp)
The physical buttons on the SenseCAP Solar are silkscreened PWR / RST / USR (left to right). Previously the firmware aliased PIN_USER_BTN to PIN_BUTTON1 (pin 13), but pin 13 is wired to the PWR button — both the SYSTEMOFF wake source and the hold-to-power-off target. The name "PIN_USER_BTN" was semantically misleading: it pointed at the power button, while the actual labeled USR button (pin 20) was completely unused. Renames so code matches the device silkscreen, keeping the existing project-wide PIN_USER_BTN convention for the user-labeled button: - PIN_PWR_BTN -> pin 13 (PWR, leftmost) [new name] - PIN_USER_BTN -> pin 20 (USR, rightmost) [re-pointed] RST is hardwired to the nRF52 reset line and is not exposed as a GPIO, so only the two firmware-controllable buttons are defined. The previous PIN_BUTTON1 / PIN_BUTTON2 intermediate aliases are removed since no code in the SenseCAP build path references them. The pin numbers are now declared directly against the silkscreen names, matching the simpler pattern used by other variants like thinknode_m2, thinknode_m5, and muziworks_r1_neo. SenseCapSolarBoard now uses PIN_PWR_BTN in the pollButton() override, the powerOff() SENSE-LOW wake config, and the begin() pinMode setup. The dead `#elif defined(PIN_BUTTON1)` fallbacks are removed since PIN_PWR_BTN is always defined for this variant. The redundant `-D PIN_USER_BTN=PIN_BUTTON1` is removed from platformio.ini; variant.h is now the single source of truth for the button pin mapping. Behavior unchanged: pin 13 still wakes the device, still triggers power-off on 1.5 s hold, still gets pull-up configured for SYSTEMOFF. The USR button (pin 20) remains unused but is now correctly named for future use — matching the established PIN_USER_BTN convention used across other variants.
Author
|
Continuing to lay groundwork for improving LED and button functionality for devices. Added a hook that devices can use for buttons, and removed the device-specific code for the P1-Pro into its own codebase instead of the main.cpp. |
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.
Summary
Two related changes in two commits:
1.
MainBoard::pollButton()framework hook — adds a no-op virtual hook mirroring the existingonBootComplete()pattern (#2621). Every example'sloop()callsboard.pollButton()unconditionally. Boards with buttons override; boards without inherit the no-op default. Removes the existing one-off device-specific conditional#if defined(_SEEED_SENSECAP_SOLAR_H_)blocks fromsimple_repeater/main.cppand moves the equivalent hold-1.5s-to-power-off logic intoSenseCapSolarBoard::pollButton()as an override. Behavior unchanged.2. SenseCAP Solar: correct button naming — The firmware aliased
PIN_USER_BTNto pin 13, but pin 13 is the PWR button (SYSTEMOFF wake source + hold-to-power-off target). The actual USR button (pin 20) was completely unused. Renames so code matches silkscreen:PIN_PWR_BTN→ pin 13,PIN_USER_BTN→ pin 20. RST is hardware-only (not GPIO). Behavior unchanged.Rationale
This PR follows the same pattern as the recently-merged
onBootComplete()framework hook (#2621). It exists as a precondition for two in-flight device-specific PRs (ThinkNode M6 power-button/LED work, SenseCAP Solar boot LED/Button improvements) so that those PRs don't have to carry both the framework decision and the device implementation in a single review.Follow-up
Two device-specific PRs are queued to land after this one:
pollButton()for a 2 s hold-to-power-off sequence with red-flash UXpollButton()override