Skip to content

Add button_e_pressed and include button E in any_button_pressed - #100

Closed
tomahawkeer wants to merge 1 commit into
adafruit:mainfrom
tomahawkeer:fix/button-e-pressed
Closed

tomahawkeer wants to merge 1 commit into
adafruit:mainfrom
tomahawkeer:fix/button-e-pressed

Conversation

@tomahawkeer

Copy link
Copy Markdown

Fixes #98

Peripherals.buttons gets a fifth entry for BOOT0 (button E) when the board defines it, but there was no button_e_pressed property, and any_button_pressed only checked buttons[0:4], so presses of button E were ignored.

Changes

  • Add button_e_pressed. It returns False when the board has no BOOT0, so existing four-button setups never raise.
  • any_button_pressed now checks every entry in self.buttons (any(not button.value for button in self.buttons)).

Testing

  • Ran Peripherals against stubbed board/digitalio/analogio/neopixel modules, both with and without board.BOOT0, pressing each button in turn: all button_*_pressed and any_button_pressed results are correct. On the unpatched code, the same script raises AttributeError: 'Peripherals' object has no attribute 'button_e_pressed'.
  • ruff check and ruff format --check pass.
  • Not tested on physical MagTag hardware.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FiGQujBCL8qnuH6bAv3Yiz

Peripherals.buttons gains a fifth entry for BOOT0 (button E) when the board
defines it, but there was no button_e_pressed property and any_button_pressed
only checked buttons[0:4], so presses of button E were ignored.

- Add button_e_pressed (returns False if the board has no BOOT0)
- any_button_pressed now checks every entry in self.buttons

Fixes adafruit#98

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FiGQujBCL8qnuH6bAv3Yiz
@tomahawkeer

Copy link
Copy Markdown
Author

Closing this as a duplicate of #99, which was opened first and is already under review. Sorry for the noise.

One thing that may be worth carrying over to #99: board.BOOT0 is only appended to self.buttons when the board defines it, so on a board without it self.buttons[4] raises IndexError. This PR guarded that case (if len(self.buttons) < 5: return False). That guard would apply equally to the button_boot_pressed name suggested there.

@tomahawkeer tomahawkeer closed this Nov 3, 2026
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.

magtag.peripherals.buttons list has a fifth element for button e (BOOT0), but not button_e_pressed; ALSO button e missing from any_button_pressed.

1 participant