Code: Select all
#!/usr/bin/python3
def getRevision():
# Extract revision from cpuinfo file
revision = "ERROR"
try:
f = open('/proc/cpuinfo','r')
for line in f:
if line[0:8]=='Revision':
revision = line[11:15]
f.close()
except:
revision = "ERROR"
return revision
def revToModel():
rev = getRevision()
model = [
"0002", ["Model B Rev 1.0", "256MB"],
"0003", ["Model B Rev 1.0 (no fuses,D14)", "256MB"],
"0004", ["Model B Rev 2.0 (mounting holes,Sony)", "256MB"],
"0005", ["Model B Rev 2.0 (mounting holes,Qisda)", "256MB"],
"0006", ["Model B Rev 2.0 (mounting holes,Egoman)", "256MB"],
"0007", ["Model A (Egoman)", "256MB"],
"0008", ["Model A (Sony)", "256MB"],
"0009", ["Model A (Qisda)", "256MB"],
"000d", ["Model B Rev 2.0 (mounting holes,Egoman)", "512MB"],
"000e", ["Model B Rev 2.0 (mounting holes,Sony)", "512MB"],
"000f", ["Model B Rev 2.0 (mounting holes,Qisda)", "512MB"],
"0010", ["Model B+", "512MB"],
"0011", ["Compute Module", "512MB"],
"0012", ["Model A+", "256MB"]
]
ix = model.index(rev)
board, memory = model[ix+1]
return (rev, board, memory)
rev, board, memory = revToModel()
print ("Revision: %s, Board: %s, Memory: %s" % (rev,board,memory))It's not future proof.Gumboil wrote:Excellent - thank you Dougie
It doesn't work if the warranty bit is set:DougieLawson wrote: But it works for now.
Code: Select all
rob@raspberrypi ~ $ cat /proc/cpuinfo |grep Revision
Revision : 100000e
Your problem, you can code round it.RobHenry wrote:It doesn't work if the warranty bit is set:DougieLawson wrote: But it works for now.
Could be fixed in a number of ways, I don't have a pi without the warranty bit set so can't regression test.Code: Select all
rob@raspberrypi ~ $ cat /proc/cpuinfo |grep Revision Revision : 100000e