feat: Support for WS2812 RGB LEDs (#3909)

Co-authored-by: 3djc <lesitewebdejc@hotmail.com>
This commit is contained in:
Raphael Coeffic
2023-10-14 14:06:55 +10:00
committed by GitHub
co-authored by 3djc
parent f8ad3a7bda
commit b22a1b5d32
60 changed files with 788 additions and 122 deletions
+4
View File
@@ -572,6 +572,10 @@ int Boards::getCapability(Board::Type board, Board::Capability capability)
// TX12, TX12MK2, ZORRO, BOXER, T8, TLITE, TPRO, LR3PRO, COMMANDO8
return (IS_FAMILY_HORUS_OR_T16(board) && !IS_HORUS_X12S(board)) || IS_FAMILY_T12(board);
case HasLedStripGPIO:
// No current radio do support that feature
return false;
case SportMaxBaudRate:
if (IS_FAMILY_T16(board) || IS_FLYSKY_NV14(board) || IS_FLYSKY_EL18(board) || IS_TARANIS_X7_ACCESS(board) ||
(IS_TARANIS(board) && !IS_TARANIS_XLITE(board) && !IS_TARANIS_X7(board) && !IS_TARANIS_X9LITE(board)))
+1
View File
@@ -164,6 +164,7 @@ namespace Board {
HasIntModuleHeartbeatGPIO,
HasTrainerModuleCPPM,
HasTrainerModuleSBUS,
HasLedStripGPIO
};
struct SwitchInfo
@@ -127,6 +127,8 @@ QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData
return tr("Set Main Screen");
else if (func == FuncDisableAudioAmp)
return tr("Audio Amp Off");
else if (func == FuncRGBLed)
return tr("RGB leds");
else {
return QString(CPN_STR_UNKNOWN_ITEM);
}
@@ -260,7 +262,8 @@ bool CustomFunctionData::isFuncAvailable(const int index, const ModelData * mode
((index >= FuncAdjustGV1 && index <= FuncAdjustGVLast) && !fw->getCapability(Gvars)) ||
((index == FuncDisableTouch) && !IS_HORUS_OR_TARANIS(fw->getBoard())) ||
((index == FuncSetScreen && !Boards::getCapability(fw->getBoard(), Board::HasColorLcd)) ||
((index == FuncDisableAudioAmp && !Boards::getCapability(fw->getBoard(), Board::HasAudioMuteGPIO))))
((index == FuncDisableAudioAmp && !Boards::getCapability(fw->getBoard(), Board::HasAudioMuteGPIO))) ||
((index == FuncRGBLed && !Boards::getCapability(fw->getBoard(), Board::HasLedStripGPIO))))
);
return !ret;
}
@@ -475,7 +478,8 @@ bool CustomFunctionData::isParamAvailable() const
FuncBindExternalModule,
FuncRacingMode,
FuncDisableTouch,
FuncDisableAudioAmp
FuncDisableAudioAmp,
FuncRGBLed
};
return funcList.contains(func) ? false : true;
@@ -73,6 +73,7 @@ enum AssignFunc {
FuncDisableTouch,
FuncSetScreen,
FuncDisableAudioAmp,
FuncRGBLed,
FuncCount,
FuncReserve = -1
};
@@ -39,7 +39,8 @@ static bool fnHasRepeat(AssignFunc fn)
|| (fn == FuncPlayHaptic)
|| (fn == FuncPlaySound)
|| (fn == FuncSetScreen)
|| (fn == FuncPlayScript);
|| (fn == FuncPlayScript)
|| (fn == FuncRGBLed);
}
static const YamlLookupTable customFnLut = {
@@ -68,6 +69,7 @@ static const YamlLookupTable customFnLut = {
{ FuncDisableTouch, "DISABLE_TOUCH" },
{ FuncSetScreen, "SET_SCREEN"},
{ FuncDisableAudioAmp, "DISABLE_AUDIO_AMP" },
{ FuncRGBLed, "RGB_LED" },
};
static const YamlLookupTable trainerLut = {
@@ -172,6 +174,7 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
def += temp;
} break;
case FuncPlayScript:
case FuncRGBLed:
def += std::string(rhs.paramarm);
break;
case FuncReset:
@@ -232,7 +235,7 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
if (add_comma) {
def += ",";
}
if (rhs.func == FuncPlayScript) {
if (rhs.func == FuncPlayScript || rhs.func == FuncRGBLed) {
def += ((rhs.repeatParam == 0) ? "On" : "1x");
} else if (rhs.repeatParam == 0) {
def += "1x";
@@ -297,6 +300,7 @@ bool convert<CustomFunctionData>::decode(const Node& node,
file_str.resize(getCurrentFirmware()->getCapability(VoicesMaxLength));
strncpy(rhs.paramarm, file_str.c_str(), sizeof(rhs.paramarm) - 1);
} break;
case FuncRGBLed:
case FuncPlayScript: {
std::string file_str;
getline(def, file_str, ',');
@@ -388,7 +392,7 @@ bool convert<CustomFunctionData>::decode(const Node& node,
} else if(fnHasRepeat(rhs.func)) {
std::string repeat;
getline(def, repeat);
if (rhs.func == FuncPlayScript) {
if (rhs.func == FuncPlayScript || rhs.func == FuncRGBLed) {
rhs.repeatParam = (repeat == "1x") ? 1 : 0;
} else if (repeat == "1x") {
rhs.repeatParam = 0;
+15 -3
View File
@@ -96,6 +96,18 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
}
}
if (IS_STM32(firmware->getBoard())) {
scriptsSet = getFilesSet(g.profile[g.id()].sdPath() + "/SCRIPTS/RGBLED", QStringList() << "*.lua", firmware->getCapability(VoicesMaxLength));
for (int i = 0; i < fswCapability; i++) {
if (functions[i].func == FuncRGBLed) {
QString temp = functions[i].paramarm;
if (!temp.isEmpty()) {
scriptsSet.insert(temp);
}
}
}
}
CompanionIcon playIcon("play.png");
playIcon.addImage("stop.png", QIcon::Normal, QIcon::On);
@@ -194,7 +206,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
tableLayout->addLayout(i, 4, repeatLayout);
fswtchRepeat[i] = new QComboBox(this);
fswtchRepeat[i]->setProperty("index", i);
if (functions[i].func == FuncPlayScript)
if (functions[i].func == FuncPlayScript || functions[i].func == FuncRGBLed)
fswtchRepeat[i]->setModel(tabModelFactory->getItemModel(repeatLuaId));
else
fswtchRepeat[i]->setModel(tabModelFactory->getItemModel(repeatId));
@@ -339,7 +351,7 @@ void CustomFunctionsPanel::functionEdited()
functions[index].clear();
functions[index].swtch = swtch;
functions[index].func = (AssignFunc)fswtchFunc[index]->currentData().toInt();
if (functions[index].func == FuncPlayScript)
if (functions[index].func == FuncPlayScript || functions[index].func == FuncRGBLed)
fswtchRepeat[index]->setModel(tabModelFactory->getItemModel(repeatLuaId));
else
fswtchRepeat[index]->setModel(tabModelFactory->getItemModel(repeatId));
@@ -541,7 +553,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM;
}
}
else if (func == FuncPlayScript) {
else if (func == FuncPlayScript || func == FuncRGBLed) {
widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM | CUSTOM_FUNCTION_REPEAT;
if (modified) {
Helpers::getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, 8);