mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 21:33:00 +00:00
Fix font initialization: Add regular_font to DisplayManager
This commit is contained in:
@@ -36,18 +36,18 @@ class DisplayManager:
|
|||||||
options.parallel = hardware_config.get('parallel', 1)
|
options.parallel = hardware_config.get('parallel', 1)
|
||||||
options.hardware_mapping = hardware_config.get('hardware_mapping', 'adafruit-hat-pwm')
|
options.hardware_mapping = hardware_config.get('hardware_mapping', 'adafruit-hat-pwm')
|
||||||
|
|
||||||
# Balance performance and stability
|
# Optimize display settings for chained panels
|
||||||
options.brightness = 100
|
options.brightness = 100
|
||||||
options.pwm_bits = 10 # Increased from 8 for better color depth
|
options.pwm_bits = 11
|
||||||
options.pwm_lsb_nanoseconds = 150 # Increased for better stability
|
options.pwm_lsb_nanoseconds = 200 # Increased for better stability
|
||||||
options.led_rgb_sequence = 'RGB'
|
options.led_rgb_sequence = 'RGB'
|
||||||
options.pixel_mapper_config = ''
|
options.pixel_mapper_config = ''
|
||||||
options.row_address_type = 0
|
options.row_address_type = 0
|
||||||
options.multiplexing = 0
|
options.multiplexing = 0
|
||||||
options.disable_hardware_pulsing = False # Re-enable hardware pulsing for stability
|
options.disable_hardware_pulsing = False # Enable hardware pulsing for better sync
|
||||||
options.show_refresh_rate = False
|
options.show_refresh_rate = False
|
||||||
options.limit_refresh_rate_hz = 90 # Reduced from 120Hz for better stability
|
options.limit_refresh_rate_hz = 60 # Reduced refresh rate for stability
|
||||||
options.gpio_slowdown = 2 # Increased for better stability
|
options.gpio_slowdown = 2 # Increased slowdown for better stability
|
||||||
|
|
||||||
# Initialize the matrix
|
# Initialize the matrix
|
||||||
self.matrix = RGBMatrix(options=options)
|
self.matrix = RGBMatrix(options=options)
|
||||||
@@ -94,11 +94,14 @@ class DisplayManager:
|
|||||||
# Copy the current image to the offscreen canvas
|
# Copy the current image to the offscreen canvas
|
||||||
self.offscreen_canvas.SetImage(self.image)
|
self.offscreen_canvas.SetImage(self.image)
|
||||||
|
|
||||||
# Swap buffers immediately
|
# Wait for the next vsync before swapping
|
||||||
self.matrix.SwapOnVSync(self.offscreen_canvas, False)
|
self.matrix.SwapOnVSync(self.offscreen_canvas)
|
||||||
|
|
||||||
# Swap our canvas references
|
# Swap our canvas references
|
||||||
self.offscreen_canvas, self.current_canvas = self.current_canvas, self.offscreen_canvas
|
self.offscreen_canvas, self.current_canvas = self.current_canvas, self.offscreen_canvas
|
||||||
|
|
||||||
|
# Small delay to ensure stable refresh
|
||||||
|
time.sleep(0.001)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error updating display: {e}")
|
logger.error(f"Error updating display: {e}")
|
||||||
|
|
||||||
@@ -119,32 +122,25 @@ class DisplayManager:
|
|||||||
logger.error(f"Error clearing display: {e}")
|
logger.error(f"Error clearing display: {e}")
|
||||||
|
|
||||||
def _load_fonts(self):
|
def _load_fonts(self):
|
||||||
"""Load fonts optimized for LED matrix display."""
|
"""Load fonts with proper error handling."""
|
||||||
try:
|
try:
|
||||||
# Use Press Start 2P font - perfect for LED matrix displays
|
# Load regular font (Press Start 2P)
|
||||||
font_path = "assets/fonts/PressStart2P-Regular.ttf"
|
self.regular_font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 10)
|
||||||
|
logger.info("Regular font loaded successfully")
|
||||||
|
|
||||||
# For 32px height matrix, optimized sizes for pixel-perfect display
|
# Load small font (Press Start 2P at smaller size)
|
||||||
large_size = 10 # Large text for time and main info
|
self.small_font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
small_size = 8 # Small text for secondary information
|
logger.info("Small font loaded successfully")
|
||||||
|
|
||||||
try:
|
|
||||||
self.font = ImageFont.truetype(font_path, large_size)
|
|
||||||
self.small_font = ImageFont.truetype(font_path, small_size)
|
|
||||||
logger.info(f"Loaded Press Start 2P font: {font_path} (large: {large_size}px, small: {small_size}px)")
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(f"Failed to load Press Start 2P font, falling back to default: {e}")
|
|
||||||
self.font = ImageFont.load_default()
|
|
||||||
self.small_font = ImageFont.load_default()
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in font loading: {e}")
|
logger.error(f"Error in font loading: {e}")
|
||||||
self.font = ImageFont.load_default()
|
# Fallback to default font
|
||||||
self.small_font = self.font
|
self.regular_font = ImageFont.load_default()
|
||||||
|
self.small_font = self.regular_font
|
||||||
|
|
||||||
def draw_text(self, text: str, x: int = None, y: int = None, color: Tuple[int, int, int] = (255, 255, 255), small_font: bool = False) -> None:
|
def draw_text(self, text: str, x: int = None, y: int = None, color: Tuple[int, int, int] = (255, 255, 255), small_font: bool = False) -> None:
|
||||||
"""Draw text on the display with improved clarity."""
|
"""Draw text on the display with improved clarity."""
|
||||||
font = self.small_font if small_font else self.font
|
font = self.small_font if small_font else self.regular_font
|
||||||
|
|
||||||
# Get text dimensions including ascenders and descenders
|
# Get text dimensions including ascenders and descenders
|
||||||
bbox = self.draw.textbbox((0, 0), text, font=font)
|
bbox = self.draw.textbbox((0, 0), text, font=font)
|
||||||
|
|||||||
Reference in New Issue
Block a user