Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
light_scheduler module

Basic light scheduler using WS2812 driver

WS2812 are small RGB leds controlled with a 1-wire protocol. This module is an example of controlling several leds with the color changing continuously. Implementation for ChibiOS using DMA.

Example for airframe file

Add to your firmware section: This example contains all possible configuration options, not all of them are mandatory!

<module name="light_scheduler">
b'<define name="WS2812_NB_LEDS" value="8" />\n '
b'<define name="LIGHT_SCHEDULER_MODE" value="0" />\n '
b'<define name="LIGHT_SCHEDULER_RED" value="255" />\n '
b'<define name="LIGHT_SCHEDULER_GREEN" value="255" />\n '
b'<define name="LIGHT_SCHEDULER_BLUE" value="255" />\n '
b'<define name="LIGHT_SCHEDULER_BRIGHTNESS" value="255" />\n '
b'<define name="LIGHT_SCHEDULER_COLOR" value="LIGHT_SCHEDULER_COLOR_GREEN" />\n '
b'<define name="LIGHT_SCHEDULER_ALERT" value="electrical.bat_low" />\n '
b'<define name="LIGHT_SCHEDULER_ALERT_HEADER" value="modules/energy/electrical.h" type="string" />\n '
b'<define name="LIGHT_SCHEDULER_ALERT_COLOR" value="LIGHT_SCHEDULER_COLOR_RED" />\n '
b'<define name="LIGHT_SCHEDULER_ALERT_SPARKLE" value="FALSE" />\n '
b'<configure name="WS2812_TIM" value="TIM1" />\n '
</module>

Module configuration options

Configure Options

  • name: WS2812_TIM value: TIM1
    Description: Select the timer used to control the LEDs

Define Options

  • name: WS2812_NB_LEDS value: 8
    Description: Number of leds
  • name: LIGHT_SCHEDULER_MODE value: 0
    Description: Startup mode: 0 rainbow, 1 fixed color, 2 off, 3 sparkle
  • name: LIGHT_SCHEDULER_RED value: 255
    Description: Startup red value of the fixed color (0-255)
  • name: LIGHT_SCHEDULER_GREEN value: 255
    Description: Startup green value of the fixed color (0-255)
  • name: LIGHT_SCHEDULER_BLUE value: 255
    Description: Startup blue value of the fixed color (0-255)
  • name: LIGHT_SCHEDULER_BRIGHTNESS value: 255
    Description: Startup brightness (0-255)
  • name: LIGHT_SCHEDULER_COLOR value: LIGHT_SCHEDULER_COLOR_GREEN
    Description: Startup color preset (LIGHT_SCHEDULER_COLOR_x), overrides RED/GREEN/BLUE
  • name: LIGHT_SCHEDULER_ALERT value: electrical.bat_low
    Description: Optional C condition: while true, all LEDs show the alert color in every mode
  • name: LIGHT_SCHEDULER_ALERT_HEADER value: modules/energy/electrical.h
    Description: Header to include for the alert condition
  • name: LIGHT_SCHEDULER_ALERT_COLOR value: LIGHT_SCHEDULER_COLOR_RED
    Description: Alert color preset
  • name: LIGHT_SCHEDULER_ALERT_SPARKLE value: FALSE
    Description: Show the sparkle effect (random bright colors) instead of the alert color

Module functions

Init Functions

These initialization functions are called once on startup.

Periodic Functions

These functions are called periodically at the specified frequency from the module periodic loop.

  • light_scheduler_periodic()
    • Frequency in Hz: 16
    • Autorun: LOCK
      Periodic function automatically starts after init and can't be stopped.

Files

Header Files

The following headers are automatically included in modules.h

Source Files

Raw light_scheduler.xml file:

<!DOCTYPE module SYSTEM "module.dtd">
<module name="light_scheduler" dir="light">
<doc>
<description>
Basic light scheduler using WS2812 driver
WS2812 are small RGB leds controlled with a 1-wire protocol.
This module is an example of controlling several leds with the color changing continuously.
Implementation for ChibiOS using DMA.
</description>
<configure name="WS2812_TIM" value="TIM1" description="Select the timer used to control the LEDs"/>
<define name="WS2812_NB_LEDS" value="8" description="Number of leds"/>
<define name="LIGHT_SCHEDULER_MODE" value="0" description="Startup mode: 0 rainbow, 1 fixed color, 2 off, 3 sparkle"/>
<define name="LIGHT_SCHEDULER_RED" value="255" description="Startup red value of the fixed color (0-255)"/>
<define name="LIGHT_SCHEDULER_GREEN" value="255" description="Startup green value of the fixed color (0-255)"/>
<define name="LIGHT_SCHEDULER_BLUE" value="255" description="Startup blue value of the fixed color (0-255)"/>
<define name="LIGHT_SCHEDULER_BRIGHTNESS" value="255" description="Startup brightness (0-255)"/>
<define name="LIGHT_SCHEDULER_COLOR" value="LIGHT_SCHEDULER_COLOR_GREEN" description="Startup color preset (LIGHT_SCHEDULER_COLOR_x), overrides RED/GREEN/BLUE"/>
<define name="LIGHT_SCHEDULER_ALERT" value="electrical.bat_low" description="Optional C condition: while true, all LEDs show the alert color in every mode"/>
<define name="LIGHT_SCHEDULER_ALERT_HEADER" value="modules/energy/electrical.h" type="string" description="Header to include for the alert condition"/>
<define name="LIGHT_SCHEDULER_ALERT_COLOR" value="LIGHT_SCHEDULER_COLOR_RED" description="Alert color preset"/>
<define name="LIGHT_SCHEDULER_ALERT_SPARKLE" value="FALSE" description="Show the sparkle effect (random bright colors) instead of the alert color"/>
</doc>
<settings>
<dl_settings>
<dl_settings name="Light">
<dl_setting var="light_scheduler_mode" min="0" max="3" step="1" values="Rainbow|Color|Off|Sparkle" shortname="mode" type="uint8_t"/>
<dl_setting var="light_scheduler_color" min="0" max="12" step="1" values="Custom|Red|Green|Blue|White|Yellow|Orange|Cyan|Magenta|Purple|Italy|Netherlands|France" shortname="color" type="uint8_t" module="light/light_scheduler" handler="set_color"/>
<dl_setting var="light_scheduler_red" min="0" max="255" step="1" shortname="red" type="uint8_t"/>
<dl_setting var="light_scheduler_green" min="0" max="255" step="1" shortname="green" type="uint8_t"/>
<dl_setting var="light_scheduler_blue" min="0" max="255" step="1" shortname="blue" type="uint8_t"/>
<dl_setting var="light_scheduler_brightness" min="0" max="255" step="1" shortname="brightness" type="uint8_t"/>
</dl_settings>
</dl_settings>
</settings>
<header>
<file name="light_scheduler.h"/>
</header>
<init fun="light_scheduler_init()"/>
<periodic fun="light_scheduler_periodic()" freq="16"/>
<makefile target="ap">
<configure name="WS2812_TIM" default="TIM1" case="upper"/>
<define name="STM32_PWM_USE_$(WS2812_TIM)" cond="ifeq ($(RTOS),chibios)"/>
<file name="light_scheduler.c"/>
<file_arch name="light_ws2812_arch.c"/>
<file_arch name="hal_stm32_dma.c" dir="mcu_periph" cond="ifeq ($(RTOS),chibios)"/>
<test>
<define name="LIGHT_SCHEDULER_ALERT" value="false"/>
</test>
</makefile>
</module>