7.3 KiB
FastLED Python Code Investigation
Overview
This document summarizes the investigation of existing Python code in the FastLED project, particularly focusing on Playwright integration and web scraping capabilities for the FastLED online tool.
Location: All scripts are located in the ci/ci/scrapers/ directory, organized within the CI infrastructure alongside the existing testing infrastructure, including the original Playwright implementation in ci/wasm_test.py.
Existing Python Infrastructure
Dependencies (pyproject.toml)
The project already includes comprehensive dependencies for development and testing:
- Playwright:
playwright- for browser automation - Testing:
pytest,pytest-xdistfor parallel testing - FastLED:
fastled>=1.2.26- the FastLED Python package - FastLED WASM:
fastled-wasm- WebAssembly support - HTTP Client:
httpx- for HTTP requests - Build Tools:
uv,ziglang,ninja,cmake - Code Quality:
ruff,mypy,pyright,clang-format,isort,black
Existing Playwright Implementation (ci/wasm_test.py)
The project already has a sophisticated Playwright setup that:
-
Automatic Browser Installation:
def install_playwright_browsers(): os.system(f"{sys.executable} -m playwright install chromium") -
FastLED WASM Testing:
- Starts an HTTP server for WASM examples
- Tests browser automation with the FastLED.js library
- Monitors
FastLED_onFramecallback execution - Validates WebGL/WASM functionality
-
Error Handling:
- Console log monitoring for errors
- Timeout handling for page loads
- Proper server cleanup
MCP Server Integration (mcp_server.py)
The project includes a comprehensive MCP (Model Context Protocol) server with tools for:
- Running tests with various options
- Compiling examples for different platforms
- Code fingerprinting and change detection
- Linting and formatting
- Project information and status
FestivalStick Example Analysis
Core Functionality
The FestivalStick example (examples/FestivalStick/) is a sophisticated LED pattern demo featuring:
-
Corkscrew LED Mapping:
- 19.25 turns, 288 LEDs
- Maps 2D patterns to spiral LED positions
- Uses
fl::Corkscrewclass for geometric calculations
-
UI Controls:
- Speed, position, brightness controls
- Noise pattern generation with customizable parameters
- Color palette selection (Party, Heat, Ocean, Forest, Rainbow)
- Rendering mode options (Noise, Position, Mixed)
- Color boost with saturation/luminance functions
-
Advanced Features:
- Multi-sampling for accurate LED positioning
- Real-time noise generation with cylindrical mapping
- Auto-advance mode with manual position override
- ScreenMap integration for web visualization
Key Components
// Corkscrew configuration
#define NUM_LEDS 288
#define CORKSCREW_TURNS 19.25
// Runtime corkscrew with flexible configuration
Corkscrew::Input corkscrewInput(CORKSCREW_TURNS, NUM_LEDS, 0);
Corkscrew corkscrew(corkscrewInput);
// Frame buffer for 2D pattern drawing
fl::Grid<CRGB> frameBuffer;
// ScreenMap for web interface visualization
fl::ScreenMap corkscrewScreenMap = corkscrew.toScreenMap(0.2f);
Web Scraping Script Implementation
Script Features (scrape_festival_stick.py)
-
Robust Web Navigation:
- Navigates to https://fastled.onrender.com/docs
- Handles dynamic content loading
- Searches for multiple possible interface elements
-
Smart Element Detection:
- Looks for example selection dropdowns
- Detects file upload capabilities
- Finds canvas/visualization elements
- Searches for FestivalStick-specific content
-
Screenshot Capabilities:
- Full page screenshots with timestamps
- Focused canvas screenshots when available
- Error screenshots for debugging
- Multiple resolution support (1920x1080 default)
-
File Upload Attempt:
- Automatically tries to upload
FestivalStick.ino - Handles missing file scenarios gracefully
- Waits for upload processing
- Automatically tries to upload
Script Workflow
- Install Playwright browsers automatically
- Launch visible browser with slow motion for debugging
- Navigate to online FastLED tool
- Search for example/upload functionality
- Attempt to load FestivalStick example
- Capture screenshots of the visualization
- Save timestamped results to
screenshots/directory
Project Testing Infrastructure
Unit Tests
- Location:
tests/directory - Command:
bash test(per user rules) - Comprehensive C++ unit tests for all components
- Platform compilation tests
- Code quality checks
Example Compilation
- Multi-platform support:
uno,esp32,teensy, etc. - Command:
./compile <platform> --examples <example_name> - Batch compilation for multiple platforms
- Interactive and automated modes
Key Findings
-
Comprehensive Infrastructure: The FastLED project already has extensive Python tooling with Playwright, testing, and web automation capabilities.
-
Advanced LED Visualization: The FestivalStick example represents sophisticated LED pattern generation with real-time parameter control and web visualization.
-
Web Integration Ready: The existing WASM testing infrastructure provides a solid foundation for web-based LED visualization and interaction.
-
Documentation Gap: While the code is well-implemented, there could be more comprehensive documentation of the web tooling capabilities.
Recommendations
-
Extend Web Scraping: The created script could be enhanced to:
- Test multiple examples automatically
- Capture video recordings of animations
- Perform parameter sweeps for different configurations
-
Integration Testing: Consider adding the web scraping script to the CI/CD pipeline for automated web interface testing.
-
User Documentation: Create user guides for the online FastLED tool and example usage.
Results
✅ Successfully captured screenshot: ci/ci/scrapers/screenshots/festival_stick_20250620_224055.png (82KB)
The script successfully:
- Navigated to https://fastled.onrender.com/docs
- Detected and interacted with the FastLED web interface
- Captured a full-page screenshot of the FestivalStick example visualization
- Saved the result with timestamp for easy identification
Files Created/Modified
ci/ci/scrapers/scrape_festival_stick.py- Main web scraping script with Playwright automationci/ci/scrapers/run_fastled_scraper.py- Utility script for easy execution with different configurationsci/ci/scrapers/screenshots/- Directory containing captured imagesci/ci/scrapers/screenshots/festival_stick_20250620_224055.png- Successfully captured screenshot (82KB)ci/ci/scrapers/fastled_python_investigation.md- This documentation file
Usage Examples
# Run the scraper directly from project root
uv run ci/ci/scrapers/scrape_festival_stick.py
# Use the utility script with options
uv run ci/ci/scrapers/run_fastled_scraper.py --example FestivalStick --headless --timeout 60
# Make scripts executable and run from project root
chmod +x ci/ci/scrapers/scrape_festival_stick.py ci/ci/scrapers/run_fastled_scraper.py
./ci/ci/scrapers/scrape_festival_stick.py
./ci/ci/scrapers/run_fastled_scraper.py --help
# Or run from within the scrapers directory
cd ci/ci/scrapers
uv run scrape_festival_stick.py
uv run run_fastled_scraper.py --help