Skip to content
Draft
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
4 changes: 2 additions & 2 deletions companion/src/firmwares/boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#include "boards.h"
#include "macros.h"
#include "compounditemmodels.h"
#include "moduledata.h"
#include "helpers.h"
#include "boardfactories.h"
#include "generalsettings.h"
#include "modeldata.h"

// TODO remove all those constants
// Update: These are now all only used within this class.
Expand Down Expand Up @@ -330,7 +330,7 @@ int Boards::getCapability(Board::Type board, Board::Capability capability)

case FunctionSwitchGroups:
if (getCapability(board, FunctionSwitches)) {
return IS_RADIOMASTER_GX12(board) ? 4 : 3;
return IS_RADIOMASTER_GX12(board) ? CPN_MAX_CUSTOMSWITCH_GROUPS : 3;
}
return 0;

Expand Down
124 changes: 111 additions & 13 deletions companion/src/firmwares/customisation_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@

ZoneOptionValue::ZoneOptionValue()
{
unsignedValue = 0;
signedValue = 0;
boolValue = 0;
stringValue.clear();
sourceValue.clear();
colorValue = 0;
clear();
}

ZoneOptionValue::ZoneOptionValue(const ZoneOptionValue & src)
{
copy(src);
}

ZoneOptionValue & ZoneOptionValue::operator=(const ZoneOptionValue & src)
{
copy(src);
return *this;
}

void ZoneOptionValue::copy(const ZoneOptionValue & src)
{
unsignedValue = src.unsignedValue;
signedValue = src.signedValue;
boolValue = src.boolValue;
stringValue = src.stringValue;
sourceValue = src.sourceValue;
colorValue = src.colorValue;
}

bool ZoneOptionValue::isEmpty() const
Expand All @@ -43,9 +59,14 @@ bool ZoneOptionValue::isEmpty() const
stringValue.empty() && sourceValue.toValue() == 0;
}

ZoneOptionValueTyped::ZoneOptionValueTyped()
void ZoneOptionValue::clear()
{
type = ZOV_Unsigned;
unsignedValue = 0;
signedValue = 0;
boolValue = 0;
stringValue.clear();
sourceValue.clear();
colorValue = 0;
}

inline void setZoneOptionValue(ZoneOptionValue& zov, bool value)
Expand Down Expand Up @@ -107,31 +128,108 @@ inline const char * zoneOptionValueEnumToString(ZoneOptionValueEnum zovenum) {
}
}

static const ZoneOptionValueTyped zero_widget_option = {};
ZoneOptionValueTyped::ZoneOptionValueTyped()
{
clear();
}

bool ZoneOptionValueTyped::isEmpty() const
{
return type == ZOV_Unsigned && value.isEmpty();
}

void ZoneOptionValueTyped::clear()
{
type = ZOV_Unsigned;
value.clear();
}

void WidgetPersistentData::clear()
{
for (int i = 0; i < MAX_WIDGET_OPTIONS; i += 1)
options[i].clear();
}

ZonePersistentData::ZonePersistentData(const ZonePersistentData & src)
{
copy(src);
}

ZonePersistentData & ZonePersistentData::operator=(const ZonePersistentData & src)
{
copy(src);
return *this;
}

void ZonePersistentData::copy(const ZonePersistentData & src)
{
widgetName = src.widgetName;
widgetData = src.widgetData;
}

bool ZonePersistentData::isEmpty() const
{
return widgetName.empty();
}

void ZonePersistentData::clear()
{
widgetName.clear();
widgetData.clear();
}

RadioLayout::CustomScreenData::CustomScreenData(const RadioLayout::CustomScreenData & src)
{
copy(src);
}

RadioLayout::CustomScreenData & RadioLayout::CustomScreenData::operator=(const RadioLayout::CustomScreenData & src)
{
copy(src);
return *this;
}

