Page 1 of 1

[Share]Modular design of lighting effects.

Posted: 2023年 Dec 26日 16:53
by jm.yao

I. Purpose
To guide developers with the design principles of modular lighting effects, simplifying the control method of lighting effects.

II. Requirements

  1. Use modular design, to enhance code reusability.
  2. Achieve configurable lighting effect functions.
  3. Support simultaneous control of multiple LED lights and RGB lights.
  4. Support switching of lighting effects such as on, off, and flashing.
  5. Support priority control for lighting effect transitions.

III. Overall Design Process
Image
After an application initializes an LED, it will receive a control handle returned by the component. This handle allows for manual control of the LED's on, off, and flashing states through an external interface. Internally, the component can also automatically control the lighting effects according to the run parameters configured during initialization. Higher-priority lighting effects will override those of lower priority, and once the display of the higher-priority effects is complete, the display of the lower-priority effects can be resumed.

IV. Functional Design
Image
The logic behind LED_ON and LED_OFF is similar; the following explanation uses LED_OFF as an example:

  1. When the duration for LED_OFF is set to a value other than 0xFFFF and is greater than 0, the LED turns off and will remain off until the set duration expires, after which the LED turns back on.
  2. When the duration for LED_OFF is set to 0xFFFF, the LED turns off and maintains its current light effect priority (it can be overridden by a higher priority, but will revert to the current light effect once the higher priority light effect has finished).
  3. When the duration for LED_OFF is set to 0, the LED turns off and the current light effect priority is terminated (it can be overridden by a higher priority, but it will not revert to the current light effect once the higher priority light effect has finished).

Image
The logic for LED_FLASH_ON and LED_FLASH_OFF is similar; here, LED_FLASH_OFF is taken as an example:

  1. When the flashing begins, the LED adapts according to its current state: if the LED is currently on, it will first turn off; if the LED is currently off, it will first turn on.
  2. If the duration for LED_FLASH_OFF is set to something other than 0xFFFF and is greater than 0, the LED will flash for the set duration, after which the LED will turn off.
  3. If the duration for LED_FLASH_OFF is set to 0xFFFF, the LED will continue to flash indefinitely, maintaining its current priority of light effects (it can be overridden by a higher priority, but will revert to the current effect once the higher priority effect concludes).
  4. If the duration for LED_FLASH_OFF is set to 0, the LED will flash and terminate the current light effect priority (it can be overridden by a higher priority, but it will not revert to the current effect after the higher priority effect is over).

V. Interface Design

  1. Light Effect Function Initialization
    tuya_gw_led_init
  2. Create LED Control Handle
    tuya_gw_create_led_handle
  3. External Light Effect Control Interface
    tuya_gw_set_led_light_handle
    tuya_gw_set_led_light_hsv_handle

VI. Application Examples
Image
The initialization configuration parameters are defined in sequence as follows:
event: Light effect event type, see LED_EVENT_TYPE_E
prio: Priority type, see LED_PRIO_E
cb_type: Callback method, the user can choose to use the component's original implementation or a custom implementation
type: Light effect display status: on, off, flashing
bright: Nightlight brightness, for RGB lights
rgb: Nightlight color, for RGB lights
flash_cycle: The toggle time for flashing, in milliseconds
flh_sum_time: The duration of flashing, in milliseconds (0xFFFF indicates always on, always off, or continuously flashing)
flh_time_type: Type of flashing duration (used when a low-priority light effect event resumes operation)

Image
The parameters set via the external control interface will override the lighting effect configuration initialized at startup.