1+ """Detect boards."""
12import adafruit_platformdetect .chip as ap_chip
2- import platform
3- import sys
4- import re
53
4+ # Allow for aligned constant definitions:
5+ # pylint: disable=bad-whitespace
66BEAGLEBONE = 'BEAGLEBONE'
77BEAGLEBONE_BLACK = 'BEAGLEBONE_BLACK'
88BEAGLEBONE_BLUE = 'BEAGLEBONE_BLUE'
2121
2222FEATHER_HUZZAH = "FEATHER_HUZZAH"
2323FEATHER_M0_EXPRESS = "FEATHER_M0_EXPRESS"
24+ GENERIC_LINUX_PC = "GENERIC_LINUX_PC"
2425PYBOARD = "PYBOARD"
2526NODEMCU = "NODEMCU"
2627ORANGE_PI_PC = "ORANGE_PI_PC"
3738RASPBERRY_PI_3B_PLUS = "RASPBERRY_PI_3B_PLUS"
3839RASPBERRY_PI_CM3 = "RASPBERRY_PI_CM3"
3940RASPBERRY_PI_3A_PLUS = "RASPBERRY_PI_3A_PLUS"
41+ # pylint: enable=bad-whitespace
4042
41- # TODO: Should this include RASPBERRY_PI_3A_PLUS or any other models?
4243ANY_RASPBERRY_PI_2_OR_3 = (
4344 RASPBERRY_PI_2B ,
4445 RASPBERRY_PI_3B ,
9697 BEAGLEBONE_AIR : (
9798 ('A0' , 'A335BNLTNAD0' ),
9899 ),
99- # TODO: Does this differ meaningfully from the PocketBeagle?
100100 BEAGLEBONE_POCKETBONE : (
101101 ('0' , 'A335BNLTBP00' ),
102102 ),
130130}
131131
132132class Board :
133- """
134- Attempt to detect specific boards.
135- """
133+ """Attempt to detect specific boards."""
136134 def __init__ (self , detector ):
137135 self .detector = detector
138136
137+ # pylint: disable=invalid-name
139138 @property
140139 def id (self ):
141140 """Return a unique id for the detected board, if any."""
142141
143142 chip_id = self .detector .chip .id
143+ board_id = None
144144
145145 if chip_id == ap_chip .BCM2XXX :
146- return self ._pi_id ()
146+ board_id = self ._pi_id ()
147147 elif chip_id == ap_chip .AM33XX :
148- return self ._beaglebone_id ()
148+ board_id = self ._beaglebone_id ()
149+ elif chip_id == ap_chip .GENERIC_X86 :
150+ board_id = GENERIC_LINUX_PC
149151 elif chip_id == ap_chip .SUN8I :
150- return self ._armbian_id ()
152+ board_id = self ._armbian_id ()
151153 elif chip_id == ap_chip .ESP8266 :
152- return FEATHER_HUZZAH
154+ board_id = FEATHER_HUZZAH
153155 elif chip_id == ap_chip .SAMD21 :
154- return FEATHER_M0_EXPRESS
156+ board_id = FEATHER_M0_EXPRESS
155157 elif chip_id == ap_chip .STM32 :
156- return PYBOARD
158+ board_id = PYBOARD
157159
158- return None
160+ return board_id
161+ # pylint: enable=invalid-name
159162
160163 def _pi_id (self ):
161164 """Try to detect id of a Raspberry Pi."""
@@ -178,6 +181,7 @@ def _pi_rev_code(self):
178181 return None
179182 return self .detector .get_cpuinfo_field ('Revision' )
180183
184+ # pylint: disable=no-self-use
181185 def _beaglebone_id (self ):
182186 """Try to detect id of a Beaglebone."""
183187 try :
@@ -190,14 +194,14 @@ def _beaglebone_id(self):
190194 return None
191195
192196 id_string = eeprom_bytes [4 :].decode ("ascii" )
193- for model , ids in _BEAGLEBONE_BOARD_IDS .items ():
194- for id in ids :
195- if id_string == id [1 ]:
197+ for model , bb_ids in _BEAGLEBONE_BOARD_IDS .items ():
198+ for bb_id in bb_ids :
199+ if id_string == bb_id [1 ]:
196200 return model
197201
198202 return None
203+ # pylint: enable=no-self-use
199204
200- @property
201205 def _armbian_id (self ):
202206 """Check whether the current board is an OrangePi PC."""
203207 board_value = self .detector .get_armbian_release_field ('BOARD' )
@@ -212,6 +216,7 @@ def any_raspberry_pi(self):
212216
213217 @property
214218 def any_raspberry_pi_2_or_3 (self ):
219+ """Check whether the current board is any Raspberry Pi 2 or 3."""
215220 return self .id in ANY_RASPBERRY_PI_2_OR_3
216221
217222 def __getattr__ (self , attr ):
0 commit comments