Skip to content

Commit ef04b6c

Browse files
committed
Removed harcoding of vcgencmd command
1 parent 2913313 commit ef04b6c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

RaspberryPiVcgencmd/Vcgencmd.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class Vcgencmd:
1111
def __init__(self):
1212
# TODO: add a "vcgencmd run" check and first time its called we should check what commands are supported
1313
# TODO: allow specifying where vcgencmd lives.
14-
pass
14+
self.vcgen_command = "vcgencmd"
1515

1616
def get_cpu_temp(self, fahrenheit=False):
1717
"""Get the cpu temperature of the soc, optionally request output in fahrenheit"""
18-
lines = subprocess.check_output(["vcgencmd", "measure_temp"])
18+
lines = subprocess.check_output([self.vcgen_command, "measure_temp"])
1919
temp = float(self._parse_lines(lines)['temp'][:-2])
2020

2121
if fahrenheit:
@@ -26,8 +26,8 @@ def get_cpu_temp(self, fahrenheit=False):
2626
def get_ram_split(self):
2727
"""Get the ram split between cpu/gpu this returns a dict"""
2828

29-
lines_arm = subprocess.check_output(["vcgencmd", "get_mem", "arm"])
30-
lines_gpu = subprocess.check_output(["vcgencmd", "get_mem", "gpu"])
29+
lines_arm = subprocess.check_output([self.vcgen_command, "get_mem", "arm"])
30+
lines_gpu = subprocess.check_output([self.vcgen_command, "get_mem", "gpu"])
3131
arm = self._parse_lines(lines_arm)['arm']
3232
gpu = self._parse_lines(lines_gpu)['gpu']
3333
return {
@@ -39,7 +39,7 @@ def measure_volts(self, type="core"):
3939
"""Measures the volts on parts of the chip"""
4040

4141
if type in ["core", "sdram_c", "sdram_i", "sdram_p"]:
42-
lines = subprocess.check_output(["vcgencmd", "measure_volts", type])
42+
lines = subprocess.check_output([self.vcgen_command, "measure_volts", type])
4343
data = self._parse_lines(lines)
4444
return float(data['volt'][:-1])
4545
else:
@@ -48,27 +48,27 @@ def measure_volts(self, type="core"):
4848
def measure_clock(self, type):
4949
"""Returns the clock speed in Hz of various parts of the chip"""
5050
if type in ["arm", "core", "h264", "isp", "v3d", "uart", "pwm", "emmc", "pixel", "vec", "hdmi", "dpi"]:
51-
line = subprocess.check_output(["vcgencmd", "measure_clock", type])
51+
line = subprocess.check_output([self.vcgen_command, "measure_clock", type])
5252
return self._parse_line_get_value(line)
5353
else:
5454
raise ValueError("Type must be on of arm, core, h264, isp, v3d, uart, pwm, emmc, pixel, vec, hdmi, dpi")
5555

5656
def is_codec_available(self, codec):
5757
"""Returns whether the codec is available on the Raspberry Pi"""
5858
if codec in ["H264", "MPG2", "WVC1", "MPG4", "MJPG", "WMV9"]:
59-
line = subprocess.check_output(["vcgencmd", "codec_enabled", codec])
59+
line = subprocess.check_output([self.vcgen_command, "codec_enabled", codec])
6060
return (self._parse_line_get_value(line) == "enabled")
6161
else:
6262
raise ValueError("Codec must be one of H264, MPG2, WVC1, MPG4, MJPG, WMV9")
6363

6464
def get_version(self):
6565
"""Gets the version string of the firmware"""
66-
return subprocess.check_output(["vcgencmd", "version"]).decode("utf-8").rstrip()
66+
return subprocess.check_output([self.vcgen_command, "version"]).decode("utf-8").rstrip()
6767

6868
def set_display_power(self, power):
6969
"""Sets the display power of the Raspberry Pi, warning setting this to 0 will disable video output"""
7070
if power in [0, 1]:
71-
subprocess.check_output(["vcgencmd", "display_power", str(power)])
71+
subprocess.check_output([self.vcgen_command, "display_power", str(power)])
7272
else:
7373
raise ValueError("Power must be either 0 or 1")
7474

0 commit comments

Comments
 (0)