69 lines
1.4 KiB
Python
69 lines
1.4 KiB
Python
"""
|
|
https://blog.gtwang.org/iot/raspberry-pi-vcgencmd-hardware-information/
|
|
"""
|
|
|
|
from biopro.util.sys import system_call
|
|
from biopro.util.text import part_suffix
|
|
|
|
_RUNTIME_COMPILE = False
|
|
|
|
|
|
def measure_clock(clock: str) -> int:
|
|
"""
|
|
|
|
:param clock: could be arm, core, h264, isp, v3d, uart, pwm, emmc, pixel, vec, hdmi, dpi
|
|
:return: frequency in Hz
|
|
"""
|
|
try:
|
|
output = system_call('vcgencmd', 'measure_clock', clock).strip()
|
|
_, freq = part_suffix(output, '=')
|
|
return int(freq)
|
|
except FileNotFoundError:
|
|
if _RUNTIME_COMPILE:
|
|
raise
|
|
else:
|
|
return 0
|
|
|
|
|
|
def measure_volts(hd: str = 'core') -> float:
|
|
"""
|
|
|
|
:param hd: core, sdram_c, sdram_i, sdram_p
|
|
:return:
|
|
"""
|
|
try:
|
|
output = system_call('vcgencmd', 'measure_volts', hd).strip()
|
|
_, volt = part_suffix(output, '=')
|
|
|
|
if volt.endswith('V'):
|
|
volt = volt[:-1]
|
|
|
|
return float(volt)
|
|
except FileNotFoundError:
|
|
if _RUNTIME_COMPILE:
|
|
raise
|
|
else:
|
|
return 0.0
|
|
|
|
|
|
def measure_temp() -> float:
|
|
"""
|
|
|
|
:return: temperature in 'C
|
|
"""
|
|
try:
|
|
output = system_call('vcgencmd', 'measure_temp').strip()
|
|
_, temp = part_suffix(output, '=')
|
|
|
|
if temp.endswith("'C"):
|
|
temp = temp[:-2]
|
|
|
|
return float(temp)
|
|
except FileNotFoundError:
|
|
if _RUNTIME_COMPILE:
|
|
raise
|
|
else:
|
|
return 0.0
|
|
|
|
|