File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/python
2-
2+ import re
33import smbus
44
55# ===========================================================================
@@ -11,14 +11,21 @@ class Adafruit_I2C(object):
1111 @staticmethod
1212 def getPiRevision ():
1313 "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
1715 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
2229 except :
2330 return 0
2431
You can’t perform that action at this time.
0 commit comments