detect-rpi icon indicating copy to clipboard operation
detect-rpi copied to clipboard

Update detection method and add helper functions

Open oxmc opened this issue 6 months ago • 0 comments

Updated Raspberry Pi Detection & Added Helper Functions

This PR improves the Raspberry Pi detection reliability and adds useful helper functions for getting detailed system information.

Key Changes

  1. Enhanced Detection Method:

    • Improved hardware detection by checking both /proc/cpuinfo fields
    • Added support for newer Pi models (including Pi 5 and Zero 2 W)
    • Added fallback checks when Hardware field is missing (Bookworm 64-bit)
    • Expanded list of known Pi hardware identifiers
  2. New Helper Functions:

    • Added model() - Returns the full Pi model string
    • Added revision() - Returns the board revision code
    • Added info() - Returns structured detection results
    {
      isPi: boolean,
      model: string,
      hardware: string,
      revision: string
    }
    

Backward Compatibility

  • Fully maintains existing API
  • No breaking changes
  • Same simple isPi() interface still works as before

Testing

Verified on:

  • Raspberry Pi OS Bullseye (32-bit)
  • Raspberry Pi OS Bookworm (64-bit)
  • Pi models: 3B+, 4B, 5, Compute Model 4
  • Non-Pi systems (negative testing)

Example Usage

const isPi = require('detect-rpi');

// Basic detection
console.log(isPi()); // true/false

// Get detailed info
const piInfo = isPi.info();
if (piInfo.isPi) {
  console.log(`Running on ${piInfo.model}`);
  console.log(`Hardware: ${piInfo.hardware}`);
  console.log(`Revision: ${piInfo.revision}`);
}

oxmc avatar Jul 25 '25 01:07 oxmc