Skip to content

Commit

Permalink
Brightness control and linux symlink support (#23)
Browse files Browse the repository at this point in the history
* Added brightness control and symlink support

* Add brightness validation and correction
  • Loading branch information
svenvschie authored Dec 2, 2024
1 parent 7707d16 commit 401ea07
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/wrappers/python/contourwall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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.
Expand All @@ -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))
Expand Down Expand Up @@ -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

0 comments on commit 401ea07

Please sign in to comment.