Skip to content

Commit

Permalink
Update discover to try and resolve a path to vcgencmd instead of …
Browse files Browse the repository at this point in the history
…trying a hard-coded one
  • Loading branch information
NeonDaniel committed Jan 3, 2024
1 parent 312a5ee commit 9b782a8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ovos_gui_plugin_shell_companion/brightness.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 9b782a8

Please sign in to comment.