From 401ea07a4b789cdc8053ade9372db5600e2dd843 Mon Sep 17 00:00:00 2001 From: Sven van Schie <129615435+svenvschie@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:25:50 +0100 Subject: [PATCH] Brightness control and linux symlink support (#23) * Added brightness control and symlink support * Add brightness validation and correction --- lib/wrappers/python/contourwall.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/wrappers/python/contourwall.py b/lib/wrappers/python/contourwall.py index 5410442..f71a87e 100644 --- a/lib/wrappers/python/contourwall.py +++ b/lib/wrappers/python/contourwall.py @@ -4,6 +4,7 @@ from ctypes import c_void_p, c_char_p, c_uint32, c_uint8, c_bool from sys import platform import time +import os class ContourWallCore(ctypes.Structure): """ @@ -124,7 +125,7 @@ def single_new_with_port(self, port: str, baudrate: int=2_000_000) -> None: else: raise Exception(f"COM port '{port}' does not exist") - def show(self, sleep_ms:int=0, optimize:bool=True) -> None: + def show(self, sleep_ms:int=0, optimize:bool=True, brightness:float=1) -> None: """ Show the current state of the pixel array on the ContourWall. @@ -137,7 +138,12 @@ def show(self, sleep_ms:int=0, optimize:bool=True) -> None: ``` This example code will show the current state of the pixel array on the ContourWall. """ - + + if not (0 <= brightness <= 1): + print(f"[Contour Wall Warning] Brightness needs to be a float between 0 and 1, not {brightness}.") + brightness = max(0, min(brightness, 1)) + + self.pixels[:] = self.pixels[:] // (1 / brightness) ptr: ctypes._Pointer[c_uint8] = ctypes.cast(ctypes.c_char_p(self.pixels.tobytes()), ctypes.POINTER(ctypes.c_uint8)) self._update_all(ctypes.byref(self._cw_core), ptr, optimize) self._show(ctypes.byref(self._cw_core)) @@ -229,6 +235,9 @@ def check_comport_existence(COMports: list[str]) -> bool: """ for COMport in COMports: + if os.path.islink(COMport): + COMport = os.path.realpath(COMport) + if not any(port.device == COMport for port in serial.tools.list_ports.comports()): return False return True \ No newline at end of file