Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions companion/src/firmwares/boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions companion/src/firmwares/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ namespace Board {
FlexInputs,
FlexSwitches,
FunctionSwitches,
FunctionSwitchColors,
Gyros,
GyroAxes,
HasAudioMuteGPIO,
Expand Down
27 changes: 27 additions & 0 deletions companion/src/firmwares/edgetx/yaml_modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions companion/src/firmwares/modeldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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;
Expand Down
Loading