void RadioLayout::CustomScreenData::copy(const RadioLayout::CustomScreenData & src)
{
layoutId = src.layoutId;
layoutPersistentData = src.layoutPersistentData;
}

bool RadioLayout::CustomScreenData::isEmpty() const
{
return layoutId.empty();
}

void RadioLayout::CustomScreenData::clear()
{
layoutId.clear();
layoutPersistentData.clear();
}

RadioLayout::CustomScreens::CustomScreens(const RadioLayout::CustomScreens & src)
{
copy(src);
}

RadioLayout::CustomScreens & RadioLayout::CustomScreens::operator=(const RadioLayout::CustomScreens & src)
{
copy(src);
return *this;
}

void RadioLayout::CustomScreens::copy(const RadioLayout::CustomScreens & src)
{
for (int i = 0; i < MAX_CUSTOM_SCREENS; i++)
customScreenData[i] = src.customScreenData[i];
}

void RadioLayout::CustomScreens::clear()
{
for (int i = 0; i < MAX_CUSTOM_SCREENS; i++) {
customScreenData[i] = CustomScreenData();
}
for (int i = 0; i < MAX_CUSTOM_SCREENS; i++)
customScreenData[i].clear();
}

void RadioLayout::init(const char* layoutId, CustomScreens& customScreens)
void RadioLayout::init(const std::string layoutId, CustomScreens& customScreens)
{
customScreens.clear();

Expand Down
31 changes: 30 additions & 1 deletion companion/src/firmwares/customisation_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ struct ZoneOptionValue // union in radio/src/datastructs.h
unsigned int colorValue;

ZoneOptionValue();
ZoneOptionValue(const ZoneOptionValue & src);
ZoneOptionValue & operator=(const ZoneOptionValue & src);

void clear();
void copy(const ZoneOptionValue & src);
bool isEmpty() const;
};

Expand Down Expand Up @@ -111,20 +116,26 @@ struct ZoneOptionValueTyped
ZoneOptionValue value;

ZoneOptionValueTyped();
void clear();
bool isEmpty() const;
};

struct WidgetPersistentData {
ZoneOptionValueTyped options[MAX_WIDGET_OPTIONS];

WidgetPersistentData() {}
void clear();
};

struct ZonePersistentData {
std::string widgetName;
WidgetPersistentData widgetData;

ZonePersistentData() {}
ZonePersistentData(const ZonePersistentData & src);
ZonePersistentData & operator=(const ZonePersistentData & src);
void clear();
void copy(const ZonePersistentData & src);
bool isEmpty() const;
};

Expand All @@ -134,6 +145,14 @@ struct WidgetsContainerPersistentData {
ZoneOptionValueTyped options[O];

WidgetsContainerPersistentData() {}
void clear() {
for (int i = 0; i < N; i++) {
zones[i].clear();
}
for (int i = 0; i < O; i++) {
options[i].clear();
}
}
};

typedef WidgetsContainerPersistentData<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
Expand All @@ -152,14 +171,24 @@ class RadioLayout
LayoutPersistentData layoutPersistentData;

CustomScreenData() {}
CustomScreenData(const CustomScreenData & src);
CustomScreenData & operator=(const CustomScreenData & src);

void clear();
void copy(const CustomScreenData & src);
bool isEmpty() const;
};

struct CustomScreens {
CustomScreenData customScreenData[MAX_CUSTOM_SCREENS];

CustomScreens() {}
CustomScreens(const CustomScreens & src);
CustomScreens & operator=(const CustomScreens & src);

void clear();
void copy(const CustomScreens & src);
};

static void init(const char * layoutId, CustomScreens & customScreens);
static void init(const std::string layoutId, CustomScreens & customScreens);
};
27 changes: 15 additions & 12 deletions companion/src/firmwares/edgetx/yaml_modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,12 +984,12 @@ struct convert<FrSkyScreenData> {
};

