mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Add LED profile feature - 4278
This commit is contained in:
parent
e0fc9300ed
commit
4ec536a317
15 changed files with 333 additions and 101 deletions
|
@ -39,32 +39,55 @@
|
|||
|
||||
#include "fc/config.h"
|
||||
|
||||
#include "io/ledstrip.h"
|
||||
|
||||
#include "interface/settings.h"
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
|
||||
static bool featureRead = false;
|
||||
static uint8_t cmsx_FeatureLedstrip;
|
||||
static uint8_t cmsx_LedProfile;
|
||||
static uint8_t cmsx_RaceColor;
|
||||
const char * const ledProfileNames[LED_PROFILE_COUNT] = {
|
||||
"RACE",
|
||||
"BEACON",
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
"STATUS"
|
||||
#endif
|
||||
};
|
||||
|
||||
static long cmsx_Ledstrip_FeatureRead(void)
|
||||
static long cmsx_Ledstrip_OnEnter(void)
|
||||
{
|
||||
if (!featureRead) {
|
||||
cmsx_FeatureLedstrip = featureIsEnabled(FEATURE_LED_STRIP) ? 1 : 0;
|
||||
featureRead = true;
|
||||
}
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
cmsx_LedProfile = getLedProfile();
|
||||
cmsx_RaceColor = getLedRaceColor();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long cmsx_Ledstrip_FeatureWriteback(const OSD_Entry *self)
|
||||
static long cmsx_Ledstrip_OnExit(const OSD_Entry *self)
|
||||
{
|
||||
UNUSED(self);
|
||||
if (featureRead) {
|
||||
if (cmsx_FeatureLedstrip)
|
||||
featureEnable(FEATURE_LED_STRIP);
|
||||
else
|
||||
else {
|
||||
ledStripDisable();
|
||||
featureDisable(FEATURE_LED_STRIP);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
setLedProfile(cmsx_LedProfile);
|
||||
setLedRaceColor(cmsx_RaceColor);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -72,7 +95,8 @@ static OSD_Entry cmsx_menuLedstripEntries[] =
|
|||
{
|
||||
{ "-- LED STRIP --", OME_Label, NULL, NULL, 0 },
|
||||
{ "ENABLED", OME_Bool, NULL, &cmsx_FeatureLedstrip, 0 },
|
||||
|
||||
{ "PROFILE", OME_TAB, NULL, &(OSD_TAB_t){ &cmsx_LedProfile, LED_PROFILE_COUNT-1, ledProfileNames }, 0 },
|
||||
{ "RACE COLOR", OME_TAB, NULL, &(OSD_TAB_t){ &cmsx_RaceColor, COLOR_COUNT-1, lookupTableLEDRaceColors }, 0 },
|
||||
{ "BACK", OME_Back, NULL, NULL, 0 },
|
||||
{ NULL, OME_END, NULL, NULL, 0 }
|
||||
};
|
||||
|
@ -82,8 +106,8 @@ CMS_Menu cmsx_menuLedstrip = {
|
|||
.GUARD_text = "MENULED",
|
||||
.GUARD_type = OME_MENU,
|
||||
#endif
|
||||
.onEnter = cmsx_Ledstrip_FeatureRead,
|
||||
.onExit = cmsx_Ledstrip_FeatureWriteback,
|
||||
.onEnter = cmsx_Ledstrip_OnEnter,
|
||||
.onExit = cmsx_Ledstrip_OnExit,
|
||||
.entries = cmsx_menuLedstripEntries
|
||||
};
|
||||
#endif // LED_STRIP
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "flight/pid.h"
|
||||
|
||||
#include "io/beeper.h"
|
||||
#include "io/ledstrip.h"
|
||||
#include "io/motors.h"
|
||||
#include "io/pidaudio.h"
|
||||
#include "io/osd.h"
|
||||
|
@ -242,6 +243,10 @@ static const adjustmentConfig_t defaultAdjustmentConfigs[ADJUSTMENT_FUNCTION_COU
|
|||
.adjustmentFunction = ADJUSTMENT_OSD_PROFILE,
|
||||
.mode = ADJUSTMENT_MODE_SELECT,
|
||||
.data = { .switchPositions = 3 }
|
||||
}, {
|
||||
.adjustmentFunction = ADJUSTMENT_LED_PROFILE,
|
||||
.mode = ADJUSTMENT_MODE_SELECT,
|
||||
.data = { .switchPositions = 3 }
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -665,11 +670,20 @@ static uint8_t applySelectAdjustment(adjustmentFunction_e adjustmentFunction, ui
|
|||
}
|
||||
#endif
|
||||
break;
|
||||
#ifdef USE_OSD_PROFILES
|
||||
case ADJUSTMENT_OSD_PROFILE:
|
||||
#ifdef USE_OSD_PROFILES
|
||||
if (getCurrentOsdProfileIndex() != (position + 1)) {
|
||||
changeOsdProfileIndex(position+1);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case ADJUSTMENT_LED_PROFILE:
|
||||
#ifdef USE_LED_STRIP
|
||||
#ifndef UNIT_TEST
|
||||
if (getLedProfile() != position) {
|
||||
setLedProfile(position);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
@ -793,6 +807,9 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig)
|
|||
&& adjustmentState->config->adjustmentFunction != ADJUSTMENT_RATE_PROFILE // Rate profile already has an OSD element
|
||||
#ifdef USE_OSD_PROFILES
|
||||
&& adjustmentState->config->adjustmentFunction != ADJUSTMENT_OSD_PROFILE
|
||||
#endif
|
||||
#ifdef USE_LED_STRIP
|
||||
&& adjustmentState->config->adjustmentFunction != ADJUSTMENT_LED_PROFILE
|
||||
#endif
|
||||
) {
|
||||
adjustmentRangeNameIndex = adjustmentFunction;
|
||||
|
|
|
@ -59,6 +59,7 @@ typedef enum {
|
|||
ADJUSTMENT_ROLL_F,
|
||||
ADJUSTMENT_YAW_F,
|
||||
ADJUSTMENT_OSD_PROFILE,
|
||||
ADJUSTMENT_LED_PROFILE,
|
||||
ADJUSTMENT_FUNCTION_COUNT
|
||||
} adjustmentFunction_e;
|
||||
|
||||
|
|
|
@ -1579,7 +1579,7 @@ static void cliRxRange(char *cmdline)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
static void printLed(uint8_t dumpMask, const ledConfig_t *ledConfigs, const ledConfig_t *defaultLedConfigs)
|
||||
{
|
||||
const char *format = "led %u %s";
|
||||
|
@ -4657,7 +4657,7 @@ static void printConfig(char *cmdline, bool doDiff)
|
|||
cliPrintHashLine("serial");
|
||||
printSerial(dumpMask, &serialConfig_Copy, serialConfig());
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
cliPrintHashLine("led");
|
||||
printLed(dumpMask, ledStripConfig_Copy.ledConfigs, ledStripConfig()->ledConfigs);
|
||||
|
||||
|
@ -4818,8 +4818,8 @@ const clicmd_t cmdTable[] = {
|
|||
#if defined(USE_BOARD_INFO)
|
||||
CLI_COMMAND_DEF("board_name", "get / set the name of the board model", "[board name]", cliBoardName),
|
||||
#endif
|
||||
#ifdef USE_LED_STRIP
|
||||
CLI_COMMAND_DEF("color", "configure colors", NULL, cliColor),
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
CLI_COMMAND_DEF("color", "configure colors", NULL, cliColor),
|
||||
#endif
|
||||
CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", "[nosave]", cliDefaults),
|
||||
CLI_COMMAND_DEF("diff", "list configuration changes from default", "[master|profile|rates|all] {defaults}", cliDiff),
|
||||
|
@ -4857,8 +4857,8 @@ const clicmd_t cmdTable[] = {
|
|||
CLI_COMMAND_DEF("gyroregisters", "dump gyro config registers contents", NULL, cliDumpGyroRegisters),
|
||||
#endif
|
||||
CLI_COMMAND_DEF("help", NULL, NULL, cliHelp),
|
||||
#ifdef USE_LED_STRIP
|
||||
CLI_COMMAND_DEF("led", "configure leds", NULL, cliLed),
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
CLI_COMMAND_DEF("led", "configure leds", NULL, cliLed),
|
||||
#endif
|
||||
#if defined(USE_BOARD_INFO)
|
||||
CLI_COMMAND_DEF("manufacturer_id", "get / set the id of the board manufacturer", "[manufacturer id]", cliManufacturerId),
|
||||
|
@ -4869,7 +4869,7 @@ const clicmd_t cmdTable[] = {
|
|||
CLI_COMMAND_DEF("mixer", "configure mixer", "list\r\n\t<name>", cliMixer),
|
||||
#endif
|
||||
CLI_COMMAND_DEF("mmix", "custom motor mixer", NULL, cliMotorMix),
|
||||
#ifdef USE_LED_STRIP
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
CLI_COMMAND_DEF("mode_color", "configure mode and special colors", NULL, cliModeColor),
|
||||
#endif
|
||||
CLI_COMMAND_DEF("motor", "get/set motor", "<index> [<value>]", cliMotor),
|
||||
|
|
|
@ -1181,7 +1181,7 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst)
|
|||
}
|
||||
break;
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
case MSP_LED_COLORS:
|
||||
for (int i = 0; i < LED_CONFIGURABLE_COLOR_COUNT; i++) {
|
||||
const hsvColor_t *color = &ledStripConfig()->colors[i];
|
||||
|
@ -2255,7 +2255,7 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
|||
}
|
||||
break;
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
case MSP_SET_LED_COLORS:
|
||||
for (int i = 0; i < LED_CONFIGURABLE_COLOR_COUNT; i++) {
|
||||
hsvColor_t *color = &ledStripConfigMutable()->colors[i];
|
||||
|
|
|
@ -340,7 +340,7 @@ static const char * const lookupOverclock[] = {
|
|||
};
|
||||
#endif
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
static const char * const lookupLedStripFormatRGB[] = {
|
||||
"GRB", "RGB"
|
||||
};
|
||||
|
@ -423,6 +423,35 @@ static const char * const lookupTableTpaMode[] = {
|
|||
};
|
||||
#endif
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
static const char * const lookupTableLEDProfile[] = {
|
||||
"RACE", "BEACON", "STATUS"
|
||||
};
|
||||
#else
|
||||
static const char * const lookupTableLEDProfile[] = {
|
||||
"RACE", "BEACON"
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
const char * const lookupTableLEDRaceColors[COLOR_COUNT] = {
|
||||
"BLACK",
|
||||
"WHITE",
|
||||
"RED",
|
||||
"ORANGE",
|
||||
"YELLOW",
|
||||
"LIME_GREEN",
|
||||
"GREEN",
|
||||
"MINT_GREEN",
|
||||
"CYAN",
|
||||
"LIGHT_BLUE",
|
||||
"BLUE",
|
||||
"DARK_VIOLET",
|
||||
"MAGENTA",
|
||||
"DEEP_PINK"
|
||||
};
|
||||
|
||||
#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
|
||||
|
||||
const lookupTableEntry_t lookupTables[] = {
|
||||
|
@ -492,7 +521,7 @@ const lookupTableEntry_t lookupTables[] = {
|
|||
#ifdef USE_OVERCLOCK
|
||||
LOOKUP_TABLE_ENTRY(lookupOverclock),
|
||||
#endif
|
||||
#ifdef USE_LED_STRIP
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
LOOKUP_TABLE_ENTRY(lookupLedStripFormatRGB),
|
||||
#endif
|
||||
#ifdef USE_MULTI_GYRO
|
||||
|
@ -531,6 +560,10 @@ const lookupTableEntry_t lookupTables[] = {
|
|||
#ifdef USE_TPA_MODE
|
||||
LOOKUP_TABLE_ENTRY(lookupTableTpaMode),
|
||||
#endif
|
||||
#ifdef USE_LED_STRIP
|
||||
LOOKUP_TABLE_ENTRY(lookupTableLEDProfile),
|
||||
LOOKUP_TABLE_ENTRY(lookupTableLEDRaceColors),
|
||||
#endif
|
||||
};
|
||||
|
||||
#undef LOOKUP_TABLE_ENTRY
|
||||
|
@ -1014,6 +1047,8 @@ const clivalue_t valueTable[] = {
|
|||
#ifdef USE_LED_STRIP
|
||||
{ "ledstrip_visual_beeper", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledstrip_visual_beeper) },
|
||||
{ "ledstrip_grb_rgb", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_RGB_GRB }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledstrip_grb_rgb) },
|
||||
{ "ledstrip_profile", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_LED_PROFILE }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledstrip_profile) },
|
||||
{ "ledstrip_race_color", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_LED_RACE_COLOR }, PG_LED_STRIP_CONFIG, offsetof(ledStripConfig_t, ledRaceColor) },
|
||||
#endif
|
||||
|
||||
// PG_SDCARD_CONFIG
|
||||
|
|
|
@ -92,7 +92,7 @@ typedef enum {
|
|||
#ifdef USE_OVERCLOCK
|
||||
TABLE_OVERCLOCK,
|
||||
#endif
|
||||
#ifdef USE_LED_STRIP
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
TABLE_RGB_GRB,
|
||||
#endif
|
||||
#ifdef USE_MULTI_GYRO
|
||||
|
@ -130,6 +130,10 @@ typedef enum {
|
|||
#endif
|
||||
#ifdef USE_TPA_MODE
|
||||
TABLE_TPA_MODE,
|
||||
#endif
|
||||
#ifdef USE_LED_STRIP
|
||||
TABLE_LED_PROFILE,
|
||||
TABLE_LED_RACE_COLOR,
|
||||
#endif
|
||||
LOOKUP_TABLE_COUNT
|
||||
} lookupTableIndex_e;
|
||||
|
@ -218,3 +222,5 @@ extern const char * const lookupTableMagHardware[];
|
|||
//extern const uint8_t lookupTableMagHardwareEntryCount;
|
||||
|
||||
extern const char * const lookupTableRangefinderHardware[];
|
||||
|
||||
extern const char * const lookupTableLEDRaceColors[];
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
|
||||
#include "drivers/light_ws2811strip.h"
|
||||
#include "drivers/serial.h"
|
||||
#include "drivers/time.h"
|
||||
#include "drivers/vtx_common.h"
|
||||
|
||||
#include "fc/config.h"
|
||||
|
@ -83,35 +84,21 @@ const modeColorIndexes_t *modeColors;
|
|||
specialColorIndexes_t specialColors;
|
||||
|
||||
static bool ledStripInitialised = false;
|
||||
static bool ledStripEnabled = true;
|
||||
static volatile bool ledStripEnabled = true;
|
||||
|
||||
static void ledStripDisable(void);
|
||||
void ledStripDisable(void);
|
||||
|
||||
#define HZ_TO_US(hz) ((int32_t)((1000 * 1000) / (hz)))
|
||||
|
||||
#define MAX_TIMER_DELAY (5 * 1000 * 1000)
|
||||
|
||||
#define BEACON_FLASH_PERIOD_MS 1000 // 1000ms
|
||||
#define BEACON_FLASH_ON_TIME 100 // 100ms
|
||||
|
||||
#if LED_MAX_STRIP_LENGTH > WS2811_LED_STRIP_LENGTH
|
||||
# error "Led strip length must match driver"
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
COLOR_BLACK = 0,
|
||||
COLOR_WHITE,
|
||||
COLOR_RED,
|
||||
COLOR_ORANGE,
|
||||
COLOR_YELLOW,
|
||||
COLOR_LIME_GREEN,
|
||||
COLOR_GREEN,
|
||||
COLOR_MINT_GREEN,
|
||||
COLOR_CYAN,
|
||||
COLOR_LIGHT_BLUE,
|
||||
COLOR_BLUE,
|
||||
COLOR_DARK_VIOLET,
|
||||
COLOR_MAGENTA,
|
||||
COLOR_DEEP_PINK
|
||||
} colorId_e;
|
||||
|
||||
const hsvColor_t hsv[] = {
|
||||
// H S V
|
||||
[COLOR_BLACK] = { 0, 0, 0},
|
||||
|
@ -175,7 +162,12 @@ void pgResetFn_ledStripConfig(ledStripConfig_t *ledStripConfig)
|
|||
memcpy_fn(&ledStripConfig->specialColors, &defaultSpecialColors, sizeof(defaultSpecialColors));
|
||||
ledStripConfig->ledstrip_visual_beeper = 0;
|
||||
ledStripConfig->ledstrip_aux_channel = THROTTLE;
|
||||
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
ledStripConfig->ledstrip_profile = LED_PROFILE_STATUS;
|
||||
#else
|
||||
ledStripConfig->ledstrip_profile = LED_PROFILE_RACE;
|
||||
#endif
|
||||
ledStripConfig->ledRaceColor = COLOR_ORANGE;
|
||||
#ifndef UNIT_TEST
|
||||
ledStripConfig->ioTag = timerioTagGetByUsage(TIM_USE_LED, 0);
|
||||
#endif
|
||||
|
@ -183,8 +175,9 @@ void pgResetFn_ledStripConfig(ledStripConfig_t *ledStripConfig)
|
|||
|
||||
static int scaledThrottle;
|
||||
static int auxInput;
|
||||
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
static void updateLedRingCounts(void);
|
||||
#endif
|
||||
|
||||
STATIC_UNIT_TESTED void updateDimensions(void)
|
||||
{
|
||||
|
@ -251,10 +244,13 @@ void reevaluateLedConfig(void)
|
|||
{
|
||||
updateLedCount();
|
||||
updateDimensions();
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
updateLedRingCounts();
|
||||
updateRequiredOverlay();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
// get specialColor by index
|
||||
static const hsvColor_t* getSC(ledSpecialColorIds_e index)
|
||||
{
|
||||
|
@ -264,9 +260,10 @@ 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' };
|
||||
#endif
|
||||
|
||||
#define CHUNK_BUFFER_SIZE 11
|
||||
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
bool parseLedStripConfig(int ledIndex, const char *config)
|
||||
{
|
||||
if (ledIndex >= LED_MAX_STRIP_LENGTH)
|
||||
|
@ -781,11 +778,12 @@ static void applyLedGpsLayer(bool updateNow, timeUs_t *timer)
|
|||
|
||||
applyLedHsv(LED_MOV_FUNCTION(LED_FUNCTION_GPS), gpsColor);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define INDICATOR_DEADBAND 25
|
||||
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
static void applyLedIndicatorLayer(bool updateNow, timeUs_t *timer)
|
||||
{
|
||||
static bool flash = 0;
|
||||
|
@ -992,6 +990,7 @@ static uint16_t disabledTimerMask;
|
|||
|
||||
STATIC_ASSERT(timTimerCount <= sizeof(disabledTimerMask) * 8, disabledTimerMask_too_small);
|
||||
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
// function to apply layer.
|
||||
// function must replan self using timer pointer
|
||||
// when updateNow is true (timer triggered), state must be updated first,
|
||||
|
@ -1014,6 +1013,7 @@ static applyLayerFn_timed* layerTable[] = {
|
|||
[timIndicator] = &applyLedIndicatorLayer,
|
||||
[timRing] = &applyLedThrustRingLayer
|
||||
};
|
||||
#endif
|
||||
|
||||
bool isOverlayTypeUsed(ledOverlayId_e overlayType)
|
||||
{
|
||||
|
@ -1038,23 +1038,9 @@ void updateRequiredOverlay(void)
|
|||
disabledTimerMask |= !isOverlayTypeUsed(LED_OVERLAY_INDICATOR) << timIndicator;
|
||||
}
|
||||
|
||||
void ledStripUpdate(timeUs_t currentTimeUs)
|
||||
{
|
||||
if (!(ledStripInitialised && isWS2811LedStripReady())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (IS_RC_MODE_ACTIVE(BOXLEDLOW) && !(ledStripConfig()->ledstrip_visual_beeper && isBeeperOn())) {
|
||||
if (ledStripEnabled) {
|
||||
ledStripDisable();
|
||||
ledStripEnabled = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
ledStripEnabled = true;
|
||||
|
||||
const uint32_t now = currentTimeUs;
|
||||
static void applyStatusProfile(uint32_t now) {
|
||||
|
||||
// apply all layers; triggered timed functions has to update timers
|
||||
// test all led timers, setting corresponding bits
|
||||
uint32_t timActive = 0;
|
||||
for (timId_e timId = 0; timId < timTimerCount; timId++) {
|
||||
|
@ -1074,19 +1060,67 @@ void ledStripUpdate(timeUs_t currentTimeUs)
|
|||
if (!timActive)
|
||||
return; // no change this update, keep old state
|
||||
|
||||
// apply all layers; triggered timed functions has to update timers
|
||||
|
||||
scaledThrottle = ARMING_FLAG(ARMED) ? scaleRange(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, 100) : 0;
|
||||
auxInput = rcData[ledStripConfig()->ledstrip_aux_channel];
|
||||
|
||||
applyLedFixedLayers();
|
||||
|
||||
for (timId_e timId = 0; timId < ARRAYLEN(layerTable); timId++) {
|
||||
uint32_t *timer = &timerVal[timId];
|
||||
bool updateNow = timActive & (1 << timId);
|
||||
(*layerTable[timId])(updateNow, timer);
|
||||
}
|
||||
ws2811UpdateStrip((ledStripFormatRGB_e)ledStripConfig()->ledstrip_grb_rgb);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void applyBeaconProfile(void) {
|
||||
|
||||
bool ledsBlink = millis() % (BEACON_FLASH_PERIOD_MS) < BEACON_FLASH_ON_TIME;
|
||||
if (ledsBlink) {
|
||||
setStripColor(&HSV(WHITE));
|
||||
} else {
|
||||
setStripColor(&HSV(BLACK));
|
||||
}
|
||||
}
|
||||
|
||||
void ledStripUpdate(timeUs_t currentTimeUs)
|
||||
{
|
||||
#ifndef USE_LED_STRIP_STATUS_MODE
|
||||
UNUSED(currentTimeUs);
|
||||
#endif
|
||||
|
||||
if (!(ledStripInitialised && isWS2811LedStripReady())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (((true == ledStripEnabled)
|
||||
|| (ledStripConfig()->ledstrip_visual_beeper && isBeeperOn()))
|
||||
&& !IS_RC_MODE_ACTIVE(BOXLEDLOW)) {
|
||||
|
||||
scaledThrottle = ARMING_FLAG(ARMED) ? scaleRange(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, 100) : 0;
|
||||
auxInput = rcData[ledStripConfig()->ledstrip_aux_channel];
|
||||
|
||||
switch (ledStripConfig()->ledstrip_profile) {
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
case LED_PROFILE_STATUS: {
|
||||
applyStatusProfile(currentTimeUs);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case LED_PROFILE_RACE: {
|
||||
setStripColor(&hsv[ledStripConfig()->ledRaceColor]);
|
||||
break;
|
||||
}
|
||||
case LED_PROFILE_BEACON: {
|
||||
applyBeaconProfile();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ws2811UpdateStrip((ledStripFormatRGB_e) ledStripConfig()->ledstrip_grb_rgb);
|
||||
}
|
||||
else
|
||||
{
|
||||
setStripColor(&HSV(BLACK));
|
||||
ws2811UpdateStrip((ledStripFormatRGB_e)ledStripConfig()->ledstrip_grb_rgb);
|
||||
}
|
||||
}
|
||||
|
||||
bool parseColor(int index, const char *colorConfig)
|
||||
|
@ -1135,6 +1169,7 @@ bool parseColor(int index, const char *colorConfig)
|
|||
return result;
|
||||
}
|
||||
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
/*
|
||||
* Redefine a color in a mode.
|
||||
* */
|
||||
|
@ -1160,6 +1195,7 @@ bool setModeColor(ledModeIndex_e modeIndex, int modeColorIndex, int colorIndex)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ledStripInit(void)
|
||||
{
|
||||
|
@ -1175,12 +1211,39 @@ void ledStripEnable(void)
|
|||
ledStripInitialised = true;
|
||||
|
||||
ws2811LedStripInit(ledStripConfig()->ioTag);
|
||||
ledStripEnabled = true;
|
||||
}
|
||||
|
||||
static void ledStripDisable(void)
|
||||
void ledStripDisable(void)
|
||||
{
|
||||
ledStripEnabled = false;
|
||||
setStripColor(&HSV(BLACK));
|
||||
|
||||
ws2811UpdateStrip((ledStripFormatRGB_e)ledStripConfig()->ledstrip_grb_rgb);
|
||||
}
|
||||
|
||||
|
||||
uint8_t getLedProfile(void)
|
||||
{
|
||||
return ledStripConfig()->ledstrip_profile;
|
||||
}
|
||||
|
||||
void setLedProfile(uint8_t profile)
|
||||
{
|
||||
if (profile < LED_PROFILE_COUNT) {
|
||||
ledStripConfigMutable()->ledstrip_profile = profile;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getLedRaceColor(void)
|
||||
{
|
||||
return ledStripConfig()->ledRaceColor;
|
||||
}
|
||||
|
||||
void setLedRaceColor(uint8_t color)
|
||||
{
|
||||
if (color <= COLOR_DEEP_PINK) {
|
||||
ledStripConfigMutable()->ledRaceColor = color;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -77,6 +77,24 @@
|
|||
#define LED_XY_MASK 0x0F
|
||||
#define CALCULATE_LED_XY(x, y) ((((x) & LED_XY_MASK) << LED_X_BIT_OFFSET) | (((y) & LED_XY_MASK) << LED_Y_BIT_OFFSET))
|
||||
|
||||
typedef enum {
|
||||
COLOR_BLACK = 0,
|
||||
COLOR_WHITE,
|
||||
COLOR_RED,
|
||||
COLOR_ORANGE,
|
||||
COLOR_YELLOW,
|
||||
COLOR_LIME_GREEN,
|
||||
COLOR_GREEN,
|
||||
COLOR_MINT_GREEN,
|
||||
COLOR_CYAN,
|
||||
COLOR_LIGHT_BLUE,
|
||||
COLOR_BLUE,
|
||||
COLOR_DARK_VIOLET,
|
||||
COLOR_MAGENTA,
|
||||
COLOR_DEEP_PINK,
|
||||
COLOR_COUNT
|
||||
} colorId_e;
|
||||
|
||||
typedef enum {
|
||||
LED_MODE_ORIENTATION = 0,
|
||||
LED_MODE_HEADFREE,
|
||||
|
@ -127,6 +145,15 @@ typedef enum {
|
|||
LED_OVERLAY_WARNING
|
||||
} ledOverlayId_e;
|
||||
|
||||
typedef enum {
|
||||
LED_PROFILE_RACE = 0,
|
||||
LED_PROFILE_BEACON,
|
||||
#ifdef USE_LED_STRIP_STATUS_MODE
|
||||
LED_PROFILE_STATUS,
|
||||
#endif
|
||||
LED_PROFILE_COUNT
|
||||
} ledProfile_e;
|
||||
|
||||
typedef struct modeColorIndexes_s {
|
||||
uint8_t color[LED_DIRECTION_COUNT];
|
||||
} modeColorIndexes_t;
|
||||
|
@ -153,6 +180,9 @@ typedef struct ledStripConfig_s {
|
|||
uint8_t ledstrip_aux_channel;
|
||||
ioTag_t ioTag;
|
||||
ledStripFormatRGB_e ledstrip_grb_rgb;
|
||||
ledProfile_e ledstrip_profile;
|
||||
colorId_e ledRaceColor;
|
||||
|
||||
} ledStripConfig_t;
|
||||
|
||||
PG_DECLARE(ledStripConfig_t, ledStripConfig);
|
||||
|
@ -186,6 +216,7 @@ void reevaluateLedConfig(void);
|
|||
|
||||
void ledStripInit(void);
|
||||
void ledStripEnable(void);
|
||||
void ledStripDisable(void);
|
||||
void ledStripUpdate(timeUs_t currentTimeUs);
|
||||
|
||||
bool setModeColor(ledModeIndex_e modeIndex, int modeColorIndex, int colorIndex);
|
||||
|
@ -196,3 +227,8 @@ void applyDefaultModeColors(modeColorIndexes_t *modeColors);
|
|||
void applyDefaultSpecialColors(specialColorIndexes_t *specialColors);
|
||||
|
||||
void updateRequiredOverlay(void);
|
||||
|
||||
uint8_t getLedProfile(void);
|
||||
void setLedProfile(uint8_t profile);
|
||||
uint8_t getLedRaceColor(void);
|
||||
void setLedRaceColor(uint8_t color);
|
||||
|
|
|
@ -234,6 +234,10 @@
|
|||
#define USE_SERIAL_4WAY_BLHELI_BOOTLOADER
|
||||
#endif
|
||||
|
||||
#if !defined(USE_LED_STRIP)
|
||||
#undef USE_LED_STRIP_STATUS_MODE
|
||||
#endif
|
||||
|
||||
#if defined(SIMULATOR_BUILD) || defined(UNIT_TEST)
|
||||
// This feature uses 'arm_math.h', which does not exist for x86.
|
||||
#undef USE_GYRO_DATA_ANALYSE
|
||||
|
|
|
@ -240,6 +240,7 @@
|
|||
#define USE_ABSOLUTE_CONTROL
|
||||
#define USE_HOTT_TEXTMODE
|
||||
#define USE_LED_STRIP
|
||||
#define USE_LED_STRIP_STATUS_MODE
|
||||
#define USE_VARIO
|
||||
#define USE_RX_LINK_QUALITY_INFO
|
||||
#define USE_ESC_SENSOR_TELEMETRY
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# A sample Makefile for building Google Test and using it in user
|
||||
# A sample Makefile for building Google Test and using it in user
|
||||
# tests. Please tweak it to suit your environment and project. You
|
||||
# may want to move it to your project's root directory.
|
||||
#
|
||||
|
@ -156,7 +157,10 @@ ledstrip_unittest_SRC := \
|
|||
$(USER_DIR)/fc/rc_modes.c \
|
||||
$(USER_DIR)/io/ledstrip.c
|
||||
|
||||
|
||||
ledstrip_unittest_DEFINES := \
|
||||
USE_LED_STRIP=
|
||||
|
||||
|
||||
maths_unittest_SRC := \
|
||||
$(USER_DIR)/common/maths.c
|
||||
|
||||
|
@ -187,7 +191,7 @@ rc_controls_unittest_SRC := \
|
|||
$(USER_DIR)/common/bitarray.c \
|
||||
$(USER_DIR)/common/maths.c \
|
||||
$(USER_DIR)/fc/rc_adjustments.c \
|
||||
$(USER_DIR)/fc/rc_modes.c \
|
||||
$(USER_DIR)/fc/rc_modes.c
|
||||
|
||||
|
||||
rx_crsf_unittest_SRC := \
|
||||
|
|
|
@ -351,6 +351,9 @@ void delay(uint32_t ms)
|
|||
}
|
||||
|
||||
uint32_t micros(void) { return 0; }
|
||||
|
||||
uint32_t millis(void) { return 0; }
|
||||
|
||||
bool shouldSoundBatteryAlarm(void) { return false; }
|
||||
bool featureIsEnabled(uint32_t mask) {
|
||||
UNUSED(mask);
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#define USE_TELEMETRY_MAVLINK
|
||||
#define USE_TELEMETRY_SMARTPORT
|
||||
#define USE_LED_STRIP
|
||||
#define USE_LED_STRIP_STATUS_MODE
|
||||
#define USE_SERVOS
|
||||
#define USE_TRANSPONDER
|
||||
#define USE_VCP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue