Skip to content

Initialize PN532 IFD-NFC at startup when configured and detected on I2C#360

Open
Copilot wants to merge 7 commits into
devfrom
copilot/featureadd-ssl-support
Open

Initialize PN532 IFD-NFC at startup when configured and detected on I2C#360
Copilot wants to merge 7 commits into
devfrom
copilot/featureadd-ssl-support

Conversation

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown

Description

PN532 smartcard access could remain unavailable after boot when smartcard_interfaces already contained pn532, because activation side-effects were only triggered on value transitions. This change adds startup-time PN532 activation, but only when the NFC interface is configured and a PN532 is detected on I2C.

  • Startup activation path

    • Added _maybe_activate_pn532_on_startup(settings) and invoked it during Settings.get_instance() initialization.
    • Activation now happens without requiring a manual NFC test scan.
  • I2C-gated hardware detection

    • Added _is_i2c_device_detected() to probe /dev/i2c-1 and /dev/i2c-0 with i2cdetect for address 0x24 (PN532 default).
    • ifdnfc-activate yes is executed only when pn532 is configured and the device probe succeeds.
  • Fail-safe behavior

    • No-op when ifdnfc-activate, i2cdetect, or I2C buses are unavailable.
    • Logs activation/probe outcomes; avoids hard failures in non-SeedSignerOS/dev environments.

Example of the new startup gate:

sc_interfaces = settings_obj._data.get(SettingsConstants.SETTING__SMARTCARD_INTERFACES, [])
if "pn532" in sc_interfaces and _is_i2c_device_detected("0x24"):
    subprocess.run(["ifdnfc-activate", "yes"], check=False)

Describe the change simply. Provide a reason for the change.

Include screenshots of any new or modified screens (or at least explain why they were omitted)

No UI changes; screenshots omitted.

This pull request is categorized as a:

  • New feature
  • Bug fix
  • Code refactor
  • Documentation
  • Other

Checklist

  • I’ve run pytest and made sure all unit tests pass before sumbitting the PR

If you modified or added functionality/workflow, did you add new unit tests?

  • No, I’m a fool
  • Yes
  • N/A

I have tested this PR on the following platforms/os:

Note: Keep your changes limited in scope; if you uncover other issues or improvements along the way, ideally submit those as a separate PR. The more complicated the PR the harder to review, test, and merge.

@3rdIteration 3rdIteration marked this pull request as ready for review June 1, 2026 19:45
Copilot AI review requested due to automatic review settings June 1, 2026 19:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ensures the PN532 IFD-NFC stack is activated during application startup when PN532 is already configured in settings, avoiding the prior “only activates on value transition” behavior. Activation is gated by a best-effort I2C probe so it only runs when a PN532 is actually present.

Changes:

  • Added an i2cdetect-based I2C probe helper (_is_i2c_device_detected) to detect a device at 0x24.
  • Added startup-time activation helper (_maybe_activate_pn532_on_startup) that runs ifdnfc-activate yes only when configured + detected.
  • Invoked the activation helper during Settings.get_instance() initialization.

Comment thread src/seedsigner/models/settings.py
Comment thread src/seedsigner/models/settings.py
Comment thread src/seedsigner/models/settings.py Outdated
Comment thread src/seedsigner/models/settings.py Outdated
Comment thread src/seedsigner/models/settings.py Outdated
Comment thread src/seedsigner/models/settings.py Outdated
3rdIteration and others added 6 commits June 8, 2026 10:45
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

3 participants