Skip to content

Commit cce416b

Browse files
authored
feat(cpn): add customisable switch colors to Companion YAML file handling (#5796)
1 parent e41680b commit cce416b

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

companion/src/firmwares/boards.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ int Boards::getCapability(Board::Type board, Board::Capability capability)
405405
case Surface:
406406
return IS_RADIOMASTER_MT12(board);
407407

408+
case FunctionSwitchColors:
409+
return IS_RADIOMASTER_GX12(board);
410+
408411
default:
409412
return getBoardJson(board)->getCapability(capability);
410413
}

companion/src/firmwares/boards.h

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ namespace Board {
209209
FlexInputs,
210210
FlexSwitches,
211211
FunctionSwitches,
212+
FunctionSwitchColors,
212213
Gyros,
213214
GyroAxes,
214215
HasAudioMuteGPIO,

companion/src/firmwares/edgetx/yaml_modeldata.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,19 @@ Node convert<ModelData>::encode(const ModelData& rhs)
12061206
node["switchNames"][std::to_string(i)]["val"] = rhs.functionSwitchNames[i];
12071207
}
12081208
}
1209+
1210+
if (Boards::getCapability(board, Board::FunctionSwitchColors)) {
1211+
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
1212+
node["functionSwitchLedONColor"][std::to_string(i)]["r"] = rhs.functionSwitchLedONColor[i].r;
1213+
node["functionSwitchLedONColor"][std::to_string(i)]["g"] = rhs.functionSwitchLedONColor[i].g;
1214+
node["functionSwitchLedONColor"][std::to_string(i)]["b"] = rhs.functionSwitchLedONColor[i].b;
1215+
}
1216+
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
1217+
node["functionSwitchLedOFFColor"][std::to_string(i)]["r"] = rhs.functionSwitchLedOFFColor[i].r;
1218+
node["functionSwitchLedOFFColor"][std::to_string(i)]["g"] = rhs.functionSwitchLedOFFColor[i].g;
1219+
node["functionSwitchLedOFFColor"][std::to_string(i)]["b"] = rhs.functionSwitchLedOFFColor[i].b;
1220+
}
1221+
}
12091222
}
12101223

12111224
// Custom USB joytsick mapping
@@ -1474,6 +1487,20 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
14741487
node["functionSwitchStartConfig"] >> rhs.functionSwitchStartConfig;
14751488
node["functionSwitchLogicalState"] >> rhs.functionSwitchLogicalState;
14761489
node["switchNames"] >> rhs.functionSwitchNames;
1490+
if (node["functionSwitchLedONColor"]) {
1491+
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
1492+
node["functionSwitchLedONColor"][std::to_string(i)]["r"] >> rhs.functionSwitchLedONColor[i].r;
1493+
node["functionSwitchLedONColor"][std::to_string(i)]["g"] >> rhs.functionSwitchLedONColor[i].g;
1494+
node["functionSwitchLedONColor"][std::to_string(i)]["b"] >> rhs.functionSwitchLedONColor[i].b;
1495+
}
1496+
}
1497+
if (node["functionSwitchLedOFFColor"]) {
1498+
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
1499+
node["functionSwitchLedOFFColor"][std::to_string(i)]["r"] >> rhs.functionSwitchLedOFFColor[i].r;
1500+
node["functionSwitchLedOFFColor"][std::to_string(i)]["g"] >> rhs.functionSwitchLedOFFColor[i].g;
1501+
node["functionSwitchLedOFFColor"][std::to_string(i)]["b"] >> rhs.functionSwitchLedOFFColor[i].b;
1502+
}
1503+
}
14771504

14781505
// Custom USB joytsick mapping
14791506
node["usbJoystickExtMode"] >> rhs.usbJoystickExtMode;

companion/src/firmwares/modeldata.h

+11
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ class USBJoystickChData {
104104
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(USBJoystickChData)); }
105105
};
106106

107+
class RGBLedColor {
108+
public:
109+
RGBLedColor() { clear(); }
110+
int r;
111+
int g;
112+
int b;
113+
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(RGBLedColor)); }
114+
};
115+
107116
class ModelData {
108117
Q_DECLARE_TR_FUNCTIONS(ModelData)
109118

@@ -232,6 +241,8 @@ class ModelData {
232241
unsigned int functionSwitchStartConfig;
233242
unsigned int functionSwitchLogicalState;
234243
char functionSwitchNames[CPN_MAX_SWITCHES_FUNCTION][HARDWARE_NAME_LEN + 1];
244+
RGBLedColor functionSwitchLedONColor[CPN_MAX_SWITCHES_FUNCTION];
245+
RGBLedColor functionSwitchLedOFFColor[CPN_MAX_SWITCHES_FUNCTION];
235246

236247
// Custom USB joytsick mapping
237248
unsigned int usbJoystickExtMode;

0 commit comments

Comments
 (0)