# On-Demand Display - Quick Start Guide ## ๐ŸŽฏ What Is It? On-Demand Display lets users **manually trigger** specific plugins to show on the LED matrix - perfect for "Show Now" buttons in your web interface! > **2025 update:** The LEDMatrix web interface now ships with first-class on-demand controls. You can trigger plugins directly from the Plugin Management page or by calling the new `/api/v3/display/on-demand/*` endpoints described below. The legacy quick-start steps are still documented for bespoke integrations. ## โœ… Built-In Controls ### Web Interface (no-code) - Navigate to **Settings โ†’ Plugin Management**. - Each installed plugin now exposes a **Run On-Demand** button: - Choose the display mode (when a plugin exposes multiple views). - Optionally set a fixed duration (leave blank to use the plugin default or `0` to run until you stop it). - Pin the plugin so rotation stays paused. - The dashboard shows real-time status and lets you stop the session. **Shift+click** the stop button to stop the display service after clearing the plugin. - The status card refreshes automatically and indicates whether the display service is running. ### REST Endpoints All endpoints live under `/api/v3/display/on-demand`. | Endpoint | Method | Description | |----------|--------|-------------| | `/status` | GET | Returns the current on-demand state plus display service health. | | `/start` | POST | Requests a plugin/mode to run. Automatically starts the display service (unless `start_service: false`). | | `/stop` | POST | Clears on-demand mode. Include `{"stop_service": true}` to stop the systemd service. | Example `curl` calls: ```bash # Start the default mode for football-scoreboard for 45 seconds curl -X POST http://localhost:5000/api/v3/display/on-demand/start \ -H "Content-Type: application/json" \ -d '{ "plugin_id": "football-scoreboard", "duration": 45, "pinned": true }' # Start by mode name (plugin id inferred automatically) curl -X POST http://localhost:5000/api/v3/display/on-demand/start \ -H "Content-Type: application/json" \ -d '{ "mode": "football_live" }' # Stop on-demand and shut down the display service curl -X POST http://localhost:5000/api/v3/display/on-demand/stop \ -H "Content-Type: application/json" \ -d '{ "stop_service": true }' # Check current status curl http://localhost:5000/api/v3/display/on-demand/status | jq ``` **Notes** - The display controller will honour the pluginโ€™s configured `display_duration` when no duration is provided. - When you pass `duration: 0` (or omit it) and `pinned: true`, the plugin stays active until you issue `/stop`. - The service automatically resumes normal rotation after the on-demand session expires or is cleared. ## ๐Ÿš€ Quick Implementation (3 Steps) > The steps below describe a lightweight custom implementation that predates the built-in API. You generally no longer need this unless you are integrating with a separate control surface. ### Step 1: Add API Endpoint ```python # In web_interface/blueprints/api_v3.py @api_v3.route('/display/show', methods=['POST']) def show_on_demand(): data = request.json mode = data.get('mode') duration = data.get('duration', 30) # Default 30 seconds # Get display controller (implementation depends on your setup) controller = get_display_controller() success = controller.show_on_demand(mode, duration=duration) return jsonify({'success': success}) @api_v3.route('/display/clear', methods=['POST']) def clear_on_demand(): controller = get_display_controller() controller.clear_on_demand() return jsonify({'success': True}) ``` ### Step 2: Add UI Button ```html ``` ### Step 3: Done! ๐ŸŽ‰ Users can now click the button to show weather immediately! ## ๐Ÿ“‹ Complete Web UI Example ```html Display Control

โ›… Weather

๐Ÿ’ Hockey

๐ŸŽต Music

``` ## โšก Usage Patterns ### Pattern 1: Timed Preview ```javascript // Show for 30 seconds then return to rotation showPlugin('weather', 30); ``` ### Pattern 2: Pinned Display ```javascript // Stay on this plugin until manually cleared pinPlugin('hockey_live'); ``` ### Pattern 3: Quick Check ```javascript // Show for 10 seconds showPlugin('clock', 10); ``` ### Pattern 4: Indefinite Display ```javascript // Show until cleared (duration=0) fetch('/api/v3/display/show', { method: 'POST', body: JSON.stringify({ mode: 'weather', duration: 0 }) }); ``` ## ๐Ÿ“Š Priority Order ``` User clicks "Show Weather" button โ†“ 1. On-Demand (Highest) โ† Shows immediately 2. Live Priority โ† Overridden 3. Normal Rotation โ† Paused ``` On-demand has **highest priority** - it overrides everything! ## ๐ŸŽฎ Common Use Cases ### Quick Weather Check ```html ``` ### Monitor Live Game ```html ``` ### Test Plugin Configuration ```html ``` ### Emergency Message ```html ``` ## ๐Ÿ”ง Duration Options | Value | Behavior | Example | |-------|----------|---------| | `30` | Show for 30s then return | Quick preview | | `0` | Show until cleared | Extended viewing | | `null` | Use plugin's default | Let plugin decide | | `pinned: true` | Stay until unpinned | Monitor mode | ## โ“ FAQ ### Q: What happens when duration expires? **A:** Display automatically returns to normal rotation (or live priority if active). ### Q: Can I show multiple modes at once? **A:** No, only one mode at a time. Last request wins. ### Q: Does it override live games? **A:** Yes! On-demand has highest priority, even over live priority. ### Q: How do I go back to normal rotation? **A:** Either wait for duration to expire, or call `clearOnDemand()`. ### Q: What if the mode doesn't exist? **A:** API returns `success: false` and logs a warning. ## ๐Ÿ› Testing ### Test 1: Show for 30 seconds ```bash curl -X POST http://pi-ip:5001/api/v3/display/show \ -H "Content-Type: application/json" \ -d '{"mode": "weather", "duration": 30}' ``` ### Test 2: Pin mode ```bash curl -X POST http://pi-ip:5001/api/v3/display/show \ -H "Content-Type: application/json" \ -d '{"mode": "hockey_live", "pinned": true}' ``` ### Test 3: Clear on-demand ```bash curl -X POST http://pi-ip:5001/api/v3/display/clear ``` ### Test 4: Check status ```bash curl http://pi-ip:5001/api/v3/display/on-demand-info ``` ## ๐Ÿ“ Implementation Checklist - [ ] Add API endpoints to web interface - [ ] Add "Show Now" buttons to plugin cards - [ ] Add status bar showing current on-demand mode - [ ] Add "Clear" button when on-demand active - [ ] Add authentication to API endpoints - [ ] Test with multiple plugins - [ ] Test duration expiration - [ ] Test pinned mode ## ๐Ÿ“š Full Documentation See `ON_DEMAND_DISPLAY_API.md` for: - Complete API reference - Security best practices - Troubleshooting guide - Advanced examples ## ๐ŸŽฏ Key Points 1. **User-triggered** - Manual control from web UI 2. **Highest priority** - Overrides everything 3. **Auto-clear** - Returns to rotation after duration 4. **Pin mode** - Stay on mode until manually cleared 5. **Simple API** - Just 3 endpoints needed That's it! Your users can now control what shows on the display! ๐Ÿš€