/* * 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" #include struct YamlStickLookup { static int name2idx(const std::string& name); static std::string idx2name(unsigned int idx); }; template struct YamlNameConfig { char name[N][HARDWARE_NAME_LEN + 1]; 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)); } }; typedef YamlNameConfig YamlStickConfig; template struct YamlKnobConfig : public YamlNameConfig { unsigned int config[N]; 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) { memcpy(config, in_configs, 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)); } }; // SA: // type: 3pos // name: struct YamlSwitchLookup { static int name2idx(const std::string& name); static std::string idx2name(unsigned int idx); }; extern const YamlLookupTable switchConfigLut; typedef YamlKnobConfig YamlSwitchConfig; // S1: // type: with_detent // name: struct YamlPotLookup { static int name2idx(const std::string& name); static std::string idx2name(unsigned int idx); }; extern const YamlLookupTable potConfigLut; typedef YamlKnobConfig YamlPotConfig; // S1: // type: with_detent // name: struct YamlSliderLookup { static int name2idx(const std::string& name); static std::string idx2name(unsigned int idx); }; extern const YamlLookupTable sliderConfigLut; typedef YamlKnobConfig YamlSliderConfig; namespace YAML { template struct convert > { static Node encode(const YamlNameConfig& rhs) { Node node; for (unsigned int i=0; i& rhs) { if (!node.IsMap()) return false; int idx = 0; for (const auto& kv : node) { idx = name_lookup::name2idx(kv.first.Scalar()); if (idx >= 0) { kv.second["name"] >> rhs.name[idx]; } } return true; } }; template struct convert > { static Node encode(const YamlKnobConfig& rhs) { Node node; for (unsigned int i=0; i& rhs) { if (!node.IsMap()) return false; int idx = 0; for (const auto& kv : node) { idx = name_lookup::name2idx(kv.first.Scalar()); if (idx >= 0) { kv.second["type"] >> cfg_lut >> rhs.config[idx]; kv.second["name"] >> rhs.name[idx]; } } return true; } }; } // namespace YAML