Flicker adjustments and text padding

This commit is contained in:
Chuck
2025-04-07 20:54:53 -05:00
parent 4fd1a9c492
commit b9641389d0
2 changed files with 13 additions and 9 deletions

View File

@@ -11,19 +11,19 @@
"cols": 64, "cols": 64,
"chain_length": 2, "chain_length": 2,
"parallel": 1, "parallel": 1,
"brightness": 50, "brightness": 60,
"hardware_mapping": "adafruit-hat-pwm", "hardware_mapping": "adafruit-hat-pwm",
"scan_mode": "progressive", "scan_mode": "progressive",
"pwm_bits": 11, "pwm_bits": 8,
"pwm_dither_bits": 0, "pwm_dither_bits": 1,
"pwm_lsb_nanoseconds": 130, "pwm_lsb_nanoseconds": 130,
"disable_hardware_pulsing": true, "disable_hardware_pulsing": true,
"inverse_colors": false, "inverse_colors": false,
"show_refresh_rate": false, "show_refresh_rate": false,
"limit_refresh_rate_hz": 0 "limit_refresh_rate_hz": 100
}, },
"runtime": { "runtime": {
"gpio_slowdown": 4 "gpio_slowdown": 2
}, },
"rotation_interval": 30 "rotation_interval": 30
}, },

View File

@@ -23,8 +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
# Use a smaller font size for better fitting # Use an even smaller font size for better fitting
self.font = ImageFont.truetype("DejaVuSans.ttf", 16) self.font = ImageFont.truetype("DejaVuSans.ttf", 12)
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
@@ -89,6 +89,7 @@ class DisplayManager:
line_widths = [] line_widths = []
total_height = 0 total_height = 0
max_width = 0 max_width = 0
padding = 2 # Add padding between lines
for line in lines: for line in lines:
bbox = self.draw.textbbox((0, 0), line, font=self.font) bbox = self.draw.textbbox((0, 0), line, font=self.font)
@@ -97,7 +98,10 @@ class DisplayManager:
line_heights.append(line_height) line_heights.append(line_height)
line_widths.append(line_width) line_widths.append(line_width)
total_height += line_height total_height += line_height
max_width = max(max_width, line_width)
# Add padding between lines
if len(lines) > 1:
total_height += padding * (len(lines) - 1)
# Calculate starting Y position to center all lines vertically # Calculate starting Y position to center all lines vertically
if y is None: if y is None:
@@ -114,7 +118,7 @@ class DisplayManager:
logger.info(f"Drawing line '{line}' at position ({line_x}, {current_y})") 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) self.draw.text((line_x, current_y), line, font=self.font, fill=color)
current_y += line_heights[i] current_y += line_heights[i] + padding
self.matrix.SetImage(self.image) self.matrix.SetImage(self.image)