From a3b9d9ff7f6bf3c50788181a92391de457a4bd54 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 13 Sep 2021 12:30:07 +0200 Subject: [PATCH] Re-enable customisation data --- companion/src/firmwares/CMakeLists.txt | 1 + .../src/firmwares/customisation_data.cpp | 138 ++++++++++++++++++ companion/src/firmwares/customisation_data.h | 97 +----------- 3 files changed, 145 insertions(+), 91 deletions(-) create mode 100644 companion/src/firmwares/customisation_data.cpp diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index e3e075c2e..9a8593b99 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -30,6 +30,7 @@ set(firmwares_SRCS opentx/opentxeeprom.cpp opentx/opentxinterface.cpp datahelpers.cpp + customisation_data.cpp ) string(REPLACE ".cpp" ".h" firmwares_HDRS "${firmwares_SRCS}") diff --git a/companion/src/firmwares/customisation_data.cpp b/companion/src/firmwares/customisation_data.cpp new file mode 100644 index 000000000..34489aa59 --- /dev/null +++ b/companion/src/firmwares/customisation_data.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * 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 "customisation_data.h" + +// cannot use QColor so use formula from libopenui_defines.h +#define RADIO_RGB(r, g, b) \ + (uint16_t)((((r)&0xF8) << 8) + (((g)&0xFC) << 3) + (((b)&0xF8) >> 3)) +#define WHITE RADIO_RGB(0xFF, 0xFF, 0xFF) +#define RED RADIO_RGB(229, 32, 30) + +inline void setZoneOptionValue(ZoneOptionValue& zov, bool value) +{ + zov.boolValue = value; +} + +inline void setZoneOptionValue(ZoneOptionValue& zov, int value) +{ + zov.signedValue = value; +} + +inline void setZoneOptionValue(ZoneOptionValue& zov, char value) +{ + memset(&zov.stringValue, value, LEN_ZONE_OPTION_STRING); +} + +inline void setZoneOptionValue(ZoneOptionValue& zov, unsigned int value) +{ + zov.unsignedValue = value; +} + +inline ZoneOptionValueEnum zoneValueEnumFromType(ZoneOption::Type type) +{ + switch(type) { + case ZoneOption::File: + case ZoneOption::String: + return ZOV_String; + + case ZoneOption::Integer: + return ZOV_Signed; + + case ZoneOption::Bool: + return ZOV_Bool; + + case ZoneOption::Color: + case ZoneOption::Timer: + case ZoneOption::Switch: + case ZoneOption::Source: + case ZoneOption::TextSize: + default: + return ZOV_Unsigned; + } +} + +inline const char * zoneOptionValueEnumToString(ZoneOptionValueEnum zovenum) { + switch (zovenum) { + case ZOV_Unsigned: + return "unsigned"; + case ZOV_Signed: + return "signed"; + case ZOV_Bool: + return "bool"; + case ZOV_String: + return "string"; + default: + return "unknown"; + } +} + +void RadioTheme::init(const char* themeName, ThemeData& themeData) +{ + memset(&themeData, 0, sizeof(ThemeData)); + + memcpy(&themeData.themeName, themeName, THEME_NAME_LEN); + + PersistentData& persistentData = themeData.themePersistentData; + + persistentData.options[0].type = + zoneValueEnumFromType(ZoneOption::Type::Color); + setZoneOptionValue(persistentData.options[0].value, (unsigned int)WHITE); + + persistentData.options[1].type = + zoneValueEnumFromType(ZoneOption::Type::Color); + setZoneOptionValue(persistentData.options[1].value, (unsigned int)RED); +} + +void RadioLayout::init(const char* layoutId, CustomScreens& customScreens) +{ + memset(&customScreens, 0, sizeof(CustomScreens)); + + for (int i = 0; i < MAX_CUSTOM_SCREENS; i++) { + if (i == 0) + memcpy(&customScreens.customScreenData[i].layoutId, layoutId, + LAYOUT_ID_LEN); + + LayoutPersistentData& persistentData = + customScreens.customScreenData[i].layoutPersistentData; + + int j = 0; + persistentData.options[j].type = + zoneValueEnumFromType(ZoneOption::Type::Bool); + setZoneOptionValue(persistentData.options[j++].value, (bool)true); + + persistentData.options[j].type = + zoneValueEnumFromType(ZoneOption::Type::Bool); + setZoneOptionValue(persistentData.options[j++].value, (bool)true); + + persistentData.options[j].type = + zoneValueEnumFromType(ZoneOption::Type::Bool); + setZoneOptionValue(persistentData.options[j++].value, (bool)true); + + persistentData.options[j].type = + zoneValueEnumFromType(ZoneOption::Type::Bool); + setZoneOptionValue(persistentData.options[j++].value, (bool)true); + + persistentData.options[j].type = + zoneValueEnumFromType(ZoneOption::Type::Bool); + setZoneOptionValue(persistentData.options[j++].value, (bool)false); + } +} diff --git a/companion/src/firmwares/customisation_data.h b/companion/src/firmwares/customisation_data.h index 4feda24d9..baad3c828 100644 --- a/companion/src/firmwares/customisation_data.h +++ b/companion/src/firmwares/customisation_data.h @@ -68,21 +68,6 @@ enum ZoneOptionValueEnum { ZOV_LAST = ZOV_String }; -inline const char * zoneOptionValueEnumToString(ZoneOptionValueEnum zovenum) { - switch (zovenum) { - case ZOV_Unsigned: - return "unsigned"; - case ZOV_Signed: - return "signed"; - case ZOV_Bool: - return "bool"; - case ZOV_String: - return "string"; - default: - return "unknown"; - } -} - struct ZoneOption { enum Type { @@ -110,29 +95,6 @@ struct ZoneOptionValueTyped ZoneOptionValue value; }; -inline ZoneOptionValueEnum zoneValueEnumFromType(ZoneOption::Type type) -{ - switch(type) { - case ZoneOption::File: - case ZoneOption::String: - return ZOV_String; - - case ZoneOption::Integer: - return ZOV_Signed; - - case ZoneOption::Bool: - return ZOV_Bool; - - case ZoneOption::Color: - case ZoneOption::Timer: - case ZoneOption::Switch: - case ZoneOption::Source: - case ZoneOption::TextSize: - default: - return ZOV_Unsigned; - } -} - struct WidgetPersistentData { ZoneOptionValueTyped options[MAX_WIDGET_OPTIONS]; }; @@ -148,19 +110,11 @@ struct WidgetsContainerPersistentData { ZoneOptionValueTyped options[O]; }; -typedef WidgetsContainerPersistentData LayoutPersistentData; +typedef WidgetsContainerPersistentData + LayoutPersistentData; -typedef WidgetsContainerPersistentData TopBarPersistentData; - -inline void setZoneOptionValue(ZoneOptionValue & zov, bool value) { zov.boolValue = value; } -inline void setZoneOptionValue(ZoneOptionValue & zov, int value) { zov.signedValue = value; } -inline void setZoneOptionValue(ZoneOptionValue & zov, char value) { memset(&zov.stringValue, value, LEN_ZONE_OPTION_STRING); } -inline void setZoneOptionValue(ZoneOptionValue & zov, unsigned int value) { zov.unsignedValue = value; } - -// cannot use QColor so use formula from libopenui_defines.h -// #define RGB(r, g, b) (uint16_t)((((r) & 0xF8) << 8) + (((g) & 0xFC) << 3) + (((b) & 0xF8) >> 3)) -// #define WHITE RGB(0xFF, 0xFF, 0xFF) -// #define RED RGB(229, 32, 30) +typedef WidgetsContainerPersistentData + TopBarPersistentData; class RadioTheme { @@ -176,20 +130,7 @@ class RadioTheme PersistentData themePersistentData; }; - static void init(const char * themeName, ThemeData & themeData) - { - memset(&themeData, 0, sizeof(ThemeData)); - - // memcpy(&themeData.themeName, themeName, THEME_NAME_LEN); - - // PersistentData & persistentData = themeData.themePersistentData; - - // persistentData.options[0].type = zoneValueEnumFromType(ZoneOption::Type::Color); - // setZoneOptionValue(persistentData.options[0].value, (unsigned int)WHITE); - - // persistentData.options[1].type = zoneValueEnumFromType(ZoneOption::Type::Color); - // setZoneOptionValue(persistentData.options[1].value, (unsigned int)RED); - } + static void init(const char * themeName, ThemeData & themeData); }; class RadioLayout @@ -206,31 +147,5 @@ class RadioLayout CustomScreenData customScreenData[MAX_CUSTOM_SCREENS]; }; - static void init(const char * layoutId, CustomScreens & customScreens) - { - memset(&customScreens, 0, sizeof(CustomScreens)); - - // for (int i = 0; i < MAX_CUSTOM_SCREENS; i++) { - // if (i == 0) - // memcpy(&customScreens.customScreenData[i].layoutId, layoutId, LAYOUT_ID_LEN); - - // LayoutPersistentData & persistentData = customScreens.customScreenData[i].layoutPersistentData; - - // int j = 0; - // persistentData.options[j].type = zoneValueEnumFromType(ZoneOption::Type::Bool); - // setZoneOptionValue(persistentData.options[j++].value, (bool)true); - - // persistentData.options[j].type = zoneValueEnumFromType(ZoneOption::Type::Bool); - // setZoneOptionValue(persistentData.options[j++].value, (bool)true); - - // persistentData.options[j].type = zoneValueEnumFromType(ZoneOption::Type::Bool); - // setZoneOptionValue(persistentData.options[j++].value, (bool)true); - - // persistentData.options[j].type = zoneValueEnumFromType(ZoneOption::Type::Bool); - // setZoneOptionValue(persistentData.options[j++].value, (bool)true); - - // persistentData.options[j].type = zoneValueEnumFromType(ZoneOption::Type::Bool); - // setZoneOptionValue(persistentData.options[j++].value, (bool)false); - // } - } + static void init(const char * layoutId, CustomScreens & customScreens); };