mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 05:42:59 +00:00
scroll tuning
scroll tuning
This commit is contained in:
@@ -55,7 +55,7 @@
|
|||||||
"enabled": true,
|
"enabled": true,
|
||||||
"update_interval": 300,
|
"update_interval": 300,
|
||||||
"scroll_speed": 1,
|
"scroll_speed": 1,
|
||||||
"scroll_delay": 0.0005,
|
"scroll_delay": 0.001,
|
||||||
"max_headlines_per_symbol": 1
|
"max_headlines_per_symbol": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,9 +154,12 @@ class NewsManager:
|
|||||||
|
|
||||||
# Get the current news item to display
|
# Get the current news item to display
|
||||||
current_news = all_news[self.current_news_index]
|
current_news = all_news[self.current_news_index]
|
||||||
|
next_news = all_news[(self.current_news_index + 1) % len(all_news)]
|
||||||
|
|
||||||
# Format the news text
|
# Format the news text with spacing between items
|
||||||
news_text = f"{current_news['symbol']}: {current_news['title']}"
|
current_text = f"{current_news['symbol']}: {current_news['title']}"
|
||||||
|
next_text = f"{next_news['symbol']}: {next_news['title']}"
|
||||||
|
news_text = f"{current_text} {next_text}"
|
||||||
|
|
||||||
# Create a text image for efficient scrolling
|
# Create a text image for efficient scrolling
|
||||||
text_image = self._create_text_image(news_text)
|
text_image = self._create_text_image(news_text)
|
||||||
@@ -165,17 +168,11 @@ class NewsManager:
|
|||||||
# Calculate the visible portion of the text
|
# Calculate the visible portion of the text
|
||||||
visible_width = min(self.display_manager.matrix.width, text_width)
|
visible_width = min(self.display_manager.matrix.width, text_width)
|
||||||
|
|
||||||
# If this is the first time displaying this news item, clear the screen
|
|
||||||
if self.scroll_position == 0:
|
|
||||||
self.display_manager.clear()
|
|
||||||
self.display_manager.update_display()
|
|
||||||
|
|
||||||
# Create a new image for the current frame
|
# Create a new image for the current frame
|
||||||
frame_image = Image.new('RGB', (self.display_manager.matrix.width, self.display_manager.matrix.height), (0, 0, 0))
|
frame_image = Image.new('RGB', (self.display_manager.matrix.width, self.display_manager.matrix.height), (0, 0, 0))
|
||||||
|
|
||||||
# Calculate the source and destination regions for the visible portion
|
# Calculate the source and destination regions for the visible portion
|
||||||
# For left-to-right scrolling, we start from the left side of the text
|
src_x = self.scroll_position % text_width # Use modulo to wrap around smoothly
|
||||||
src_x = self.scroll_position
|
|
||||||
src_width = min(visible_width, text_width - src_x)
|
src_width = min(visible_width, text_width - src_x)
|
||||||
|
|
||||||
# Copy the visible portion of the text to the frame
|
# Copy the visible portion of the text to the frame
|
||||||
@@ -199,13 +196,12 @@ class NewsManager:
|
|||||||
# Update scroll position
|
# Update scroll position
|
||||||
self.scroll_position += self.scroll_speed
|
self.scroll_position += self.scroll_speed
|
||||||
|
|
||||||
# If we've scrolled past the end of the text, move to the next news item
|
# If we've scrolled past the current text, move to the next news item
|
||||||
if self.scroll_position > text_width + self.display_manager.matrix.width:
|
if self.scroll_position >= text_width:
|
||||||
self.scroll_position = 0
|
self.scroll_position = 0
|
||||||
self.current_news_index = (self.current_news_index + 1) % len(all_news)
|
self.current_news_index = (self.current_news_index + 1) % len(all_news)
|
||||||
|
|
||||||
# Add a small delay to control scroll speed
|
# Add a small delay to control scroll speed
|
||||||
time.sleep(self.scroll_delay)
|
time.sleep(self.scroll_delay)
|
||||||
|
|
||||||
# Return True if we've displayed all news items
|
return True
|
||||||
return self.current_news_index == 0 and self.scroll_position == 0
|
|
||||||
Reference in New Issue
Block a user