diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 6c4f53ded..870d14cde 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -45,6 +45,7 @@ set(firmwares_SRCS edgetx/yaml_logicalswitchdata.cpp edgetx/yaml_customfunctiondata.cpp edgetx/yaml_sensordata.cpp + edgetx/yaml_screendata.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/customisation_data.cpp b/companion/src/firmwares/customisation_data.cpp index 34489aa59..5de5fb803 100644 --- a/companion/src/firmwares/customisation_data.cpp +++ b/companion/src/firmwares/customisation_data.cpp @@ -85,6 +85,25 @@ inline const char * zoneOptionValueEnumToString(ZoneOptionValueEnum zovenum) { } } +static const ZoneOptionValueTyped zero_widget_option = { + ZOV_Unsigned, {0} +}; + +bool ZoneOptionValueTyped::isEmpty() const +{ + return !memcmp((void*)this, &zero_widget_option, sizeof(zero_widget_option)); +} + +bool ZonePersistentData::isEmpty() const +{ + return strlen(widgetName) == 0; +} + +bool RadioLayout::CustomScreenData::isEmpty() const +{ + return strlen(layoutId) == 0; +} + void RadioTheme::init(const char* themeName, ThemeData& themeData) { memset(&themeData, 0, sizeof(ThemeData)); diff --git a/companion/src/firmwares/customisation_data.h b/companion/src/firmwares/customisation_data.h index baad3c828..457be6c0c 100644 --- a/companion/src/firmwares/customisation_data.h +++ b/companion/src/firmwares/customisation_data.h @@ -20,6 +20,7 @@ #pragma once #include "constants.h" +#include "rawsource.h" #include @@ -58,6 +59,8 @@ struct ZoneOptionValue // union in radio/src/datastructs.h int signedValue; unsigned int boolValue; char stringValue[LEN_ZONE_OPTION_STRING + 1]; + RawSource sourceValue; + unsigned int colorValue; }; enum ZoneOptionValueEnum { @@ -65,7 +68,9 @@ enum ZoneOptionValueEnum { ZOV_Signed, ZOV_Bool, ZOV_String, - ZOV_LAST = ZOV_String + ZOV_Source, + ZOV_Color, + ZOV_LAST = ZOV_Color }; struct ZoneOption @@ -93,6 +98,8 @@ struct ZoneOptionValueTyped { ZoneOptionValueEnum type; ZoneOptionValue value; + + bool isEmpty() const; }; struct WidgetPersistentData { @@ -102,6 +109,8 @@ struct WidgetPersistentData { struct ZonePersistentData { char widgetName[WIDGET_NAME_LEN + 1]; WidgetPersistentData widgetData; + + bool isEmpty() const; }; template @@ -141,6 +150,8 @@ class RadioLayout struct CustomScreenData { char layoutId[LAYOUT_ID_LEN + 1]; LayoutPersistentData layoutPersistentData; + + bool isEmpty() const; }; struct CustomScreens { diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index b76e1fd80..ec4af1e8c 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -28,6 +28,7 @@ #include "yaml_logicalswitchdata.h" #include "yaml_customfunctiondata.h" #include "yaml_sensordata.h" +#include "yaml_screendata.h" #include "modeldata.h" #include "output_data.h" @@ -526,9 +527,13 @@ Node convert::encode(const ModelData& rhs) node["toplcdTimer"] = rhs.toplcdTimer; - // B&W only - // customScreens - // topBarData + for (int i=0; i::decode(const Node& node, ModelData& rhs) // customScreens // topBarData + node["screenData"] >> rhs.customScreens.customScreenData; + node["topbarData"] >> rhs.topBarData; + node["view"] >> rhs.view; node["modelRegistrationID"] >> rhs.registrationId; diff --git a/companion/src/firmwares/edgetx/yaml_screendata.cpp b/companion/src/firmwares/edgetx/yaml_screendata.cpp new file mode 100644 index 000000000..ab26f4f49 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_screendata.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_screendata.h" +#include "yaml_rawsource.h" +#include "yaml_ops.h" + +static const YamlLookupTable zoneOptionValueEnum = { + {ZOV_Unsigned, "Unsigned"}, {ZOV_Signed, "Signed"}, {ZOV_Bool, "Bool"}, + {ZOV_String, "String"}, {ZOV_Source, "Source"}, {ZOV_Color, "Color"}, +}; + +namespace YAML +{ +ENUM_CONVERTER(ZoneOptionValueEnum, zoneOptionValueEnum); + +Node convert::encode(const ZoneOptionValueTyped& rhs) +{ + Node node, value; + node["type"] = rhs.type; + + switch (rhs.type) { + case ZOV_Unsigned: + value["unsignedValue"] = rhs.value.unsignedValue; + break; + case ZOV_Signed: + value["signedValue"] = rhs.value.signedValue; + break; + case ZOV_Bool: + value["boolValue"] = rhs.value.boolValue; + break; + case ZOV_Source: + value["sourceValue"] = rhs.value.sourceValue; + break; + case ZOV_Color: + value["colorValue"] = rhs.value.colorValue; + break; + default: + break; + } + node["value"] = value; + return node; +} + +bool convert::decode(const Node& node, + ZoneOptionValueTyped& rhs) +{ + node["type"] >> rhs.type; + if (node["value"]) { + Node value = node["value"]; + if (value.IsMap()) { + value["unsignedValue"] >> rhs.value.unsignedValue; + value["signedValue"] >> rhs.value.signedValue; + value["boolValue"] >> rhs.value.boolValue; + value["stringValue"] >> rhs.value.stringValue; + value["sourceValue"] >> rhs.value.sourceValue; + value["colorValue"] >> rhs.value.colorValue; + } + } + return true; +} + +template <> +struct convert { + static Node encode(const WidgetPersistentData& rhs) + { + Node node; + for (int i=0; i> rhs.options; + return true; + } +}; + +Node convert::encode(const ZonePersistentData& rhs) +{ + Node node; + node["widgetName"] = rhs.widgetName; + node["widgetData"] = rhs.widgetData; + return node; +} + +bool convert::decode(const Node& node, ZonePersistentData& rhs) +{ + node["widgetName"] >> rhs.widgetName; + node["widgetData"] >> rhs.widgetData; + return true; +} + +Node convert::encode(const ScreenData& rhs) +{ + Node node; + node["LayoutId"] = rhs.layoutId; + node["layoutData"] = rhs.layoutPersistentData; + return node; +} + +bool convert::decode(const Node& node, ScreenData& rhs) +{ + node["LayoutId"] >> rhs.layoutId; + node["layoutData"] >> rhs.layoutPersistentData; + return true; +} +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_screendata.h b/companion/src/firmwares/edgetx/yaml_screendata.h new file mode 100644 index 000000000..81349e588 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_screendata.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "customisation_data.h" + +namespace YAML +{ +template <> +struct convert { + static Node encode(const ZonePersistentData& rhs); + static bool decode(const Node& node, ZonePersistentData& rhs); +}; + +template <> +struct convert { + static Node encode(const ZoneOptionValueTyped& rhs); + static bool decode(const Node& node, ZoneOptionValueTyped& rhs); +}; + +template +struct convert > { + typedef WidgetsContainerPersistentData PersistentData; + static Node encode(const PersistentData& rhs) + { + Node node; + for (int i=0; i 0) { + node["zones"][std::to_string(i)] = rhs.zones[i]; + } + } + for(int i=0; i> rhs.zones; + node["options"] >> rhs.options; + return true; + } +}; + +typedef RadioLayout::CustomScreenData ScreenData; + +template <> +struct convert { + static Node encode(const ScreenData& rhs); + static bool decode(const Node& node, ScreenData& rhs); +}; +} // namespace YAML