mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
added dynamic display durations to scrolling managers
This commit is contained in:
@@ -88,6 +88,14 @@ class OddsTickerManager:
|
||||
self.broadcast_logo_max_width_ratio = self.odds_ticker_config.get('broadcast_logo_max_width_ratio', 0.8)
|
||||
self.request_timeout = self.odds_ticker_config.get('request_timeout', 30)
|
||||
|
||||
# Dynamic duration settings
|
||||
self.dynamic_duration_enabled = self.odds_ticker_config.get('dynamic_duration', True)
|
||||
self.min_duration = self.odds_ticker_config.get('min_duration', 30)
|
||||
self.max_duration = self.odds_ticker_config.get('max_duration', 300)
|
||||
self.duration_buffer = self.odds_ticker_config.get('duration_buffer', 0.1)
|
||||
self.dynamic_duration = 60 # Default duration in seconds
|
||||
self.total_scroll_width = 0 # Track total width for dynamic duration calculation
|
||||
|
||||
# Initialize managers
|
||||
self.cache_manager = CacheManager()
|
||||
self.odds_manager = OddsManager(self.cache_manager, ConfigManager())
|
||||
@@ -846,6 +854,10 @@ class OddsTickerManager:
|
||||
for y in range(height):
|
||||
self.ticker_image.putpixel((bar_x, y), (255, 255, 255))
|
||||
current_x += gap_width
|
||||
|
||||
# Calculate total scroll width for dynamic duration
|
||||
self.total_scroll_width = total_width
|
||||
self.calculate_dynamic_duration()
|
||||
|
||||
def _draw_text_with_outline(self, draw: ImageDraw.Draw, text: str, position: tuple, font: ImageFont.FreeTypeFont,
|
||||
fill: tuple = (255, 255, 255), outline_color: tuple = (0, 0, 0)) -> None:
|
||||
@@ -857,6 +869,67 @@ class OddsTickerManager:
|
||||
# Draw main text
|
||||
draw.text((x, y), text, font=font, fill=fill)
|
||||
|
||||
def calculate_dynamic_duration(self):
|
||||
"""Calculate the exact time needed to display all odds ticker content"""
|
||||
# If dynamic duration is disabled, use fixed duration from config
|
||||
if not self.dynamic_duration_enabled:
|
||||
self.dynamic_duration = self.odds_ticker_config.get('display_duration', 60)
|
||||
logger.debug(f"Dynamic duration disabled, using fixed duration: {self.dynamic_duration}s")
|
||||
return
|
||||
|
||||
if not self.total_scroll_width:
|
||||
self.dynamic_duration = self.min_duration # Use configured minimum
|
||||
return
|
||||
|
||||
try:
|
||||
# Get display width (assume full width of display)
|
||||
display_width = getattr(self.display_manager, 'matrix', None)
|
||||
if display_width:
|
||||
display_width = display_width.width
|
||||
else:
|
||||
display_width = 128 # Default to 128 if not available
|
||||
|
||||
# Calculate total scroll distance needed
|
||||
# Text needs to scroll from right edge to completely off left edge
|
||||
total_scroll_distance = display_width + self.total_scroll_width
|
||||
|
||||
# Calculate time based on scroll speed and delay
|
||||
# scroll_speed = pixels per frame, scroll_delay = seconds per frame
|
||||
frames_needed = total_scroll_distance / self.scroll_speed
|
||||
total_time = frames_needed * self.scroll_delay
|
||||
|
||||
# Add buffer time for smooth cycling (configurable %)
|
||||
buffer_time = total_time * self.duration_buffer
|
||||
calculated_duration = int(total_time + buffer_time)
|
||||
|
||||
# Apply configured min/max limits
|
||||
if calculated_duration < self.min_duration:
|
||||
self.dynamic_duration = self.min_duration
|
||||
logger.debug(f"Duration capped to minimum: {self.min_duration}s")
|
||||
elif calculated_duration > self.max_duration:
|
||||
self.dynamic_duration = self.max_duration
|
||||
logger.debug(f"Duration capped to maximum: {self.max_duration}s")
|
||||
else:
|
||||
self.dynamic_duration = calculated_duration
|
||||
|
||||
logger.debug(f"Odds ticker dynamic duration calculation:")
|
||||
logger.debug(f" Display width: {display_width}px")
|
||||
logger.debug(f" Text width: {self.total_scroll_width}px")
|
||||
logger.debug(f" Total scroll distance: {total_scroll_distance}px")
|
||||
logger.debug(f" Frames needed: {frames_needed:.1f}")
|
||||
logger.debug(f" Base time: {total_time:.2f}s")
|
||||
logger.debug(f" Buffer time: {buffer_time:.2f}s ({self.duration_buffer*100}%)")
|
||||
logger.debug(f" Calculated duration: {calculated_duration}s")
|
||||
logger.debug(f" Final duration: {self.dynamic_duration}s")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error calculating dynamic duration: {e}")
|
||||
self.dynamic_duration = self.min_duration # Use configured minimum as fallback
|
||||
|
||||
def get_dynamic_duration(self) -> int:
|
||||
"""Get the calculated dynamic duration for display"""
|
||||
return self.dynamic_duration
|
||||
|
||||
def update(self):
|
||||
"""Update odds ticker data."""
|
||||
logger.debug("Entering update method")
|
||||
|
||||
Reference in New Issue
Block a user