diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 16aa92710..e419ad923 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -33,6 +33,7 @@ set(firmwares_SRCS edgetx/yaml_ops.cpp edgetx/yaml_generalsettings.cpp edgetx/yaml_calibdata.cpp + edgetx/yaml_switchconfig.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index da3d0ada0..a11f2d066 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -22,6 +22,7 @@ #include "generalsettings.h" #include "yaml_trainerdata.h" #include "yaml_calibdata.h" +#include "yaml_switchconfig.h" extern const YamlLookupTable beeperModeLut; extern const YamlLookupTable backlightModeLut; @@ -120,15 +121,21 @@ namespace YAML { // TODO: // char stickName[CPN_MAX_STICKS][HARDWARE_NAME_LEN + 1]; + + YamlStickConfig stickConfig; + node["sticksConfig"] >> stickConfig; - // char switchName[CPN_MAX_SWITCHES][HARDWARE_NAME_LEN + 1]; - // unsigned int switchConfig[CPN_MAX_SWITCHES]; + YamlSwitchConfig switchConfig; + node["switchConfig"] >> switchConfig; + switchConfig.copy(rhs.switchName, rhs.switchConfig); - // char potName[CPN_MAX_KNOBS][HARDWARE_NAME_LEN + 1]; - // unsigned int potConfig[CPN_MAX_KNOBS]; + YamlPotConfig potsConfig; + node["potsConfig"] >> potsConfig; + potsConfig.copy(rhs.potName, rhs.potConfig); - // char sliderName[CPN_MAX_SLIDERS][HARDWARE_NAME_LEN + 1]; - // unsigned int sliderConfig[CPN_MAX_SLIDERS]; + YamlSliderConfig slidersConfig; + node["slidersConfig"] >> slidersConfig; + slidersConfig.copy(rhs.sliderName, rhs.sliderConfig); // Color lcd theme settings are probably obsolete // RadioTheme::ThemeData themeData; diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp new file mode 100644 index 000000000..2fabedf19 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -0,0 +1,64 @@ +/* + * 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_switchconfig.h" +#include "boards.h" + +const YamlLookupTable sticksLut = { + {0, "0"}, + {1, "1"}, + {2, "2"}, + {3, "3"}, +}; + +const YamlLookupTable switchesLut = { + {0, "SA"}, {1, "SB"}, {2, "SC"}, {3, "SD"}, {4, "SE"}, + {5, "SF"}, {6, "SG"}, {7, "SH"}, {8, "SI"}, {9, "SJ"}, +}; + +const YamlLookupTable switchConfigLut = { + {Board::SWITCH_NOT_AVAILABLE, "none"}, + {Board::SWITCH_TOGGLE, "toggle"}, + {Board::SWITCH_2POS, "2pos"}, + {Board::SWITCH_3POS, "3pos"}, +}; + +const YamlLookupTable potsLut = { + {0, "S1"}, {1, "6POS"}, {2, "S2"}, {3, "EXT1"}, {4, "EXT2"}, + // { 5, "EXT3" }, + // { 6, "EXT4" }, +}; + +const YamlLookupTable potConfigLut = { + {Board::POT_NONE, "none"}, + {Board::POT_WITH_DETENT, "with_detent"}, + {Board::POT_MULTIPOS_SWITCH, "multipos_switch"}, + {Board::POT_WITHOUT_DETENT, "without_detent"}, +}; + +const YamlLookupTable slidersLut = { + {0, "LS"}, + {1, "RS"}, +}; + +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 new file mode 100644 index 000000000..0fac60bc3 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.h @@ -0,0 +1,101 @@ +/* + * 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. + */ + +#pragma once + +#include "yaml_ops.h" +#include "generalsettings.h" + +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)); + } +}; + +extern const YamlLookupTable sticksLut; +typedef YamlNameConfig YamlStickConfig; + +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)); + } +}; + +// SA: +// type: 3pos +// name: +extern const YamlLookupTable switchesLut; +extern const YamlLookupTable switchConfigLut; +typedef YamlKnobConfig YamlSwitchConfig; + +// S1: +// type: with_detent +// name: +extern const YamlLookupTable potsLut; +extern const YamlLookupTable potConfigLut; +typedef YamlKnobConfig YamlPotConfig; + +// S1: +// type: with_detent +// name: +extern const YamlLookupTable slidersLut; +extern const YamlLookupTable sliderConfigLut; +typedef YamlKnobConfig YamlSliderConfig; + +namespace YAML +{ +template +struct convert > { + static bool decode(const Node& node, YamlNameConfig& rhs) + { + if (!node.IsMap()) return false; + int idx = 0; + for (const auto& kv : node) { + kv.first >> name_lut >> idx; + kv.second["name"] >> rhs.name[idx]; + } + return true; + } +}; + +template +struct convert > { + static bool decode(const Node& node, YamlKnobConfig& rhs) + { + if (!node.IsMap()) return false; + int idx = 0; + for (const auto& kv : node) { + kv.first >> name_lut >> idx; + kv.second["type"] >> cfg_lut >> rhs.config[idx]; + kv.second["name"] >> rhs.name[idx]; + } + return true; + } +}; +} // namespace YAML