Last active
January 5, 2024 01:57
-
-
Save simryang/a03d9fbdaf3b0ef096a2bc85926b4926 to your computer and use it in GitHub Desktop.
get raspberry type in python include Raspberry pi 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
from pathlib import Path | |
def get_rpi_type() -> str: | |
rev = int(yaml.safe_load(Path("/proc/cpuinfo").read_text().replace("\t", "")).get("Revision"), base=16) | |
rpi_type = (rev & 0x00000FF0)>>4 if rev & 0x800000 else [0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 6, 2, 3, 6, 2][rev & 0x1f] | |
rpi_model = {0: 'A', 1: 'B', 2: 'A+', 3: 'B+', 4: '2B', 6: 'CM1', 8: '3B', 9: 'Zero', 0xa: 'CM3', 0xc: 'ZeroW', 0xd: '3B+', 0xe: '3A+', 0x10: 'CM3+', 0x11: '4B', 0x12: 'Zero2W', 0x13: '400', 0x14: 'CM4', 0x15: 'CM4S', 0x17: '5',} | |
return rpi_model.get(rpi_type, "") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment