Display improvements

display rotate 0
set refresh to 120
slowed down weather
scaled text to fit
This commit is contained in:
Chuck
2025-04-07 20:45:08 -05:00
parent f2fff9c0c9
commit c3cfe8ed6c
2 changed files with 36 additions and 13 deletions

View File

@@ -24,7 +24,7 @@
"multiplexing": 0, "multiplexing": 0,
"disable_hardware_pulsing": true, "disable_hardware_pulsing": true,
"inverse_colors": false, "inverse_colors": false,
"show_refresh_rate": false, "show_refresh_rate": true,
"limit_refresh_rate_hz": 0 "limit_refresh_rate_hz": 0
}, },
"runtime": { "runtime": {

View File

@@ -23,7 +23,8 @@ class DisplayManager:
self.config = config self.config = config
logger.info("Initializing DisplayManager with config: %s", config) logger.info("Initializing DisplayManager with config: %s", config)
self._setup_matrix() # This now sets self.matrix self._setup_matrix() # This now sets self.matrix
self.font = ImageFont.truetype("DejaVuSans.ttf", 24) # Use a smaller font size for better fitting
self.font = ImageFont.truetype("DejaVuSans.ttf", 16)
self.image = Image.new('RGB', (self.matrix.width, self.matrix.height)) self.image = Image.new('RGB', (self.matrix.width, self.matrix.height))
self.draw = ImageDraw.Draw(self.image) self.draw = ImageDraw.Draw(self.image)
DisplayManager._initialized = True DisplayManager._initialized = True
@@ -80,19 +81,41 @@ class DisplayManager:
"""Draw text on the display with automatic centering.""" """Draw text on the display with automatic centering."""
self.clear() self.clear()
# Get text size # Split text into lines if it contains newlines
text_bbox = self.draw.textbbox((0, 0), text, font=self.font) lines = text.split('\n')
text_width = text_bbox[2] - text_bbox[0]
text_height = text_bbox[3] - text_bbox[1]
# Calculate center position if not specified # Calculate total height of all lines
if x is None: line_heights = []
x = (self.matrix.width - text_width) // 2 line_widths = []
total_height = 0
max_width = 0
for line in lines:
bbox = self.draw.textbbox((0, 0), line, font=self.font)
line_width = bbox[2] - bbox[0]
line_height = bbox[3] - bbox[1]
line_heights.append(line_height)
line_widths.append(line_width)
total_height += line_height
max_width = max(max_width, line_width)
# Calculate starting Y position to center all lines vertically
if y is None: if y is None:
y = (self.matrix.height - text_height) // 2 y = (self.matrix.height - total_height) // 2
# Draw each line
current_y = y
for i, line in enumerate(lines):
if x is None:
# Center this line horizontally
line_x = (self.matrix.width - line_widths[i]) // 2
else:
line_x = x
logger.info(f"Drawing line '{line}' at position ({line_x}, {current_y})")
self.draw.text((line_x, current_y), line, font=self.font, fill=color)
current_y += line_heights[i]
logger.info(f"Drawing text '{text}' at position ({x}, {y})")
self.draw.text((x, y), text, font=self.font, fill=color)
self.matrix.SetImage(self.image) self.matrix.SetImage(self.image)
def cleanup(self): def cleanup(self):