3.3 KiB
3.3 KiB
| title | description | keywords | ||||||
|---|---|---|---|---|---|---|---|---|
| StatusLight Component | A component for controlling and monitoring status lights with blinking capability |
|
StatusLight
Path: 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 - Base class for all components
- Bridge - For serial command interface
- ModbusTCP - For Modbus network integration
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.
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:
#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}