Skip to content

Add MainBoard::pollButton() hook + correct SenseCAP Solar button naming#2622

Open
AtlavoxDev wants to merge 2 commits into
meshcore-dev:devfrom
AtlavoxDev:feature/mainboard-pollbutton-hook
Open

Add MainBoard::pollButton() hook + correct SenseCAP Solar button naming#2622
AtlavoxDev wants to merge 2 commits into
meshcore-dev:devfrom
AtlavoxDev:feature/mainboard-pollbutton-hook

Conversation

@AtlavoxDev
Copy link
Copy Markdown

Summary

Two related changes in two commits:

1. MainBoard::pollButton() framework hook — adds a no-op virtual hook mirroring the existing onBootComplete() pattern (#2621). Every example's loop() calls board.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 from simple_repeater/main.cpp and moves the equivalent hold-1.5s-to-power-off logic into SenseCapSolarBoard::pollButton() as an override. Behavior unchanged.

2. SenseCAP Solar: correct button naming — The firmware aliased PIN_USER_BTN to 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:

  • ThinkNode M6: overrides pollButton() for a 2 s hold-to-power-off sequence with red-flash UX
  • SenseCAP Solar: adds boot LED sequence and adds hold-feedback flashes to the existing pollButton() override

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.
@AtlavoxDev
Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant