1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 08:15:30 +03:00

Add rainbow effect to led strip (#12323)

* Add rainbow effect

* unit test

* default values + version change
This commit is contained in:
ASDosjani 2023-03-16 15:07:17 +01:00 committed by GitHub
parent 8a7068d633
commit 7735a7129e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 10 deletions

View file

@ -1288,6 +1288,8 @@ const clivalue_t valueTable[] = {
{ "ledstrip_beacon_percent", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledstrip_beacon_percent) },
{ "ledstrip_beacon_armed_only", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledstrip_beacon_armed_only) },
{ "ledstrip_brightness", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 5, 100 }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledstrip_brightness) },
{ "ledstrip_rainbow_delta", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, HSV_HUE_MAX }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledstrip_rainbow_delta) },
{ "ledstrip_rainbow_freq", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 1, 200 }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledstrip_rainbow_freq) },
#endif
// PG_SDCARD_CONFIG

View file

@ -115,7 +115,7 @@ const hsvColor_t hsv[] = {
// macro to save typing on default colors
#define HSV(color) (hsv[COLOR_ ## color])
PG_REGISTER_WITH_RESET_FN(ledStripConfig_t, ledStripConfig, PG_LED_STRIP_CONFIG, 2);
PG_REGISTER_WITH_RESET_FN(ledStripConfig_t, ledStripConfig, PG_LED_STRIP_CONFIG, 3);
void pgResetFn_ledStripConfig(ledStripConfig_t *ledStripConfig)
{
@ -132,6 +132,8 @@ void pgResetFn_ledStripConfig(ledStripConfig_t *ledStripConfig)
ledStripConfig->ledstrip_beacon_armed_only = false; // blink always
ledStripConfig->ledstrip_visual_beeper_color = VISUAL_BEEPER_COLOR;
ledStripConfig->ledstrip_brightness = 100;
ledStripConfig->ledstrip_rainbow_delta = 0;
ledStripConfig->ledstrip_rainbow_freq = 120;
#ifndef UNIT_TEST
#ifdef LED_STRIP_PIN
ledStripConfig->ioTag = IO_TAG(LED_STRIP_PIN);
@ -295,7 +297,7 @@ static const hsvColor_t* getSC(ledSpecialColorIds_e index)
static const char directionCodes[LED_DIRECTION_COUNT] = { 'N', 'E', 'S', 'W', 'U', 'D' };
static const char baseFunctionCodes[LED_BASEFUNCTION_COUNT] = { 'C', 'F', 'A', 'L', 'S', 'G', 'R' };
static const char overlayCodes[LED_OVERLAY_COUNT] = { 'T', 'O', 'B', 'V', 'I', 'W' };
static const char overlayCodes[LED_OVERLAY_COUNT] = { 'T', 'Y', 'O', 'B', 'V', 'I', 'W' };
#define CHUNK_BUFFER_SIZE 11
bool parseLedStripConfig(int ledIndex, const char *config)
@ -894,6 +896,30 @@ static void applyLedThrustRingLayer(bool updateNow, timeUs_t *timer)
}
}
static void applyRainbowLayer(bool updateNow, timeUs_t *timer)
{
static int offset = 0;
if (updateNow) {
*timer += HZ_TO_US(ledStripConfig()->ledstrip_rainbow_freq);
}
uint8_t rainbowLedIndex = 0;
for (unsigned i = 0; i < ledCounts.count; i++) {
const ledConfig_t *ledConfig = &ledStripStatusModeConfig()->ledConfigs[i];
if (ledGetOverlayBit(ledConfig, LED_OVERLAY_RAINBOW)) {
hsvColor_t ledColor;
ledColor.h = (offset + (rainbowLedIndex * ledStripConfig()->ledstrip_rainbow_delta)) % HSV_HUE_MAX;
ledColor.s = 0;
ledColor.v = HSV_VALUE_MAX;
setLedHsv(i, &ledColor);
rainbowLedIndex++;
}
}
offset++;
}
typedef struct larsonParameters_s {
uint8_t currentBrightness;
int8_t currentIndex;
@ -984,6 +1010,7 @@ static void applyLedBlinkLayer(bool updateNow, timeUs_t *timer)
// In reverse order of priority
typedef enum {
timRainbow,
timBlink,
timLarson,
timRing,
@ -1013,6 +1040,7 @@ STATIC_ASSERT(timTimerCount <= sizeof(disabledTimerMask) * 8, disabledTimerMask_
typedef void applyLayerFn_timed(bool updateNow, timeUs_t *timer);
static applyLayerFn_timed* layerTable[] = {
[timRainbow] = &applyRainbowLayer,
[timBlink] = &applyLedBlinkLayer,
[timLarson] = &applyLarsonScannerLayer,
[timBattery] = &applyLedBatteryLayer,
@ -1042,6 +1070,7 @@ bool isOverlayTypeUsed(ledOverlayId_e overlayType)
void updateRequiredOverlay(void)
{
disabledTimerMask = 0;
disabledTimerMask |= !isOverlayTypeUsed(LED_OVERLAY_RAINBOW) << timRainbow;
disabledTimerMask |= !isOverlayTypeUsed(LED_OVERLAY_BLINK) << timBlink;
disabledTimerMask |= !isOverlayTypeUsed(LED_OVERLAY_LARSON_SCANNER) << timLarson;
disabledTimerMask |= !isOverlayTypeUsed(LED_OVERLAY_WARNING) << timWarning;

View file

@ -32,22 +32,22 @@
#define LED_MODE_COUNT 6
#define LED_DIRECTION_COUNT 6
#define LED_BASEFUNCTION_COUNT 7
#define LED_OVERLAY_COUNT 6
#define LED_OVERLAY_COUNT 7
#define LED_SPECIAL_COLOR_COUNT 11
#define LED_POS_OFFSET 0
#define LED_FUNCTION_OFFSET 8
#define LED_OVERLAY_OFFSET 12
#define LED_COLOR_OFFSET 18
#define LED_DIRECTION_OFFSET 22
#define LED_PARAMS_OFFSET 28
#define LED_COLOR_OFFSET 19
#define LED_DIRECTION_OFFSET 23
#define LED_PARAMS_OFFSET 29
#define LED_POS_BITCNT 8
#define LED_FUNCTION_BITCNT 4
#define LED_OVERLAY_BITCNT 6
#define LED_OVERLAY_BITCNT 7
#define LED_COLOR_BITCNT 4
#define LED_DIRECTION_BITCNT 6
#define LED_PARAMS_BITCNT 4
#define LED_PARAMS_BITCNT 3
#define LED_FLAG_OVERLAY_MASK ((1 << LED_OVERLAY_BITCNT) - 1)
#define LED_FLAG_DIRECTION_MASK ((1 << LED_DIRECTION_BITCNT) - 1)
@ -137,6 +137,7 @@ typedef enum {
typedef enum {
LED_OVERLAY_THROTTLE,
LED_OVERLAY_RAINBOW,
LED_OVERLAY_LARSON_SCANNER,
LED_OVERLAY_BLINK,
LED_OVERLAY_VTX,
@ -182,6 +183,8 @@ typedef struct ledStripConfig_s {
uint8_t ledstrip_beacon_armed_only;
colorId_e ledstrip_visual_beeper_color;
uint8_t ledstrip_brightness;
uint8_t ledstrip_rainbow_delta;
uint8_t ledstrip_rainbow_freq;
} ledStripConfig_t;
PG_DECLARE(ledStripConfig_t, ledStripConfig);

View file

@ -62,7 +62,7 @@
#define MSP_PROTOCOL_VERSION 0
#define API_VERSION_MAJOR 1 // increment when major changes are made
#define API_VERSION_MINOR 45 // increment after a release, to set the version for all changes to go into the following release (if no changes to MSP are made between the releases, this can be reverted before the release)
#define API_VERSION_MINOR 46 // increment after a release, to set the version for all changes to go into the following release (if no changes to MSP are made between the releases, this can be reverted before the release)
#define API_VERSION_LENGTH 2

View file

@ -222,7 +222,7 @@ TEST(RxSpiExpressLrsTelemetryUnitTest, TestFlightMode)
TEST(RxSpiExpressLrsTelemetryUnitTest, TestMspVersionRequest)
{
uint8_t request[15] = {238, 12, 122, 200, 234, 48, 0, 1, 1, 0, 0, 0, 0, 128, 0};
uint8_t response[12] = {200, 10, 123, 234, 200, 48, 3, 1, 0, API_VERSION_MAJOR, API_VERSION_MINOR, 255};
uint8_t response[12] = {200, 10, 123, 234, 200, 48, 3, 1, 0, API_VERSION_MAJOR, API_VERSION_MINOR, 0x55};
uint8_t data1[6] = {1, request[0], request[1], request[2], request[3], request[4]};
uint8_t data2[6] = {2, request[5], request[6], request[7], request[8], request[9]};
uint8_t data3[6] = {3, request[10], request[11], request[12], request[13], request[14]};