mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 01:05:27 +03:00
Allow colors to be configurable via the cli.
color x h,s,v x = 0-15 h = 0-359 s = 0-255 v = 0-255
This commit is contained in:
parent
4b06592ce7
commit
72eac8048a
5 changed files with 148 additions and 7 deletions
|
@ -54,7 +54,7 @@ static failsafe_t* failsafe;
|
|||
#error "Led strip length must match driver"
|
||||
#endif
|
||||
|
||||
static hsvColor_t *colors;
|
||||
hsvColor_t *colors;
|
||||
|
||||
//#define USE_LED_ANIMATION
|
||||
|
||||
|
@ -756,6 +756,57 @@ void updateLedStrip(void)
|
|||
ws2811UpdateStrip();
|
||||
}
|
||||
|
||||
bool parseColor(uint8_t index, char *colorConfig)
|
||||
{
|
||||
char *remainingCharacters = colorConfig;
|
||||
|
||||
hsvColor_t *color = &colors[index];
|
||||
|
||||
bool ok = true;
|
||||
|
||||
uint8_t componentIndex;
|
||||
for (componentIndex = 0; ok && componentIndex < HSV_COLOR_COMPONENT_COUNT; componentIndex++) {
|
||||
uint16_t val = atoi(remainingCharacters);
|
||||
switch (componentIndex) {
|
||||
case HSV_HUE:
|
||||
if (val > HSV_HUE_MAX) {
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
colors[index].h = val;
|
||||
break;
|
||||
case HSV_SATURATION:
|
||||
if (val > HSV_SATURATION_MAX) {
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
colors[index].s = (uint8_t)val;
|
||||
break;
|
||||
case HSV_VALUE:
|
||||
if (val > HSV_VALUE_MAX) {
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
colors[index].v = (uint8_t)val;
|
||||
break;
|
||||
}
|
||||
remainingCharacters = strstr(remainingCharacters, ",");
|
||||
if (remainingCharacters) {
|
||||
remainingCharacters++;
|
||||
} else {
|
||||
if (componentIndex < 2) {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
memset(color, 0, sizeof(hsvColor_t));
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
void applyDefaultColors(hsvColor_t *colors, uint8_t colorCount)
|
||||
{
|
||||
memset(colors, 0, colorCount * sizeof(colors));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue