PiHardwareInfo 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Rex Zhang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: PiHardwareInfo
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Get Raspberry Pi hardware info
|
|
5
|
+
Author: Rex Zhang
|
|
6
|
+
Author-email: rex.zhang@gmail.com
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: repository, https://github.com/rexzhang/pi-hardware-info
|
|
9
|
+
Keywords: raspberrypi
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
|
|
18
|
+
# PiHardwareInfo
|
|
19
|
+
|
|
20
|
+
[](https://pypi.org/project/PiHardwareInfo/)
|
|
21
|
+
[](https://pypi.org/project/PiHardwareInfo/)
|
|
22
|
+
[](https://pypi.org/project/PiHardwareInfo/)
|
|
23
|
+
|
|
24
|
+
Get Raspberry Pi hardware/version info from /proc/cpuinfo
|
|
25
|
+
|
|
26
|
+
## Try
|
|
27
|
+
|
|
28
|
+
run
|
|
29
|
+
|
|
30
|
+
```console
|
|
31
|
+
curl -s https://raw.githubusercontent.com/rexzhang/pi-hardware-info/master/pi_hardware_info.py | python3
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
result
|
|
35
|
+
|
|
36
|
+
```console
|
|
37
|
+
PiHardwareInfo(revision_code='d04170', model_type=<ModelType.RPI_5: 23>, processor=<Processor.BCM2712: 4>, memory=8192, revision='1.0', serial_number='ecc0679911343e07', model_name='Raspberry Pi 5 Model B Rev 1.0', overvoltage=False, otp_program=False, otp_read=False, manufacturer=<Manufacturer.SONY_UK: 0>)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```console
|
|
43
|
+
pip install PiHardwareInfo
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage as library
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from pi_hardware_info import ModelType, get_info
|
|
50
|
+
|
|
51
|
+
info = get_info()
|
|
52
|
+
if info.model_type == ModelType.MODEL_3B_PLUS:
|
|
53
|
+
print('5G Wifi ready')
|
|
54
|
+
|
|
55
|
+
elif info.model_type == ModelType.MODEL_3B:
|
|
56
|
+
print('only 2.4G Wifi')
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage as tool
|
|
60
|
+
|
|
61
|
+
```shell
|
|
62
|
+
python -m pi_hardware_info
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## History
|
|
66
|
+
|
|
67
|
+
### 0.5.0
|
|
68
|
+
|
|
69
|
+
- Add, Support to raspberry pi 5
|
|
70
|
+
- Codebase modernization Updates
|
|
71
|
+
- Drop py3.5 py3.6 py3.7 py3.8
|
|
72
|
+
- Add type hints
|
|
73
|
+
- Add unit test
|
|
74
|
+
- Add pyproject.toml
|
|
75
|
+
- Add pre-commit
|
|
76
|
+
|
|
77
|
+
### 0.4.0
|
|
78
|
+
|
|
79
|
+
- Add, support Zero2W/400/CM4
|
|
80
|
+
- Add, Overvoltage/OTP Program/OTP Read support
|
|
81
|
+
|
|
82
|
+
### 0.3.3
|
|
83
|
+
|
|
84
|
+
- Support raspberry pi 4B
|
|
85
|
+
- Rewrite some code
|
|
86
|
+
|
|
87
|
+
### 0.2.0
|
|
88
|
+
|
|
89
|
+
- Add old style revision code support, support 1A/1B
|
|
90
|
+
|
|
91
|
+
### 0.1.0
|
|
92
|
+
|
|
93
|
+
- First release
|
|
94
|
+
|
|
95
|
+
## Alternative
|
|
96
|
+
|
|
97
|
+
- <https://github.com/tompreston/raspi-version>
|
|
98
|
+
- <https://pypi.org/project/pirev>
|
|
99
|
+
- <https://pypi.org/project/RPi.version>
|
|
100
|
+
|
|
101
|
+
## Ref
|
|
102
|
+
|
|
103
|
+
- <https://www.raspberrypi.com/documentation/computers/raspberry-pi.html>
|
|
104
|
+
- <https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-revision-codes>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
pi_hardware_info.py,sha256=EBiQcvB4NQFVhipX7PxQIh6Y73H18-HBWET8pR6V94Q,4986
|
|
2
|
+
PiHardwareInfo-0.5.0.dist-info/LICENSE,sha256=fGRFCl6JPYZa1XDp1afRCCutZggXR5E8AwljwpEaK3g,1066
|
|
3
|
+
PiHardwareInfo-0.5.0.dist-info/METADATA,sha256=FQYcnmR-BF3mdSljKuu4X_WSOmKuQ6eoPy0VuMqppY0,2562
|
|
4
|
+
PiHardwareInfo-0.5.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
5
|
+
PiHardwareInfo-0.5.0.dist-info/top_level.txt,sha256=Zma3_8OrsU5_esnO0EvYwsGZW9j9myNKjgk5uH8-uDI,17
|
|
6
|
+
PiHardwareInfo-0.5.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pi_hardware_info
|
pi_hardware_info.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Get Raspberry Pi hardware info
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from logging import getLogger
|
|
9
|
+
|
|
10
|
+
__version__ = "0.5.0"
|
|
11
|
+
|
|
12
|
+
__author__ = "Rex Zhang"
|
|
13
|
+
__author_email__ = "rex.zhang@gmail.com"
|
|
14
|
+
__licence__ = "MIT"
|
|
15
|
+
|
|
16
|
+
__description__ = "Get Raspberry Pi hardware info"
|
|
17
|
+
__project_url__ = "https://github.com/rexzhang/pi-hardware-info"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
logger = getLogger(__file__)
|
|
21
|
+
|
|
22
|
+
_memory = [256, 512, 1024, 2048, 4096, 8192, 16384]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Manufacturer(Enum):
|
|
26
|
+
UNKNOWN = -100
|
|
27
|
+
|
|
28
|
+
QISDA = -10
|
|
29
|
+
|
|
30
|
+
SONY_UK = 0
|
|
31
|
+
EGOMAN = 1
|
|
32
|
+
EMBEST = 2
|
|
33
|
+
SONY_JAPAN = 3
|
|
34
|
+
EMBEST2 = 4
|
|
35
|
+
STADIUM = 5
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Processor(Enum):
|
|
39
|
+
UNKNOWN = -100
|
|
40
|
+
|
|
41
|
+
BCM2835 = 0
|
|
42
|
+
BCM2836 = 1
|
|
43
|
+
BCM2837 = 2
|
|
44
|
+
BCM2711 = 3
|
|
45
|
+
BCM2712 = 4
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ModelType(Enum):
|
|
49
|
+
UNKNOWN = -100
|
|
50
|
+
|
|
51
|
+
RPI_A = 0
|
|
52
|
+
RPI_B = 1
|
|
53
|
+
RPI_A_PLUS = 2
|
|
54
|
+
RPI_B_PLUS = 3
|
|
55
|
+
RPI_2B = 4
|
|
56
|
+
RPI_ALPHA = 5
|
|
57
|
+
RPI_CM1 = 6
|
|
58
|
+
# 0x7 pass
|
|
59
|
+
RPI_3B = 8
|
|
60
|
+
RPI_ZERO = 9
|
|
61
|
+
RPI_CM3 = 0xA
|
|
62
|
+
# 0xb pass
|
|
63
|
+
RPI_ZERO_W = 0xC
|
|
64
|
+
RPI_3B_PLUS = 0xD
|
|
65
|
+
RPI_3A_PLUS = 0xE
|
|
66
|
+
# 0x0f: Internal use only
|
|
67
|
+
RPI_CM3_PLUS = 0x10
|
|
68
|
+
RPI_4B = 0x11
|
|
69
|
+
RPI_Zero2W = 0x12
|
|
70
|
+
RPI_400 = 0x13
|
|
71
|
+
RPI_CM4 = 0x14
|
|
72
|
+
RPI_CM4S = 0x15
|
|
73
|
+
# 0x16: Internal use only
|
|
74
|
+
RPI_5 = 0x17
|
|
75
|
+
RPI_CM5 = 0x18
|
|
76
|
+
RPI_CM5_LITE = 0x19
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
_old_style = {
|
|
80
|
+
0x0000: (ModelType.UNKNOWN, "0.0", 0, Manufacturer.UNKNOWN),
|
|
81
|
+
0x0002: (ModelType.RPI_B, "1.0", 256, Manufacturer.EGOMAN),
|
|
82
|
+
0x0003: (ModelType.RPI_B, "1.0", 256, Manufacturer.EGOMAN),
|
|
83
|
+
0x0004: (ModelType.RPI_B, "2.0", 256, Manufacturer.SONY_UK),
|
|
84
|
+
0x0005: (ModelType.RPI_B, "2.0", 256, Manufacturer.QISDA),
|
|
85
|
+
0x0006: (ModelType.RPI_B, "2.0", 256, Manufacturer.EGOMAN),
|
|
86
|
+
0x0007: (ModelType.RPI_A, "2.0", 256, Manufacturer.EGOMAN),
|
|
87
|
+
0x0008: (ModelType.RPI_A, "2.0", 256, Manufacturer.SONY_UK),
|
|
88
|
+
0x0009: (ModelType.RPI_A, "2.0", 256, Manufacturer.QISDA),
|
|
89
|
+
0x000D: (ModelType.RPI_B, "2.0", 512, Manufacturer.EGOMAN),
|
|
90
|
+
0x000E: (ModelType.RPI_B, "2.0", 512, Manufacturer.SONY_UK),
|
|
91
|
+
0x000F: (ModelType.RPI_B, "2.0", 512, Manufacturer.EGOMAN),
|
|
92
|
+
0x0010: (ModelType.RPI_B_PLUS, "1.2", 512, Manufacturer.SONY_UK),
|
|
93
|
+
0x0011: (ModelType.RPI_CM1, "1.0", 512, Manufacturer.SONY_UK),
|
|
94
|
+
0x0012: (ModelType.RPI_A_PLUS, "1.1", 256, Manufacturer.SONY_UK),
|
|
95
|
+
0x0013: (ModelType.RPI_B_PLUS, "1.2", 512, Manufacturer.EMBEST),
|
|
96
|
+
0x0014: (ModelType.RPI_CM1, "1.0", 512, Manufacturer.EMBEST),
|
|
97
|
+
0x0015: (ModelType.RPI_A_PLUS, "1.1", 512, Manufacturer.EMBEST),
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@dataclass
|
|
102
|
+
class PiHardwareInfo:
|
|
103
|
+
revision_code: str
|
|
104
|
+
|
|
105
|
+
model_type: ModelType = ModelType.UNKNOWN
|
|
106
|
+
processor: Processor = Processor.UNKNOWN
|
|
107
|
+
memory: int = 0
|
|
108
|
+
revision: str = "0.0"
|
|
109
|
+
serial_number: str = "UNKNOWN"
|
|
110
|
+
model_name: str = "UNKNOWN"
|
|
111
|
+
|
|
112
|
+
overvoltage: bool = False
|
|
113
|
+
otp_program: bool = False
|
|
114
|
+
otp_read: bool = False
|
|
115
|
+
|
|
116
|
+
manufacturer: Manufacturer = Manufacturer.UNKNOWN
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def get_info_from_revision_code(revision_code: str) -> PiHardwareInfo:
|
|
120
|
+
info = PiHardwareInfo(revision_code)
|
|
121
|
+
code = int(revision_code, 16)
|
|
122
|
+
|
|
123
|
+
new_flag = (code & 0x800000) >> 23
|
|
124
|
+
if new_flag:
|
|
125
|
+
info.model_type = ModelType((code & 0xFF0) >> 4)
|
|
126
|
+
info.processor = Processor((code & 0xF000) >> 12)
|
|
127
|
+
info.memory = _memory[(code & 0x700000) >> 20]
|
|
128
|
+
info.revision = f"1.{code & 0xF}"
|
|
129
|
+
|
|
130
|
+
info.overvoltage = bool((code & 0x80000000) >> 31)
|
|
131
|
+
info.overvoltage = bool((code & 0x40000000) >> 30)
|
|
132
|
+
info.overvoltage = bool((code & 0x20000000) >> 29)
|
|
133
|
+
|
|
134
|
+
info.manufacturer = Manufacturer((code & 0xF0000) >> 16)
|
|
135
|
+
|
|
136
|
+
else:
|
|
137
|
+
info.model_type = _old_style[code][0]
|
|
138
|
+
info.revision = _old_style[code][1]
|
|
139
|
+
info.memory = _old_style[code][2]
|
|
140
|
+
|
|
141
|
+
info.manufacturer = _old_style[code][3]
|
|
142
|
+
|
|
143
|
+
return info
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _get_data_from_line(line: str) -> str:
|
|
147
|
+
index = line.find(":")
|
|
148
|
+
if index == -1:
|
|
149
|
+
return ""
|
|
150
|
+
|
|
151
|
+
return line[index + 1 :].lstrip(" ").strip(" \n")
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def get_info():
|
|
155
|
+
info = None
|
|
156
|
+
serial_number = None
|
|
157
|
+
model_name = None
|
|
158
|
+
|
|
159
|
+
try:
|
|
160
|
+
with open("/proc/cpuinfo") as f:
|
|
161
|
+
for line in f:
|
|
162
|
+
if "Revision" in line:
|
|
163
|
+
info = get_info_from_revision_code(
|
|
164
|
+
re.sub(r"Revision\t: ([a-z0-9]+)\n", r"\1", line)
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
elif line.startswith("Serial"):
|
|
168
|
+
data = _get_data_from_line(line)
|
|
169
|
+
if data:
|
|
170
|
+
serial_number = data
|
|
171
|
+
|
|
172
|
+
elif line.startswith("Model"):
|
|
173
|
+
data = _get_data_from_line(line)
|
|
174
|
+
if data:
|
|
175
|
+
model_name = data
|
|
176
|
+
|
|
177
|
+
except FileNotFoundError:
|
|
178
|
+
logger.warning("Load Raspberry Pi hardware info from /proc/cpuinfo failed!")
|
|
179
|
+
|
|
180
|
+
if info is None:
|
|
181
|
+
return PiHardwareInfo("0000")
|
|
182
|
+
|
|
183
|
+
if serial_number:
|
|
184
|
+
info.serial_number = serial_number
|
|
185
|
+
if model_name:
|
|
186
|
+
info.model_name = model_name
|
|
187
|
+
|
|
188
|
+
return info
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
if __name__ == "__main__":
|
|
192
|
+
print(get_info())
|