File tree Expand file tree Collapse file tree 2 files changed +53
-14
lines changed Expand file tree Collapse file tree 2 files changed +53
-14
lines changed Original file line number Diff line number Diff line change 1
1
"""Detect boards."""
2
2
import os
3
+ import re
3
4
import adafruit_platformdetect .chip as ap_chip
4
5
5
6
# Allow for aligned constant definitions:
@@ -367,6 +368,30 @@ def _pi_id(self):
367
368
for model , codes in _PI_REV_CODES .items ():
368
369
if pi_rev_code in codes :
369
370
return model
371
+
372
+ # We may be on a non-Raspbian OS, so try to lazily determine
373
+ # the version based on `get_device_model`
374
+ else :
375
+ pi_model = self .detector .get_device_model ()
376
+ if pi_model :
377
+ pi_model = pi_model .upper ().replace (' ' , '_' )
378
+ if "PLUS" in pi_model :
379
+ re_model = re .search (r'(RASPBERRY_PI_\d).*([AB]_*)(PLUS)' ,
380
+ pi_model )
381
+ elif "CM" in pi_model : # untested for Compute Module
382
+ re_model = re .search (r'(RASPBERRY_PI_CM)(\d)' ,
383
+ pi_model )
384
+ else : # untested for non-plus models
385
+ re_model = re .search (r'(RASPBERRY_PI_\d).*([AB]_*)' ,
386
+ pi_model )
387
+
388
+ if re_model :
389
+ pi_model = "" .join (re_model .groups ())
390
+ available_models = _PI_REV_CODES .keys ()
391
+ for model in available_models :
392
+ if model == pi_model :
393
+ return model
394
+
370
395
return None
371
396
372
397
def _pi_rev_code (self ):
Original file line number Diff line number Diff line change @@ -115,20 +115,34 @@ def _linux_id(self): # pylint: disable=too-many-branches
115
115
elif "MIPS 24KEc" in cpu_model :
116
116
linux_id = MIPS24KEC
117
117
118
- elif hardware in ("BCM2708" , "BCM2709" , "BCM2835" ):
119
- linux_id = BCM2XXX
120
- elif "AM33XX" in hardware :
121
- linux_id = AM33XX
122
- elif "sun8i" in hardware :
123
- linux_id = SUN8I
124
- elif "ODROIDC" in hardware :
125
- linux_id = S805
126
- elif "ODROID-C2" in hardware :
127
- linux_id = S905
128
- elif "ODROID-N2" in hardware :
129
- linux_id = S922X
130
- elif "SAMA5" in hardware :
131
- linux_id = SAMA5
118
+ # we still haven't identified the hardware, so
119
+ # convert it to a list and let the remaining
120
+ # conditions attempt.
121
+ if not linux_id :
122
+ hardware = [
123
+ entry .replace ('\x00 ' , '' ) for entry in compatible .split (',' )
124
+ ]
125
+
126
+ if not linux_id :
127
+ if 'AM33XX' in hardware :
128
+ linux_id = AM33XX
129
+ elif 'sun8i' in hardware :
130
+ linux_id = SUN8I
131
+ elif 'ODROIDC' in hardware :
132
+ linux_id = S805
133
+ elif 'ODROID-C2' in hardware :
134
+ linux_id = S905
135
+ elif 'ODROID-N2' in hardware :
136
+ linux_id = S922X
137
+ elif 'SAMA5' in hardware :
138
+ linux_id = SAMA5
139
+ else :
140
+ if isinstance (hardware , str ):
141
+ if hardware in BCM_RANGE :
142
+ linux_id = BCM2XXX
143
+ elif isinstance (hardware , list ):
144
+ if set (hardware ) & BCM_RANGE :
145
+ linux_id = BCM2XXX
132
146
133
147
return linux_id
134
148
You can’t perform that action at this time.
0 commit comments