mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 13:23:00 +00:00
Stocks (#2)
* Opening Bell Introducing the Stock Ticker Feature * Update stock_manager.py Assume folder exists * Update stock_manager.py removing logos to focus on function for now * Update stock_manager.py parse yahoo scripts * Update stock_manager.py stock query update * Update stock_manager.py slow down stock display * Update display_controller.py adjust screen flow * Update stock_manager.py shipping features * Update stock_manager.py stock refresh in the background * Customize Display timings customize display timings * Update stock_manager.py stock font size change * Sizing and Spacing CHanged font sizing on chart and clock spacing * Update clock.py Date format changes * Update stock_manager.py actually read stocks from config file * Update stock_manager.py add config manager * readme update readme update and formatting for better flow * Update .gitignore rename reference folder * Update config.json changed default stocks to test update implementation * Stock News Stock news Ticker * Update config.json increase scroll speed * Scroll Performance Tuning news scrolling performance * updating scroll direction orienting scroll direction * News tuning removed test files and increased scroll speed * Create test_news_manager.py need a test script to call upon * Update test_news_manager.py test script tuning * troubleshooting test script * Update test_news_manager.py * Update config.json scroll speed increases * Update config.json scroll tuning * Update config.json speeding up * Update config.json still making text faster * Update config.json Trying to tune scrolling * Update config.json testing crazy parameters * Update test_news_manager.py remove sleep delay * scroll tuning scroll tuning * scroll logging and debugging FPS counter and debug messages * Update config.json matrix speed tuning * Update news_manager.py News separator * Update news_manager.py separator character change * Stock News manager Rename rename stock news ticker to enable other news in the future * Update display_controller.py load config update * Update stock_manager.py remove redundant import * Stock news settings Stock news has more granular control * Stock news joins the lineup Stock News added to the display controller and drawing display instead of image * Optimize scrolling text performance for news ticker * Adjust matrix settings to reduce artifacting while maintaining performance * changed float to integer * Fix news ticker performance with simplified scrolling mechanism * Fix stock news scrolling in test environment: - Optimize display manager settings for smooth scrolling - Add proper display initialization and cleanup in test script - Implement timing control to prevent display buffer overflow - Ensure consistent 1ms delay between updates for smooth scrolling * Optimize stock news scrolling for better performance: - Use pre-rendered text image for efficient scrolling - Implement cropping and pasting for smoother animation - Remove unnecessary display operations and delays * Optimize stock news display performance: - Cache text image to reduce rendering overhead - Improve frame creation and update logic - Optimize text wrapping for smoother scrolling - Remove unnecessary display clears * Optimize stock news display in controller: - Remove global sleep delay - Allow news display to run at full speed - Keep slower update rates for other displays --------- Signed-off-by: Chuck <33324927+ChuckBuilds@users.noreply.github.com>
This commit is contained in:
@@ -26,6 +26,9 @@ class StockNewsManager:
|
||||
self.news_data = {}
|
||||
self.current_news_group = 0 # Track which group of headlines we're showing
|
||||
self.scroll_position = 0
|
||||
self.cached_text_image = None # Cache for the text image
|
||||
self.cached_text = None # Cache for the text string
|
||||
|
||||
|
||||
# Get scroll settings from config with faster defaults
|
||||
self.scroll_speed = self.stock_news_config.get('scroll_speed', 1)
|
||||
@@ -205,39 +208,60 @@ class StockNewsManager:
|
||||
separator = " - " # Visual separator between news items
|
||||
news_text = separator.join(news_texts)
|
||||
|
||||
# Clear the display
|
||||
self.display_manager.clear()
|
||||
# Only create new text image if the text has changed
|
||||
if news_text != self.cached_text:
|
||||
self.cached_text = news_text
|
||||
self.cached_text_image = self._create_text_image(news_text)
|
||||
self.scroll_position = 0 # Reset scroll position for new text
|
||||
|
||||
# Calculate text width for scrolling
|
||||
bbox = self.display_manager.draw.textbbox((0, 0), news_text, font=self.display_manager.small_font)
|
||||
text_width = bbox[2] - bbox[0]
|
||||
|
||||
# Calculate scroll position
|
||||
if not self.cached_text_image:
|
||||
return
|
||||
|
||||
text_width = self.cached_text_image.width
|
||||
text_height = self.cached_text_image.height
|
||||
|
||||
display_width = self.display_manager.matrix.width
|
||||
total_width = text_width + display_width
|
||||
|
||||
# Update scroll position
|
||||
self.scroll_position = (self.scroll_position + self.scroll_speed) % total_width
|
||||
|
||||
# Draw the text at the current scroll position
|
||||
self.display_manager.draw_text(
|
||||
news_text,
|
||||
x=display_width - self.scroll_position,
|
||||
y=None, # Center vertically
|
||||
color=(255, 255, 255),
|
||||
small_font=True
|
||||
)
|
||||
|
||||
# Update the display
|
||||
self.display_manager.update_display()
|
||||
|
||||
# Calculate the visible portion of the text
|
||||
visible_width = min(display_width, text_width - self.scroll_position)
|
||||
if visible_width > 0:
|
||||
# Create a new blank image for this frame
|
||||
frame_image = Image.new('RGB', (display_width, text_height), (0, 0, 0))
|
||||
|
||||
# Crop and paste in one operation
|
||||
if self.scroll_position + visible_width <= text_width:
|
||||
# Normal case - text is still scrolling in
|
||||
visible_portion = self.cached_text_image.crop((
|
||||
self.scroll_position, 0,
|
||||
self.scroll_position + visible_width, text_height
|
||||
))
|
||||
frame_image.paste(visible_portion, (0, 0))
|
||||
else:
|
||||
# Wrapping case - text is wrapping around
|
||||
first_part_width = text_width - self.scroll_position
|
||||
first_part = self.cached_text_image.crop((
|
||||
self.scroll_position, 0,
|
||||
text_width, text_height
|
||||
))
|
||||
second_part = self.cached_text_image.crop((
|
||||
0, 0,
|
||||
visible_width - first_part_width, text_height
|
||||
))
|
||||
frame_image.paste(first_part, (0, 0))
|
||||
frame_image.paste(second_part, (first_part_width, 0))
|
||||
|
||||
# Update the display with the new frame
|
||||
self.display_manager.image = frame_image
|
||||
self.display_manager.update_display()
|
||||
|
||||
# If we've completed a full scroll, move to the next group
|
||||
if self.scroll_position == 0:
|
||||
self.current_news_group = (self.current_news_group + 1) % ((total_headlines + headlines_per_rotation - 1) // headlines_per_rotation)
|
||||
|
||||
# Small delay to control scroll speed
|
||||
time.sleep(self.scroll_delay)
|
||||
|
||||
# Log frame rate
|
||||
self._log_frame_rate()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user