firmware-base/docs-c/components/StatusLight.md
2025-06-04 13:45:12 +02:00

3.4 KiB

title description keywords
StatusLight - LED Status Indicator Component A component for controlling a status LED with simple on/off and blinking capabilities
ESP32
status LED
indicator
modbus
feedback

StatusLight

Path: src/StatusLight.h

Revision History: Initial documentation

StatusLight is a component for controlling a status LED, providing simple on/off and blinking capabilities. It supports Modbus integration for remote monitoring and control of the status indicator.

REQUIREMENTS

  • Hardware:
    • Digital GPIO pin for controlling an LED
  • Software:
    • Configuration for pin assignment in config.h
    • Modbus address configuration in config-modbus.h

FEATURES

  • Steady on/off LED control
  • Blinking functionality with configurable interval
  • Modbus integration for remote monitoring and control
  • Support for multiple instances with different Modbus addresses
  • Component state tracking

DEPENDENCIES

graph TD
    StatusLight --> Component
    StatusLight --> Bridge
    StatusLight --> Arduino
    StatusLight --> ArduinoLog
    StatusLight --> macros
    StatusLight --> xmath
    StatusLight --> enums
    StatusLight --> config
    StatusLight --> configmodbus
    StatusLight --> ModbusTCP

BEHAVIOUR

stateDiagram-v2
    [*] --> OFF
    OFF --> ON: set(1)
    ON --> OFF: set(0)
    OFF --> BLINK: set(0,1)
    ON --> BLINK: set(1,1)
    BLINK --> OFF: set(0,0)
    BLINK --> ON: set(1,0)

TODOS

PERFORMANCE

  • Consider using hardware PWM for smoother blinking effects
  • Review blinking implementation for efficiency (currently using polling in loop)

SECURITY

  • Add validation for input parameters in set() method
  • Consider authentication for Modbus write operations

COMPLIANCE

  • Ensure blinking rates are appropriate for industrial environments
  • Comply with industrial standards for visual indicators

RECOMMENDATIONS

  • Use hardware with appropriate LED drivers for high-brightness applications
  • Consider adding additional blink patterns for varied status indications
  • Add support for RGB LEDs for multi-state visualization

EXAMPLE

Below is an example of how to initialize and use the StatusLight component:

#ifdef PIN_STATUS_LIGHT
  statusLight = new StatusLight(
      this,               // owner
      PIN_STATUS_LIGHT,   // pin
      COMPONENT_KEY_FEEDBACK_0,  // id
      MB_MONITORING_STATUS_FEEDBACK_0  // modbusAddress
  );
  if (statusLight)
  {
    components.push_back(statusLight);
    Log.infoln(F("StatusLight initialized. Pin:%d, ID:%d, MB:%d"),
               PIN_STATUS_LIGHT, COMPONENT_KEY_FEEDBACK_0, 
               MB_MONITORING_STATUS_FEEDBACK_0);
              
    // Example usage
    statusLight->on();  // Turn the LED on
    // statusLight->off(); // Turn the LED off
    // statusLight->setBlink(true); // Make the LED blink
  }
  else
  {
    Log.errorln(F("StatusLight initialization failed."));
  }
#endif

References