adafruit / Adafruit_Python_GPIO

DEPRECATED! Please use Adafruit Blinka instead (was: Library to provide a cross-platform GPIO interface on the Raspberry Pi and Beaglebone Black using the RPi.GPIO and Adafruit_BBIO libraries.)
MIT License
402 stars 312 forks source link

Change platform detect to use /proc/cpuinfo to detect board type and add new board to detect. #92

Closed Groguard closed 5 years ago

Groguard commented 5 years ago

This PR changes how boards are detected by using "/proc/cpuinfo" instead of reading the platform. This change checks for the processor type and determines the board based on that. This should allow for more boards to be added and detected for use with adafruit-blinka.

Changes:

limitations:

Test code:

import os

# Platform identification constants.
UNKNOWN          = 0
RASPBERRY_PI     = 1
BEAGLEBONE_BLACK = 2
MINNOWBOARD      = 3
GIANT_BOARD      = 4

command = 'cat /proc/cpuinfo'
plat = os.popen(command).read().strip()

def return_platform():
    if plat.lower().find('generic am33xx') > -1:
        return BEAGLEBONE_BLACK
    elif plat.lower().find('atmel sama5') > -1:
        return GIANT_BOARD

print(return_platform())
ladyada commented 5 years ago

@Groguard ooh thanks - we're actually about to pull this out and into a separate repo just for platform detection. @brennen is doing that now, and may ask you to add your code there!