Skip to content

Add device path ignore functionality to DetectAll#6

Merged
wizzomafizzo merged 1 commit intomainfrom
feature/ignore-device-paths
Aug 14, 2025
Merged

Add device path ignore functionality to DetectAll#6
wizzomafizzo merged 1 commit intomainfrom
feature/ignore-device-paths

Conversation

@wizzomafizzo
Copy link
Member

Summary

Adds the ability to specify device paths that should be explicitly ignored during PN532 detection, preventing aggressive probing of sensitive devices.

Changes

  • ✅ Add IgnorePaths field to detection.Options struct
  • ✅ Implement IsPathIgnored() function with case-insensitive path matching
  • ✅ Update UART detector to respect ignore list
  • ✅ Update I2C detector to respect ignore list
  • ✅ Update SPI detector to respect ignore list
  • ✅ Add comprehensive tests covering edge cases
  • ✅ Support Unix paths (/dev/ttyUSB0), Windows paths (COM2), and transport-specific formats

Usage Example

opts := detection.DefaultOptions()
opts.IgnorePaths = []string{
    "/dev/ttyUSB0",    // Ignore specific serial port
    "COM2",            // Ignore Windows COM port
    "/dev/i2c-1:0x24", // Ignore I2C device
}

devices, err := detection.DetectAll(&opts)

Key Features

  • Early filtering: Paths checked before any communication attempts
  • Cross-transport: Works with UART, I2C, and SPI detection
  • Case-insensitive: Handles Windows COM port variations
  • Path normalization: Resolves relative path components
  • Zero overhead: No performance impact for non-ignored devices

Test Coverage

  • Empty ignore lists and device paths
  • Exact path matching (Unix and Windows)
  • Case-insensitive matching
  • Multiple path scenarios
  • Transport-specific path formats
  • Path normalization with relative components
  • Edge cases (empty strings, mixed lists)

Fixes the issue where DetectAll could be too aggressive even with existing safety levels.

- Add IgnorePaths field to detection.Options struct
- Implement IsPathIgnored function with case-insensitive path matching
- Update all transport detectors (UART, I2C, SPI) to respect ignore list
- Add comprehensive tests for path matching including edge cases
- Support Unix paths (/dev/ttyUSB0), Windows paths (COM2), and transport-specific formats
@wizzomafizzo wizzomafizzo merged commit 583c8d6 into main Aug 14, 2025
8 checks passed
@wizzomafizzo wizzomafizzo deleted the feature/ignore-device-paths branch August 14, 2025 11:25
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