File tree 1 file changed +15
-8
lines changed
1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/python
2
-
2
+ import re
3
3
import smbus
4
4
5
5
# ===========================================================================
@@ -11,14 +11,21 @@ class Adafruit_I2C(object):
11
11
@staticmethod
12
12
def getPiRevision ():
13
13
"Gets the version number of the Raspberry Pi board"
14
- # Courtesy quick2wire-python-api
15
- # https://github.com/quick2wire/quick2wire-python-api
16
- # Updated revision info from: http://elinux.org/RPi_HardwareHistory#Board_Revision_History
14
+ # Revision list available at: http://elinux.org/RPi_HardwareHistory#Board_Revision_History
17
15
try :
18
- with open ('/proc/cpuinfo' ,'r' ) as f :
19
- for line in f :
20
- if line .startswith ('Revision' ):
21
- return 1 if line .rstrip ()[- 1 ] in ['2' ,'3' ] else 2
16
+ with open ('/proc/cpuinfo' , 'r' ) as infile :
17
+ for line in infile :
18
+ # Match a line of the form "Revision : 0002" while ignoring extra
19
+ # info in front of the revsion (like 1000 when the Pi was over-volted).
20
+ match = re .match ('Revision\s+:\s+.*(\w{4})$' , line )
21
+ if match and match .group (1 ) in ['0000' , '0002' , '0003' ]:
22
+ # Return revision 1 if revision ends with 0000, 0002 or 0003.
23
+ return 1
24
+ elif match :
25
+ # Assume revision 2 if revision ends with any other 4 chars.
26
+ return 2
27
+ # Couldn't find the revision, assume revision 0 like older code for compatibility.
28
+ return 0
22
29
except :
23
30
return 0
24
31
You can’t perform that action at this time.
0 commit comments