From 8a10ffa43dc5f2c9e28a66379b5bfb98bf526598 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 1 Dec 2021 12:01:05 +0100 Subject: [PATCH] Output knobs config --- .../firmwares/edgetx/yaml_generalsettings.h | 18 ++--- .../firmwares/edgetx/yaml_switchconfig.cpp | 1 + .../src/firmwares/edgetx/yaml_switchconfig.h | 70 +++++++++++++++---- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index 270ed3edb..2548d6b73 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -112,20 +112,10 @@ namespace YAML { // } // } - // YamlStickConfig stickConfig; - // node["sticksConfig"] = stickConfig; - - // YamlSwitchConfig switchConfig; - // node["switchConfig"] = switchConfig; - // switchConfig.copy(rhs.switchName, rhs.switchConfig); - - // YamlPotConfig potsConfig; - // node["potsConfig"] = potsConfig; - // potsConfig.copy(rhs.potName, rhs.potConfig); - - // YamlSliderConfig slidersConfig; - // node["slidersConfig"] = slidersConfig; - // slidersConfig.copy(rhs.sliderName, rhs.sliderConfig); + node["sticksConfig"] = YamlStickConfig(rhs.stickName); + node["switchConfig"] = YamlSwitchConfig(rhs.switchName, rhs.switchConfig); + node["potsConfig"] = YamlPotConfig(rhs.potName, rhs.potConfig); + node["slidersConfig"] = YamlSliderConfig(rhs.sliderName, rhs.sliderConfig); // Color lcd theme settings are not used in EdgeTx // RadioTheme::ThemeData themeData; diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 2fabedf19..25d8ea75d 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -62,3 +62,4 @@ const YamlLookupTable sliderConfigLut = { {Board::SLIDER_NONE, "none"}, {Board::SLIDER_WITH_DETENT, "with_detent"}, }; + diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.h b/companion/src/firmwares/edgetx/yaml_switchconfig.h index 0fac60bc3..5cc2cc7d9 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.h +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.h @@ -22,28 +22,47 @@ #include "yaml_ops.h" #include "generalsettings.h" +#include -template +template struct YamlNameConfig { - char name[N][HARDWARE_NAME_LEN + 1]; - void copy(char out_names[N][HARDWARE_NAME_LEN + 1]) { - memcpy(out_names, name, sizeof(name)); + YamlNameConfig() { memset(name, 0, sizeof(name)); } + + YamlNameConfig(const char in_names[N][HARDWARE_NAME_LEN + 1]) + { + memcpy(name, in_names, sizeof(name)); + } + + void copy(char out_names[N][HARDWARE_NAME_LEN + 1]) + { + memcpy(out_names, name, sizeof(name)); } }; extern const YamlLookupTable sticksLut; typedef YamlNameConfig YamlStickConfig; -template +template struct YamlKnobConfig : public YamlNameConfig { - unsigned int config[N]; - void copy(char out_names[N][HARDWARE_NAME_LEN + 1], unsigned int out_configs[N]) { - YamlNameConfig::copy(out_names); - memcpy(out_configs, config, sizeof(config)); + YamlKnobConfig() { memset(config, 0, sizeof(config)); } + + YamlKnobConfig(const char in_names[N][HARDWARE_NAME_LEN + 1], + const unsigned int in_configs[N]) : + YamlNameConfig(in_names) + { + memset(config, 0, sizeof(config)); + } + + void copy(char out_names[N][HARDWARE_NAME_LEN + 1], + unsigned int out_configs[N]) + { + YamlNameConfig::copy(out_names); + memcpy(out_configs, config, sizeof(config)); } }; @@ -52,26 +71,36 @@ struct YamlKnobConfig : public YamlNameConfig { // name: extern const YamlLookupTable switchesLut; extern const YamlLookupTable switchConfigLut; -typedef YamlKnobConfig YamlSwitchConfig; +typedef YamlKnobConfig + YamlSwitchConfig; // S1: // type: with_detent -// name: +// name: extern const YamlLookupTable potsLut; extern const YamlLookupTable potConfigLut; typedef YamlKnobConfig YamlPotConfig; // S1: // type: with_detent -// name: +// name: extern const YamlLookupTable slidersLut; extern const YamlLookupTable sliderConfigLut; -typedef YamlKnobConfig YamlSliderConfig; +typedef YamlKnobConfig + YamlSliderConfig; namespace YAML { template struct convert > { + static Node encode(const YamlNameConfig& rhs) + { + Node node; + for (const auto& kv : name_lut) { + node[kv.second]["name"] = rhs.name[kv.first]; + } + return node; + } static bool decode(const Node& node, YamlNameConfig& rhs) { if (!node.IsMap()) return false; @@ -84,9 +113,20 @@ struct convert > { } }; -template +template struct convert > { - static bool decode(const Node& node, YamlKnobConfig& rhs) + static Node encode(const YamlKnobConfig& rhs) + { + Node node; + for (const auto& kv : name_lut) { + node[kv.second]["type"] = cfg_lut << rhs.config[kv.first]; + node[kv.second]["name"] = rhs.name[kv.first]; + } + return node; + } + static bool decode(const Node& node, + YamlKnobConfig& rhs) { if (!node.IsMap()) return false; int idx = 0;