Skip to content

Commit d943f95

Browse files
committed
re-add stuff after more merge conflict fixes
1 parent 82487c0 commit d943f95

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed

adafruit_platformdetect/board.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Detect boards."""
22
import os
3+
import re
34
import adafruit_platformdetect.chip as ap_chip
45

56
# Allow for aligned constant definitions:
@@ -367,6 +368,30 @@ def _pi_id(self):
367368
for model, codes in _PI_REV_CODES.items():
368369
if pi_rev_code in codes:
369370
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+
370395
return None
371396

372397
def _pi_rev_code(self):

adafruit_platformdetect/chip.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,34 @@ def _linux_id(self): # pylint: disable=too-many-branches
115115
elif "MIPS 24KEc" in cpu_model:
116116
linux_id = MIPS24KEC
117117

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
132146

133147
return linux_id
134148

0 commit comments

Comments
 (0)