From 9b782a87fbf4307e0c2999ed2ed0e009a08718ec Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Tue, 2 Jan 2024 19:03:58 -0800 Subject: [PATCH] Update `discover` to try and resolve a path to `vcgencmd` instead of trying a hard-coded one --- ovos_gui_plugin_shell_companion/brightness.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ovos_gui_plugin_shell_companion/brightness.py b/ovos_gui_plugin_shell_companion/brightness.py index 7b3bd2b..a38db84 100644 --- a/ovos_gui_plugin_shell_companion/brightness.py +++ b/ovos_gui_plugin_shell_companion/brightness.py @@ -5,7 +5,7 @@ import time from datetime import timedelta from distutils.spawn import find_executable -from os.path import isfile +from os.path import isfile, exists from astral import LocationInfo from astral.sun import sun from ovos_bus_client import Message @@ -75,10 +75,21 @@ def is_auto_dim_enabled(self, message=None): # Discover the brightness control device interface (HDMI / DSI) on the Raspberry PI def discover(self): + try: + vcgen_path = (subprocess.run(["which", "vcgencmd"], check=True, + capture_output=True).stdout.decode() + .strip()) + except subprocess.CalledProcessError: + vcgen_path = "/opt/vc/bin/vcgencmd" if ( + exists("/opt/vc/bin/vcgencmd")) else None + if not vcgen_path: + LOG.info("Falling back to DSI interface") + self.device_interface = "DSI" try: LOG.info("Discovering brightness control device interface") - proc = subprocess.Popen(["/opt/vc/bin/vcgencmd", - "get_config", "display_default_lcd"], stdout=subprocess.PIPE) + proc = subprocess.Popen([vcgen_path, + "get_config", "display_default_lcd"], + stdout=subprocess.PIPE) if proc.stdout.read().decode("utf-8").strip() == "1": self.device_interface = "DSI" else: @@ -101,7 +112,8 @@ def discover(self): if self.ddcutil_detected_bus: proc_fetch_vcp = subprocess.Popen( - ["/usr/bin/ddcutil", "getvcp", "known", "--bus", self.ddcutil_detected_bus], + ["/usr/bin/ddcutil", "getvcp", "known", "--bus", + self.ddcutil_detected_bus], stdout=subprocess.PIPE) # check the vcp output for the Brightness string and get its VCP code for line in proc_fetch_vcp.stdout: