Add screen / topbar data

This commit is contained in:
Raphael Coeffic
2021-12-31 10:53:10 +01:00
parent 9409503728
commit 2a1cc9719e
6 changed files with 244 additions and 4 deletions
+1
View File
@@ -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
)
@@ -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));
+12 -1
View File
@@ -20,6 +20,7 @@
#pragma once
#include "constants.h"
#include "rawsource.h"
#include <QtCore>
@@ -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<int N, int O>
@@ -141,6 +150,8 @@ class RadioLayout
struct CustomScreenData {
char layoutId[LAYOUT_ID_LEN + 1];
LayoutPersistentData layoutPersistentData;
bool isEmpty() const;
};
struct CustomScreens {
@@ -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<ModelData>::encode(const ModelData& rhs)
node["toplcdTimer"] = rhs.toplcdTimer;
// B&W only
// customScreens
// topBarData
for (int i=0; i<MAX_CUSTOM_SCREENS; i++) {
const auto& csd = rhs.customScreens.customScreenData[i];
if (!csd.isEmpty()) {
node["screenData"][std::to_string(i)] = csd;
}
}
node["topbarData"] = rhs.topBarData;
node["view"] = rhs.view;
node["modelRegistrationID"] = rhs.registrationId;
@@ -616,6 +621,9 @@ bool convert<ModelData>::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;
@@ -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<ZoneOptionValueTyped>::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<ZoneOptionValueTyped>::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<WidgetPersistentData> {
static Node encode(const WidgetPersistentData& rhs)
{
Node node;
for (int i=0; i<MAX_WIDGET_OPTIONS; i++) {
if (!rhs.options[i].isEmpty()) {
node["options"][std::to_string(i)] = rhs.options[i];
}
}
return node;
}
static bool decode(const Node& node, WidgetPersistentData& rhs)
{
node["options"] >> rhs.options;
return true;
}
};
Node convert<ZonePersistentData>::encode(const ZonePersistentData& rhs)
{
Node node;
node["widgetName"] = rhs.widgetName;
node["widgetData"] = rhs.widgetData;
return node;
}
bool convert<ZonePersistentData>::decode(const Node& node, ZonePersistentData& rhs)
{
node["widgetName"] >> rhs.widgetName;
node["widgetData"] >> rhs.widgetData;
return true;
}
Node convert<ScreenData>::encode(const ScreenData& rhs)
{
Node node;
node["LayoutId"] = rhs.layoutId;
node["layoutData"] = rhs.layoutPersistentData;
return node;
}
bool convert<ScreenData>::decode(const Node& node, ScreenData& rhs)
{
node["LayoutId"] >> rhs.layoutId;
node["layoutData"] >> rhs.layoutPersistentData;
return true;
}
} // namespace YAML
@@ -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<ZonePersistentData> {
static Node encode(const ZonePersistentData& rhs);
static bool decode(const Node& node, ZonePersistentData& rhs);
};
template <>
struct convert<ZoneOptionValueTyped> {
static Node encode(const ZoneOptionValueTyped& rhs);
static bool decode(const Node& node, ZoneOptionValueTyped& rhs);
};
template <int N, int O>
struct convert<WidgetsContainerPersistentData<N,O> > {
typedef WidgetsContainerPersistentData<N,O> PersistentData;
static Node encode(const PersistentData& rhs)
{
Node node;
for (int i=0; i<N; i++) {
if (strlen(rhs.zones[i].widgetName) > 0) {
node["zones"][std::to_string(i)] = rhs.zones[i];
}
}
for(int i=0; i<O; i++) {
if (!rhs.options[i].isEmpty()) {
node["options"][std::to_string(i)] = rhs.options[i];
}
}
return node;
}
static bool decode(const Node& node, PersistentData& rhs)
{
node["zones"] >> rhs.zones;
node["options"] >> rhs.options;
return true;
}
};
typedef RadioLayout::CustomScreenData ScreenData;
template <>
struct convert<ScreenData> {
static Node encode(const ScreenData& rhs);
static bool decode(const Node& node, ScreenData& rhs);
};
} // namespace YAML