docs(plugin-api): fix extra_small_font size, cache metric key and scroll pacing example

- PLUGIN_API_REFERENCE: extra_small_font loads at 7, not 6 (crisp_size
  snaps it, src/display_manager.py); get_cache_metrics() returns
  cache_hit_rate, not hit_rate (src/cache/cache_metrics.py).
- ADVANCED_PLUGIN_DEVELOPMENT: the basic scrolling example slept in a loop
  and never passed frame_hold; use ScrollHelper + scroll_config.configure()
  and set_scrolling_state(True, frame_hold=...) as PLUGIN_API_REFERENCE does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chuck
2026-09-22 16:18:30 -04:00
co-authored by Claude Opus 5.5
parent 4eaf80efc8
commit 8dad0fd41c
2 changed files with 48 additions and 26 deletions
+45 -23
View File
@@ -97,31 +97,53 @@ For plugins that scroll content (tickers, news feeds, etc.), use scrolling state
### Basic Scrolling Implementation ### Basic Scrolling Implementation
Scroll with `ScrollHelper`, configured by `src.common.scroll_config`, and
render one frame per `display()` call. Don't pace the scroll with
`time.sleep()`: `update_display()` blocks on the panel's
vsync, which is what paces a scroll. Pass the `frame_hold` that
`scroll_config.configure()` returned to `set_scrolling_state()`, or the
scroll runs faster than the configured speed (see
`set_scrolling_state()` in [PLUGIN_API_REFERENCE.md](PLUGIN_API_REFERENCE.md)).
```python ```python
from PIL import Image, ImageDraw
from src.common import scroll_config
from src.common.scroll_helper import ScrollHelper
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.scroll_helper = ScrollHelper(
self.display_manager.width, self.display_manager.height, self.logger)
self.scroll_settings = scroll_config.configure(
self.scroll_helper,
plugin_config=self.config,
global_config=self.global_config,
display_manager=self.display_manager,
plugin_logger=self.logger,
)
def _build_scroll_image(self, text):
font = self.display_manager.regular_font
width = self.display_manager.get_text_width(text, font)
img = Image.new("RGB", (width, self.display_manager.height))
ImageDraw.Draw(img).text((0, 0), text, font=font, fill=(255, 255, 255))
self.scroll_helper.set_scrolling_image(img)
def display(self, force_clear=False): def display(self, force_clear=False):
if force_clear: if force_clear or self.scroll_helper.cached_image is None:
self.display_manager.clear() self._build_scroll_image(
"This is a long scrolling message that needs to scroll across the display...")
# Mark as scrolling
self.display_manager.set_scrolling_state(True) # Mark as scrolling (calling it every frame is fine)
self.display_manager.set_scrolling_state(
try: True, frame_hold=self.scroll_settings.frame_hold)
# Scroll content self.scroll_helper.update_scroll_position()
text = "This is a long scrolling message that needs to scroll across the display..." self.display_manager.image = self.scroll_helper.get_visible_portion()
text_width = self.display_manager.get_text_width(text, self.display_manager.regular_font) self.display_manager.update_display()
display_width = self.display_manager.width
if self.scroll_helper.is_scroll_complete():
# Scroll from right to left # Mark as not scrolling when done
for x in range(display_width, -text_width, -2):
self.display_manager.clear()
self.display_manager.draw_text(text, x=x, y=16, color=(255, 255, 255))
self.display_manager.update_display()
time.sleep(0.05)
# Update scroll activity timestamp
self.display_manager.set_scrolling_state(True)
finally:
# Always mark as not scrolling when done
self.display_manager.set_scrolling_state(False) self.display_manager.set_scrolling_state(False)
``` ```
+3 -3
View File
@@ -620,7 +620,7 @@ The Display Manager provides several pre-loaded fonts:
display_manager.regular_font # Press Start 2P, size 8 display_manager.regular_font # Press Start 2P, size 8
display_manager.small_font # Press Start 2P, size 8 display_manager.small_font # Press Start 2P, size 8
display_manager.calendar_font # 5x7 BDF font display_manager.calendar_font # 5x7 BDF font
display_manager.extra_small_font # 4x6 TTF font, size 6 display_manager.extra_small_font # 4x6 TTF font, size 7 (6 snapped to its pixel grid)
display_manager.bdf_5x7_font # Alias for calendar_font display_manager.bdf_5x7_font # Alias for calendar_font
``` ```
@@ -854,12 +854,12 @@ for file_info in files:
Get cache performance metrics. Get cache performance metrics.
**Returns**: Dictionary with cache statistics (hits, misses, hit rate, etc.) **Returns**: Dictionary with cache statistics (`total_requests`, `cache_hit_rate`, `background_hit_rate`, `api_calls_saved`, `average_fetch_time`, etc.)
**Example**: **Example**:
```python ```python
metrics = self.cache_manager.get_cache_metrics() metrics = self.cache_manager.get_cache_metrics()
self.logger.info(f"Cache hit rate: {metrics['hit_rate']:.2%}") self.logger.info(f"Cache hit rate: {metrics['cache_hit_rate']:.2%}")
``` ```
#### `get_memory_cache_stats() -> Dict[str, Any]` #### `get_memory_cache_stats() -> Dict[str, Any]`