mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
adjust display controller
to run single threaded instead of multithreaded
This commit is contained in:
@@ -4,22 +4,46 @@ import time
|
||||
from typing import Dict, Any
|
||||
|
||||
class DisplayManager:
|
||||
_instance = None
|
||||
_initialized = False
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls._instance is None:
|
||||
cls._instance = super(DisplayManager, cls).__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self, config: Dict[str, Any]):
|
||||
self.config = config
|
||||
self.matrix = self._setup_matrix()
|
||||
self.font = ImageFont.truetype("DejaVuSans.ttf", 24)
|
||||
self.image = Image.new('RGB', (self.matrix.width, self.matrix.height))
|
||||
self.draw = ImageDraw.Draw(self.image)
|
||||
# Only initialize once
|
||||
if not DisplayManager._initialized:
|
||||
self.config = config
|
||||
self.matrix = self._setup_matrix()
|
||||
self.font = ImageFont.truetype("DejaVuSans.ttf", 24)
|
||||
self.image = Image.new('RGB', (self.matrix.width, self.matrix.height))
|
||||
self.draw = ImageDraw.Draw(self.image)
|
||||
DisplayManager._initialized = True
|
||||
|
||||
def _setup_matrix(self) -> RGBMatrix:
|
||||
"""Setup the RGB matrix with the provided configuration."""
|
||||
options = RGBMatrixOptions()
|
||||
|
||||
# Hardware specific settings
|
||||
options.hardware_mapping = 'adafruit-hat' # Set for Adafruit Bonnet/HAT
|
||||
options.gpio_slowdown = 4 # Required for Pi 3
|
||||
options.rows = self.config.get('rows', 32)
|
||||
options.cols = self.config.get('cols', 64)
|
||||
options.chain_length = self.config.get('chain_length', 2)
|
||||
options.hardware_mapping = 'adafruit-hat'
|
||||
options.gpio_slowdown = 4
|
||||
options.parallel = 1
|
||||
options.pwm_bits = 11
|
||||
options.brightness = self.config.get('brightness', 50)
|
||||
options.pwm_lsb_nanoseconds = 130
|
||||
options.led_rgb_sequence = "RGB"
|
||||
options.pixel_mapper_config = ""
|
||||
options.multiplexing = 0
|
||||
|
||||
# Additional options for stability
|
||||
options.disable_hardware_pulsing = False
|
||||
options.show_refresh_rate = 1
|
||||
options.limit_refresh_rate_hz = 100
|
||||
|
||||
return RGBMatrix(options=options)
|
||||
|
||||
@@ -36,4 +60,7 @@ class DisplayManager:
|
||||
|
||||
def cleanup(self):
|
||||
"""Clean up resources."""
|
||||
self.matrix.Clear()
|
||||
self.matrix.Clear()
|
||||
# Reset the singleton state when cleaning up
|
||||
DisplayManager._instance = None
|
||||
DisplayManager._initialized = False
|
||||
Reference in New Issue
Block a user