mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-05-19 19:43:32 +00:00
Reduce max_steps from 0.1s to 0.04s of catch-up time (from 5 to 2 steps at 50 FPS). When the system lags, the previous catch-up logic allowed jumping up to 5 pixels at once, causing visible jitter. Limiting to 2 steps provides smoother scrolling while still allowing for minor timing corrections. Co-authored-by: Chuck <chuck@example.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Common Utilities
This directory contains reusable utilities and helpers for LEDMatrix plugins and core modules.
Error Handling (error_handler.py)
Common error handling patterns and utilities:
handle_file_operation()- Handle file I/O with consistent error handlinghandle_json_operation()- Handle JSON operations with error handlingsafe_execute()- Safely execute operations with error handlingretry_on_failure()- Decorator for retrying failed operationslog_and_continue()- Log non-critical errors and continuelog_and_raise()- Log errors and raise exceptions
Example Usage
from src.common.error_handler import handle_json_operation, safe_execute
# Handle JSON loading
config = handle_json_operation(
lambda: json.load(open('config.json')),
"Failed to load config",
logger,
default={}
)
# Safe execution with error handling
result = safe_execute(
lambda: risky_operation(),
"Operation failed",
logger,
default=None
)
API Helpers (api_helper.py)
Utilities for making HTTP requests and handling API responses.
Configuration Helpers (config_helper.py)
Utilities for loading, saving, and validating configuration files.
Display Helpers (display_helper.py)
Utilities for rendering content to the LED matrix display.
Game Helpers (game_helper.py)
Utilities for processing game data and team information.
Logo Helpers (logo_helper.py)
Utilities for loading and managing team logos.
Text Helpers (text_helper.py)
Utilities for text processing and formatting.
Scroll Helpers (scroll_helper.py)
Utilities for scrolling text on the display.
General Utilities (utils.py)
General-purpose utility functions:
- Team abbreviation normalization
- Time formatting
- Boolean parsing
- Logger creation (deprecated - use
src.logging_config.get_logger())
Best Practices
- Use centralized logging: Import from
src.logging_configinstead of creating loggers directly - Use error handlers: Use
error_handlerutilities for consistent error handling - Reuse utilities: Check existing utilities before creating new ones
- Document additions: Add documentation when adding new utilities