Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / io / ledstrip.h
blob204a4661d170f9d88dba351dad942ca356784c66
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #include "config/parameter_group.h"
21 #include "common/color.h"
22 #include "rx/rx.h"
24 #define LED_MAX_STRIP_LENGTH 128
25 #define LED_CONFIGURABLE_COLOR_COUNT 16
26 #define LED_MODE_COUNT 6
27 #define LED_DIRECTION_COUNT 6
28 #define LED_BASEFUNCTION_COUNT 8
29 #define LED_OVERLAY_COUNT 7
30 #define LED_SPECIAL_COLOR_COUNT 9
32 #define LED_FUNCTION_OFFSET 8
33 #define LED_OVERLAY_OFFSET 16
35 #define LED_POS_BITCNT 8
36 #define LED_FUNCTION_BITCNT 8
37 #define LED_OVERLAY_BITCNT 8
38 #define LED_COLOR_BITCNT 4
39 #define LED_DIRECTION_BITCNT 6
40 #define LED_PARAMS_BITCNT 6
42 #define LED_FLAG_OVERLAY_MASK ((1 << LED_OVERLAY_BITCNT) - 1)
44 #define LED_MOV_FUNCTION(func) ((func) << LED_FUNCTION_OFFSET)
45 #define LED_MOV_OVERLAY(overlay) ((overlay) << LED_OVERLAY_OFFSET)
47 #define LED_FUNCTION_MASK LED_MOV_FUNCTION(((1 << LED_FUNCTION_BITCNT) - 1))
48 #define LED_OVERLAY_MASK LED_MOV_OVERLAY(LED_FLAG_OVERLAY_MASK)
50 #define LED_FLAG_OVERLAY(id) (1 << (id))
51 #define LED_FLAG_DIRECTION(id) (1 << (id))
53 #define LED_X_BIT_OFFSET 4
54 #define LED_Y_BIT_OFFSET 0
55 #define LED_XY_MASK 0x0F
56 #define CALCULATE_LED_XY(x, y) ((((x) & LED_XY_MASK) << LED_X_BIT_OFFSET) | (((y) & LED_XY_MASK) << LED_Y_BIT_OFFSET))
58 typedef enum {
59 COLOR_BLACK = 0,
60 COLOR_WHITE,
61 COLOR_RED,
62 COLOR_ORANGE,
63 COLOR_YELLOW,
64 COLOR_LIME_GREEN,
65 COLOR_GREEN,
66 COLOR_MINT_GREEN,
67 COLOR_CYAN,
68 COLOR_LIGHT_BLUE,
69 COLOR_BLUE,
70 COLOR_DARK_VIOLET,
71 COLOR_MAGENTA,
72 COLOR_DEEP_PINK,
73 } colorId_e;
75 typedef enum {
76 LED_MODE_ORIENTATION = 0,
77 LED_MODE_HEADFREE,
78 LED_MODE_HORIZON,
79 LED_MODE_ANGLE,
80 LED_MODE_MAG,
81 LED_MODE_BARO,
82 LED_SPECIAL
83 } ledModeIndex_e;
85 typedef enum {
86 LED_SCOLOR_DISARMED = 0,
87 LED_SCOLOR_ARMED,
88 LED_SCOLOR_ANIMATION,
89 LED_SCOLOR_BACKGROUND,
90 LED_SCOLOR_BLINKBACKGROUND,
91 LED_SCOLOR_GPSNOSATS,
92 LED_SCOLOR_GPSNOLOCK,
93 LED_SCOLOR_GPSLOCKED,
94 LED_SCOLOR_STROBE
95 } ledSpecialColorIds_e;
97 typedef enum {
98 LED_DIRECTION_NORTH = 0,
99 LED_DIRECTION_EAST,
100 LED_DIRECTION_SOUTH,
101 LED_DIRECTION_WEST,
102 LED_DIRECTION_UP,
103 LED_DIRECTION_DOWN
104 } ledDirectionId_e;
106 typedef enum {
107 LED_FUNCTION_COLOR,
108 LED_FUNCTION_FLIGHT_MODE,
109 LED_FUNCTION_ARM_STATE,
110 LED_FUNCTION_BATTERY,
111 LED_FUNCTION_RSSI,
112 LED_FUNCTION_GPS,
113 LED_FUNCTION_THRUST_RING,
114 LED_FUNCTION_CHANNEL,
115 } ledBaseFunctionId_e;
117 typedef enum {
118 LED_OVERLAY_THROTTLE,
119 LED_OVERLAY_LARSON_SCANNER,
120 LED_OVERLAY_BLINK,
121 LED_OVERLAY_LANDING_FLASH,
122 LED_OVERLAY_INDICATOR,
123 LED_OVERLAY_WARNING,
124 LED_OVERLAY_STROBE
125 } ledOverlayId_e;
127 typedef struct modeColorIndexes_s {
128 uint8_t color[LED_DIRECTION_COUNT];
129 } modeColorIndexes_t;
131 typedef struct specialColorIndexes_s {
132 uint8_t color[LED_SPECIAL_COLOR_COUNT];
133 } specialColorIndexes_t;
135 typedef struct ledConfig_s {
136 uint16_t led_position : LED_POS_BITCNT;
137 uint16_t led_function : LED_FUNCTION_BITCNT;
138 uint16_t led_overlay : LED_OVERLAY_BITCNT;
139 uint16_t led_color : LED_COLOR_BITCNT;
140 uint16_t led_direction : LED_DIRECTION_BITCNT;
141 uint16_t led_params : LED_PARAMS_BITCNT;
142 } __attribute__((packed)) ledConfig_t;
144 typedef struct ledCounts_s {
145 uint8_t count;
146 uint8_t ring;
147 uint8_t larson;
148 uint8_t ringSeqLen;
149 } ledCounts_t;
151 typedef struct ledStripConfig_s {
152 ledConfig_t ledConfigs[LED_MAX_STRIP_LENGTH];
153 hsvColor_t colors[LED_CONFIGURABLE_COLOR_COUNT];
154 modeColorIndexes_t modeColors[LED_MODE_COUNT];
155 specialColorIndexes_t specialColors;
156 } ledStripConfig_t;
158 PG_DECLARE(ledStripConfig_t, ledStripConfig);
160 #define DEFINE_LED(ledConfigPtr, x, y, col, dir, func, ol, params) { \
161 (ledConfigPtr)->led_position = CALCULATE_LED_XY(x, y); \
162 (ledConfigPtr)->led_color = (col); \
163 (ledConfigPtr)->led_direction = (dir); \
164 (ledConfigPtr)->led_function = (func); \
165 (ledConfigPtr)->led_overlay = (ol); \
166 (ledConfigPtr)->led_params = (params); }
168 static inline uint8_t ledGetXY(const ledConfig_t *lcfg) { return (lcfg->led_position); }
169 static inline uint8_t ledGetX(const ledConfig_t *lcfg) { return ((lcfg->led_position >> (LED_X_BIT_OFFSET)) & LED_XY_MASK); }
170 static inline uint8_t ledGetY(const ledConfig_t *lcfg) { return ((lcfg->led_position >> (LED_Y_BIT_OFFSET)) & LED_XY_MASK); }
171 static inline uint8_t ledGetFunction(const ledConfig_t *lcfg) { return (lcfg->led_function); }
172 static inline uint8_t ledGetOverlay(const ledConfig_t *lcfg) { return (lcfg->led_overlay); }
173 static inline uint8_t ledGetColor(const ledConfig_t *lcfg) { return (lcfg->led_color); }
174 static inline uint8_t ledGetDirection(const ledConfig_t *lcfg) { return (lcfg->led_direction); }
175 static inline uint8_t ledGetParams(const ledConfig_t *lcfg) { return (lcfg->led_params); }
177 static inline bool ledGetOverlayBit(const ledConfig_t *lcfg, int id) { return ((ledGetOverlay(lcfg) >> id) & 1); }
178 static inline bool ledGetDirectionBit(const ledConfig_t *lcfg, int id) { return ((ledGetDirection(lcfg) >> id) & 1); }
180 bool parseColor(int index, const char *colorConfig);
182 bool parseLedStripConfig(int ledIndex, const char *config);
183 void generateLedConfig(ledConfig_t *ledConfig, char *ledConfigBuffer, size_t bufferSize);
184 void reevaluateLedConfig(void);
186 void ledStripInit(void);
187 void ledStripEnable(void);
188 void ledStripUpdate(timeUs_t currentTimeUs);
190 bool setModeColor(ledModeIndex_e modeIndex, int modeColorIndex, int colorIndex);