template <>
struct convert<customSwitch> {
static Node encode(const customSwitch& rhs);
static bool decode(const Node& node, customSwitch& rhs);
struct convert<CustomSwitchData> {
static Node encode(const CustomSwitchData& rhs);
static bool decode(const Node& node, CustomSwitchData& rhs);
};

Node convert<customSwitch>::encode(const customSwitch& rhs)
Node convert<CustomSwitchData>::encode(const CustomSwitchData& rhs)
{
Node node;
node["type"] = cfsSwitchConfig << rhs.type;
Expand All @@ -1006,7 +1006,7 @@ Node convert<customSwitch>::encode(const customSwitch& rhs)
return node;
}

bool convert<customSwitch>::decode(const Node& node, customSwitch& rhs)
bool convert<CustomSwitchData>::decode(const Node& node, CustomSwitchData& rhs)
{
if (!node.IsMap()) return false;

Expand Down Expand Up @@ -1254,7 +1254,7 @@ Node convert<ModelData>::encode(const ModelData& rhs)
if (topbarData && topbarData.IsMap()) {
node["topbarData"] = topbarData;
}
for (int i = 0; i < MAX_TOPBAR_ZONES; i += 1)
for (int i = 0; i < MAX_TOPBAR_ZONES; i++)
if (rhs.topbarWidgetWidth[i] > 0)
node["topbarWidgetWidth"][std::to_string(i)]["val"] = (int)rhs.topbarWidgetWidth[i];
node["view"] = rhs.view;
Expand All @@ -1265,14 +1265,17 @@ Node convert<ModelData>::encode(const ModelData& rhs)

int funcSwCnt = Boards::getCapability(board, Board::FunctionSwitches);
if (funcSwCnt) {
for (int i = 0; i < funcSwCnt; i += 1) {
for (int i = 0; i < funcSwCnt; i++) {
int sw = Boards::getSwitchIndexForCFS(i);
std::string tag = Boards::getSwitchYamlName(sw, BoardJson::YLT_CONFIG).toStdString();
node["customSwitches"][tag] = rhs.customSwitches[i];
}

for (int i = 1; i < 4; i += 1) {
node["cfsGroupOn"][std::to_string(i)]["v"] = rhs.cfsGroupOn[i];
int funcSwGrps = Boards::getCapability(board, Board::FunctionSwitchGroups);
if (funcSwGrps) {
for (int i = 1; i <= funcSwGrps; i++) {
node["cfsGroupOn"][std::to_string(i)]["v"] = rhs.cfsGroupOn[i];
}
}
}

Expand Down Expand Up @@ -1559,7 +1562,7 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
rhs.customSwitches[i].group = v & 3;
v >>= 2;
}
for (int i = 0; i < 4; i += 1) {
for (int i = 0; i < CPN_MAX_CUSTOMSWITCH_GROUPS; i += 1) {
rhs.cfsGroupOn[i] = v & 1;
v >>= 1;
}
Expand Down Expand Up @@ -1601,16 +1604,16 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
}
}
}
int funcSwCnt = Boards::getCapability(board, Board::FunctionSwitches);
if (node["customSwitches"]) {
int funcSwCnt = Boards::getCapability(board, Board::FunctionSwitches);
for (int i = 0; i < funcSwCnt; i += 1) {
int sw = Boards::getSwitchIndexForCFS(i);
std::string tag = Boards::getSwitchYamlName(sw, BoardJson::YLT_CONFIG).toStdString();
node["customSwitches"][tag] >> rhs.customSwitches[i];
}
}
if (node["cfsGroupOn"]) {
for (int i = 1; i < 4; i += 1) {
for (int i = 1; i < CPN_MAX_CUSTOMSWITCH_GROUPS; i += 1) {
if (node["cfsGroupOn"][std::to_string(i)]) {
node["cfsGroupOn"][std::to_string(i)]["v"] >> rhs.cfsGroupOn[i];
}
Expand Down
Loading