Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
light_scheduler.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Xavier Paris
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
32#include "generated/airframe.h"
33
35#ifdef LIGHT_SCHEDULER_ALERT_HEADER
36#include LIGHT_SCHEDULER_ALERT_HEADER
37#endif
38
39#ifndef LIGHT_SCHEDULER_MODE
40#define LIGHT_SCHEDULER_MODE LIGHT_SCHEDULER_MODE_RAINBOW
41#endif
42
43#ifndef LIGHT_SCHEDULER_RED
44#define LIGHT_SCHEDULER_RED 255
45#endif
46
47#ifndef LIGHT_SCHEDULER_GREEN
48#define LIGHT_SCHEDULER_GREEN 255
49#endif
50
51#ifndef LIGHT_SCHEDULER_BLUE
52#define LIGHT_SCHEDULER_BLUE 255
53#endif
54
55#ifndef LIGHT_SCHEDULER_BRIGHTNESS
56#define LIGHT_SCHEDULER_BRIGHTNESS 255
57#endif
58
60#ifndef LIGHT_SCHEDULER_COLOR
61#define LIGHT_SCHEDULER_COLOR LIGHT_SCHEDULER_COLOR_CUSTOM
62#endif
63
65#ifndef LIGHT_SCHEDULER_ALERT_COLOR
66#define LIGHT_SCHEDULER_ALERT_COLOR LIGHT_SCHEDULER_COLOR_RED
67#endif
68
70#ifndef LIGHT_SCHEDULER_ALERT_SPARKLE
71#define LIGHT_SCHEDULER_ALERT_SPARKLE FALSE
72#endif
73
80
83 [LIGHT_SCHEDULER_COLOR_CUSTOM] = {255, 255, 255},
84 [LIGHT_SCHEDULER_COLOR_RED] = {255, 0, 0},
85 [LIGHT_SCHEDULER_COLOR_GREEN] = { 0, 255, 0},
86 [LIGHT_SCHEDULER_COLOR_BLUE] = { 0, 0, 255},
87 [LIGHT_SCHEDULER_COLOR_WHITE] = {255, 255, 255},
88 [LIGHT_SCHEDULER_COLOR_YELLOW] = {255, 180, 0},
89 [LIGHT_SCHEDULER_COLOR_ORANGE] = {255, 60, 0},
90 [LIGHT_SCHEDULER_COLOR_CYAN] = { 0, 255, 255},
91 [LIGHT_SCHEDULER_COLOR_MAGENTA] = {255, 0, 255},
92 [LIGHT_SCHEDULER_COLOR_PURPLE] = {128, 0, 255},
93};
94
104
105static uint32_t s = 0;
106static uint32_t sparkle_seed = 0x2545F491;
107
110{
112 light_ws2812_arch_set(n, (r * k) / 255, (g * k) / 255, (b * k) / 255);
113}
114
117{
118 sparkle_seed ^= sparkle_seed << 13;
119 sparkle_seed ^= sparkle_seed >> 17;
121 return sparkle_seed;
122}
123
125static void light_scheduler_sparkle(void)
126{
127 static const uint8_t palette[] = {
131 };
132 for (uint32_t n = 0; n < WS2812_NB_LEDS; n++) {
134 if ((r >> 8) % 5 == 0) {
135 light_ws2812_arch_set(n, 0, 0, 0);
136 } else {
137 const uint8_t *c = light_scheduler_presets[palette[r % sizeof(palette)]];
138 light_scheduler_set(n, c[0], c[1], c[2]);
139 }
140 }
141}
142
155
165
167{
168 uint32_t n, s0;
169#ifdef LIGHT_SCHEDULER_ALERT
173 return;
174 }
176 for (n = 0; n < WS2812_NB_LEDS; n++) {
177 light_scheduler_set(n, c[0], c[1], c[2]);
178 }
179 return;
180 }
181#endif
182
185 return;
186 }
187
188 for (n = 0; n < WS2812_NB_LEDS; n++) {
191 // flag: three equal bands, led n is in the band containing its center (5 leds: 2 | 1 | 2)
192 uint32_t band = ((2 * n + 1) * 3) / (2 * WS2812_NB_LEDS);
194 light_scheduler_set(n, c[0], c[1], c[2]);
198 light_ws2812_arch_set(n, 0, 0, 0);
199 } else if (WS2812_NB_LEDS == 32) {
200 if (n<=7) light_scheduler_set(n, 0,255,0); // LEFT = GREEN
201 else if (n<=15)
202 light_scheduler_set(n, 0,0,255); // BACK = BLUE
203 else if (n<=23)
204 light_scheduler_set(n, 255,0,0); // RIGHT = RED
205 else
206 light_scheduler_set(n, 255,255,255); // FRONT = WHITE
207 } else {
208 s0 = s + 10 * n;
209 light_scheduler_set(n, s0 % 255, (s0 + 85) % 255, (s0 + 170) % 255);
210 }
211 }
212 s += 5; // rainbow speed at 16 Hz
213}
#define LIGHT_SCHEDULER_ALERT_COLOR
Alert color, shown in every mode while LIGHT_SCHEDULER_ALERT is true.
uint8_t light_scheduler_green
green value in color mode
#define LIGHT_SCHEDULER_RED
uint8_t light_scheduler_color
selected preset (light_scheduler_color_t)
static void light_scheduler_sparkle(void)
Sparkle: every led takes a random bright color, with white twinkles and short dark blinks.
#define LIGHT_SCHEDULER_BRIGHTNESS
static uint32_t s
uint8_t light_scheduler_mode
one of LIGHT_SCHEDULER_MODE_*
static const uint8_t light_scheduler_presets[LIGHT_SCHEDULER_COLOR_FLAG_FIRST][3]
RGB values of the single color presets.
uint8_t light_scheduler_blue
blue value in color mode
#define LIGHT_SCHEDULER_ALERT_SPARKLE
Show the sparkle effect instead of the alert color while LIGHT_SCHEDULER_ALERT is true.
#define LIGHT_SCHEDULER_BLUE
void light_scheduler_set_color(uint8_t color)
Settings handler: apply a color preset to red/green/blue (or select a flag) and switch to color mode.
static void light_scheduler_set(uint32_t n, uint8_t r, uint8_t g, uint8_t b)
set one led, scaled by the brightness setting
static uint32_t sparkle_rand(void)
xorshift32 pseudo random numbers for the sparkle effect
uint8_t light_scheduler_red
red value in color mode
#define LIGHT_SCHEDULER_MODE
Optional header needed by the alert condition.
void light_scheduler_init(void)
void light_scheduler_periodic(void)
static uint32_t sparkle_seed
#define LIGHT_SCHEDULER_COLOR
Startup color preset, overrides LIGHT_SCHEDULER_RED/GREEN/BLUE when not custom.
static const uint8_t light_scheduler_flags[LIGHT_SCHEDULER_COLOR_NB - LIGHT_SCHEDULER_COLOR_FLAG_FIRST][3]
Flags: three color presets, from the first to the last led of a strip.
#define LIGHT_SCHEDULER_GREEN
uint8_t light_scheduler_brightness
brightness scaling (255 = full)
basic LED scheduler based on WS2812 RGB led driver
#define LIGHT_SCHEDULER_COLOR_FLAG_FIRST
#define LIGHT_SCHEDULER_MODE_SPARKLE
@ LIGHT_SCHEDULER_COLOR_BLUE
@ LIGHT_SCHEDULER_COLOR_FLAG_ITALY
first flag, red | white | green
@ LIGHT_SCHEDULER_COLOR_FLAG_FRANCE
blue | white | red
@ LIGHT_SCHEDULER_COLOR_GREEN
@ LIGHT_SCHEDULER_COLOR_WHITE
@ LIGHT_SCHEDULER_COLOR_ORANGE
@ LIGHT_SCHEDULER_COLOR_PURPLE
@ LIGHT_SCHEDULER_COLOR_FLAG_NETHERLANDS
red | white | blue
@ LIGHT_SCHEDULER_COLOR_YELLOW
@ LIGHT_SCHEDULER_COLOR_NB
@ LIGHT_SCHEDULER_COLOR_CUSTOM
@ LIGHT_SCHEDULER_COLOR_RED
@ LIGHT_SCHEDULER_COLOR_CYAN
@ LIGHT_SCHEDULER_COLOR_MAGENTA
#define LIGHT_SCHEDULER_MODE_COLOR
#define LIGHT_SCHEDULER_MODE_OFF
void light_ws2812_arch_set(uint32_t led_number, uint8_t r, uint8_t g, uint8_t b)
set color RGB color of one led
void light_ws2812_arch_init(void)
ws2812 driver based on ChibiOS
#define WS2812_NB_LEDS
Number of LEDs.
uint16_t foo
Definition main_demo5.c:58
static float g
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition sonar_bebop.c:65
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
float b
Definition wedgebug.c:202