mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
Add LED strip config values to MSP (#12995)
* Add LED strip config values to MSP * change hue calculation + higher max frequency * higher rainbow frequency * define LED Strip task rate * msp2 * fix delta size * Update src/main/msp/msp.c Co-authored-by: Mark Haslinghuis <mark@numloq.nl> * Update src/main/msp/msp.c Co-authored-by: Mark Haslinghuis <mark@numloq.nl> --------- Co-authored-by: Mark Haslinghuis <mark@numloq.nl>
This commit is contained in:
parent
37f119cf4f
commit
5cd2ab50e4
6 changed files with 28 additions and 9 deletions
|
@ -1319,8 +1319,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) },
|
||||
{ "ledstrip_rainbow_delta", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, HSV_HUE_MAX }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledstrip_rainbow_delta) },
|
||||
{ "ledstrip_rainbow_freq", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 1, 2000 }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledstrip_rainbow_freq) },
|
||||
#endif
|
||||
|
||||
// PG_SDCARD_CONFIG
|
||||
|
|
|
@ -407,7 +407,7 @@ task_attribute_t task_attributes[TASK_COUNT] = {
|
|||
#endif
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
[TASK_LEDSTRIP] = DEFINE_TASK("LEDSTRIP", NULL, NULL, ledStripUpdate, TASK_PERIOD_HZ(100), TASK_PRIORITY_LOW),
|
||||
[TASK_LEDSTRIP] = DEFINE_TASK("LEDSTRIP", NULL, NULL, ledStripUpdate, TASK_PERIOD_HZ(TASK_LEDSTRIP_RATE_HZ), TASK_PRIORITY_LOW),
|
||||
#endif
|
||||
|
||||
#ifdef USE_BST
|
||||
|
|
|
@ -898,26 +898,26 @@ static void applyLedThrustRingLayer(bool updateNow, timeUs_t *timer)
|
|||
|
||||
static void applyRainbowLayer(bool updateNow, timeUs_t *timer)
|
||||
{
|
||||
//use offset as a fixed point number
|
||||
static int offset = 0;
|
||||
|
||||
if (updateNow) {
|
||||
*timer += HZ_TO_US(ledStripConfig()->ledstrip_rainbow_freq);
|
||||
offset += ledStripConfig()->ledstrip_rainbow_freq;
|
||||
*timer += HZ_TO_US(TASK_LEDSTRIP_RATE_HZ);
|
||||
}
|
||||
|
||||
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.h = (offset / TASK_LEDSTRIP_RATE_HZ + rainbowLedIndex * ledStripConfig()->ledstrip_rainbow_delta) % (HSV_HUE_MAX + 1);
|
||||
ledColor.s = 0;
|
||||
ledColor.v = HSV_VALUE_MAX;
|
||||
setLedHsv(i, &ledColor);
|
||||
rainbowLedIndex++;
|
||||
}
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
|
||||
typedef struct larsonParameters_s {
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include "pg/pg.h"
|
||||
|
||||
#define TASK_LEDSTRIP_RATE_HZ 100
|
||||
|
||||
#define LED_CONFIGURABLE_COLOR_COUNT 16
|
||||
#define LED_MODE_COUNT 6
|
||||
#define LED_DIRECTION_COUNT 6
|
||||
|
@ -176,8 +178,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;
|
||||
uint16_t ledstrip_rainbow_delta;
|
||||
uint16_t ledstrip_rainbow_freq;
|
||||
} ledStripConfig_t;
|
||||
|
||||
PG_DECLARE(ledStripConfig_t, ledStripConfig);
|
||||
|
|
|
@ -2573,6 +2573,13 @@ static mspResult_e mspFcProcessOutCommandWithArg(mspDescriptor_t srcDesc, int16_
|
|||
}
|
||||
}
|
||||
break;
|
||||
#ifdef USE_LED_STRIP
|
||||
case MSP2_GET_LED_STRIP_CONFIG_VALUES:
|
||||
sbufWriteU8(dst, ledStripConfig()->ledstrip_brightness);
|
||||
sbufWriteU16(dst, ledStripConfig()->ledstrip_rainbow_delta);
|
||||
sbufWriteU16(dst, ledStripConfig()->ledstrip_rainbow_freq);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return MSP_RESULT_CMD_UNKNOWN;
|
||||
|
@ -3984,6 +3991,14 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
|
|||
}
|
||||
break;
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
case MSP2_SET_LED_STRIP_CONFIG_VALUES:
|
||||
ledStripConfigMutable()->ledstrip_brightness = sbufReadU8(src);
|
||||
ledStripConfigMutable()->ledstrip_rainbow_delta = sbufReadU16(src);
|
||||
ledStripConfigMutable()->ledstrip_rainbow_freq = sbufReadU16(src);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
// we do not know how to handle the (valid) message, indicate error MSP $M!
|
||||
return MSP_RESULT_ERROR;
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#define MSP2_GET_OSD_WARNINGS 0x3005 // returns active OSD warning message text
|
||||
#define MSP2_GET_TEXT 0x3006
|
||||
#define MSP2_SET_TEXT 0x3007
|
||||
#define MSP2_GET_LED_STRIP_CONFIG_VALUES 0x3008
|
||||
#define MSP2_SET_LED_STRIP_CONFIG_VALUES 0x3009
|
||||
|
||||
// MSP2_SET_TEXT and MSP2_GET_TEXT variable types
|
||||
#define MSP2TEXT_PILOT_NAME 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue