mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 05:42:59 +00:00
added dynamic display durations to scrolling managers
This commit is contained in:
@@ -41,6 +41,14 @@ class StockNewsManager:
|
||||
self.max_headlines_per_symbol = self.stock_news_config.get('max_headlines_per_symbol', 1)
|
||||
self.headlines_per_rotation = self.stock_news_config.get('headlines_per_rotation', 2)
|
||||
|
||||
# Dynamic duration settings
|
||||
self.dynamic_duration_enabled = self.stock_news_config.get('dynamic_duration', True)
|
||||
self.min_duration = self.stock_news_config.get('min_duration', 30)
|
||||
self.max_duration = self.stock_news_config.get('max_duration', 300)
|
||||
self.duration_buffer = self.stock_news_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
|
||||
|
||||
# Log the actual values being used
|
||||
logger.info(f"Scroll settings - Speed: {self.scroll_speed} pixels/frame, Delay: {self.scroll_delay*1000:.2f}ms")
|
||||
logger.info(f"Headline settings - Max per symbol: {self.max_headlines_per_symbol}, Per rotation: {self.headlines_per_rotation}")
|
||||
@@ -362,6 +370,10 @@ class StockNewsManager:
|
||||
self.scroll_position = 0
|
||||
self.background_image = None # Clear the background image
|
||||
|
||||
# Calculate total scroll width for dynamic duration
|
||||
self.total_scroll_width = self.cached_text_image.width
|
||||
self.calculate_dynamic_duration()
|
||||
|
||||
# Move to next rotation for next time
|
||||
self.current_rotation_index += 1
|
||||
else:
|
||||
@@ -396,6 +408,63 @@ class StockNewsManager:
|
||||
self.cached_text_image = None
|
||||
return True
|
||||
|
||||
def calculate_dynamic_duration(self):
|
||||
"""Calculate the exact time needed to display all news headlines"""
|
||||
# If dynamic duration is disabled, use fixed duration from config
|
||||
if not self.dynamic_duration_enabled:
|
||||
self.dynamic_duration = self.stock_news_config.get('fixed_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, '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"Stock news 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
|
||||
|
||||
# Calculate the visible portion
|
||||
# Handle wrap-around drawing
|
||||
visible_end = self.scroll_position + width
|
||||
|
||||
Reference in New Issue
Block a user