feat(cpn): add customisable switch colors to Companion YAML file handling (#5796)

This commit is contained in:
philmoz
2025-01-19 11:23:46 +10:00
committed by GitHub
parent e41680bf87
commit cce416b8df
4 changed files with 42 additions and 0 deletions
+3
View File
@@ -405,6 +405,9 @@ int Boards::getCapability(Board::Type board, Board::Capability capability)
case Surface:
return IS_RADIOMASTER_MT12(board);
case FunctionSwitchColors:
return IS_RADIOMASTER_GX12(board);
default:
return getBoardJson(board)->getCapability(capability);
}
+1
View File
@@ -209,6 +209,7 @@ namespace Board {
FlexInputs,
FlexSwitches,
FunctionSwitches,
FunctionSwitchColors,
Gyros,
GyroAxes,
HasAudioMuteGPIO,
@@ -1206,6 +1206,19 @@ Node convert<ModelData>::encode(const ModelData& rhs)
node["switchNames"][std::to_string(i)]["val"] = rhs.functionSwitchNames[i];
}
}
if (Boards::getCapability(board, Board::FunctionSwitchColors)) {
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
node["functionSwitchLedONColor"][std::to_string(i)]["r"] = rhs.functionSwitchLedONColor[i].r;
node["functionSwitchLedONColor"][std::to_string(i)]["g"] = rhs.functionSwitchLedONColor[i].g;
node["functionSwitchLedONColor"][std::to_string(i)]["b"] = rhs.functionSwitchLedONColor[i].b;
}
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
node["functionSwitchLedOFFColor"][std::to_string(i)]["r"] = rhs.functionSwitchLedOFFColor[i].r;
node["functionSwitchLedOFFColor"][std::to_string(i)]["g"] = rhs.functionSwitchLedOFFColor[i].g;
node["functionSwitchLedOFFColor"][std::to_string(i)]["b"] = rhs.functionSwitchLedOFFColor[i].b;
}
}
}
// Custom USB joytsick mapping
@@ -1474,6 +1487,20 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
node["functionSwitchStartConfig"] >> rhs.functionSwitchStartConfig;
node["functionSwitchLogicalState"] >> rhs.functionSwitchLogicalState;
node["switchNames"] >> rhs.functionSwitchNames;
if (node["functionSwitchLedONColor"]) {
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
node["functionSwitchLedONColor"][std::to_string(i)]["r"] >> rhs.functionSwitchLedONColor[i].r;
node["functionSwitchLedONColor"][std::to_string(i)]["g"] >> rhs.functionSwitchLedONColor[i].g;
node["functionSwitchLedONColor"][std::to_string(i)]["b"] >> rhs.functionSwitchLedONColor[i].b;
}
}
if (node["functionSwitchLedOFFColor"]) {
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
node["functionSwitchLedOFFColor"][std::to_string(i)]["r"] >> rhs.functionSwitchLedOFFColor[i].r;
node["functionSwitchLedOFFColor"][std::to_string(i)]["g"] >> rhs.functionSwitchLedOFFColor[i].g;
node["functionSwitchLedOFFColor"][std::to_string(i)]["b"] >> rhs.functionSwitchLedOFFColor[i].b;
}
}
// Custom USB joytsick mapping
node["usbJoystickExtMode"] >> rhs.usbJoystickExtMode;
+11
View File
@@ -104,6 +104,15 @@ class USBJoystickChData {
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(USBJoystickChData)); }
};
class RGBLedColor {
public:
RGBLedColor() { clear(); }
int r;
int g;
int b;
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(RGBLedColor)); }
};
class ModelData {
Q_DECLARE_TR_FUNCTIONS(ModelData)
@@ -232,6 +241,8 @@ class ModelData {
unsigned int functionSwitchStartConfig;
unsigned int functionSwitchLogicalState;
char functionSwitchNames[CPN_MAX_SWITCHES_FUNCTION][HARDWARE_NAME_LEN + 1];
RGBLedColor functionSwitchLedONColor[CPN_MAX_SWITCHES_FUNCTION];
RGBLedColor functionSwitchLedOFFColor[CPN_MAX_SWITCHES_FUNCTION];
// Custom USB joytsick mapping
unsigned int usbJoystickExtMode;