--- title: "StatusLight Component" description: "A component for controlling and monitoring status lights with blinking capability" keywords: ["status", "light", "LED", "feedback", "modbus", "blinking"] --- # StatusLight **Path**: [`src/components/StatusLight.h`](../src/components/StatusLight.h) **Revision History**: Initial documentation The StatusLight component provides functionality to control and monitor status indicators such as LEDs. It supports three states: OFF, ON, and BLINKING, with configurable blinking intervals. It integrates with the Modbus system for remote monitoring and control. ## Requirements - Digital output pin for connecting the status light/LED - STATUS_BLINK_INTERVAL defined in configuration (default: 800ms) - Optional Modbus address for network control ## Features - Three operation modes: OFF, ON, and BLINKING - Configurable blinking intervals - Modbus integration for remote monitoring and control - Serial bridge interface for local control - Automatic pin state management during state transitions ## Dependencies - [Component](../src/Component.h) - Base class for all components - [Bridge](../src/Bridge.h) - For serial command interface - [ModbusTCP](../src/modbus/ModbusTCP.h) - For Modbus network integration ```mermaid graph TD StatusLight --> Component StatusLight --> Bridge StatusLight --> ModbusTCP ``` ## Behaviour The StatusLight component manages a digital output pin with three possible states: OFF, ON, and BLINKING. When in BLINKING state, it toggles the output at the configured interval. ```mermaid stateDiagram-v2 [*] --> OFF OFF --> ON: set(1) ON --> OFF: set(0) OFF --> BLINK: status_blink(true) ON --> BLINK: status_blink(true) BLINK --> OFF: status_blink(false) + state==OFF BLINK --> ON: status_blink(false) + state==ON ``` ## TODOs ### Performance - Consider using non-blocking timers for more precise blinking intervals - Evaluate performance impact of continuous polling in the loop method ### Security - Validate input parameters in public methods to prevent unexpected behavior - Consider adding authentication for Modbus write operations ### Compliance - Ensure proper error handling for hardware failures - Add support for different blinking patterns for various status indications ### Recommendations - Use consistent addressing scheme when multiple status lights are used - Consider using PWM for dimming capability in future versions - When using with critical systems, consider adding a watchdog timer ## Example The following example shows how to initialize and use a StatusLight component: ```cpp #ifdef STATUS_WARNING_PIN StatusLight* warningLight = new StatusLight( this, // owner STATUS_WARNING_PIN, // pin COMPONENT_KEY_FEEDBACK_0, // id MB_MONITORING_STATUS_FEEDBACK_0 // modbusAddress ); if (warningLight) { components.push_back(warningLight); Log.infoln(F("Warning Status Light initialized. Pin:%d"), STATUS_WARNING_PIN); } else { Log.errorln(F("Warning Status Light initialization failed.")); } #endif // Later in the code, control the status light: warningLight->on(); // Turn on the light warningLight->off(); // Turn off the light warningLight->setBlink(true); // Make it blink ``` ### References ${DOXYGEN_PLACEHOLDER} ${VENDOR_PLACEHOLDER}