Add stick, switch, pots & slider config

This commit is contained in:
Raphael Coeffic
2021-12-31 10:53:09 +01:00
parent 278a27b65f
commit 9dd8917ab4
4 changed files with 179 additions and 6 deletions
+1
View File
@@ -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
)
@@ -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;
@@ -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"},
};
@@ -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<unsigned int N, const YamlLookupTable& name_lut>
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<CPN_MAX_SWITCHES, sticksLut> YamlStickConfig;
template<unsigned int N, const YamlLookupTable& name_lut, const YamlLookupTable& cfg_lut>
struct YamlKnobConfig : public YamlNameConfig<N, name_lut> {
unsigned int config[N];
void copy(char out_names[N][HARDWARE_NAME_LEN + 1], unsigned int out_configs[N]) {
YamlNameConfig<N, name_lut>::copy(out_names);
memcpy(out_configs, config, sizeof(config));
}
};
// SA:
// type: 3pos
// name:
extern const YamlLookupTable switchesLut;
extern const YamlLookupTable switchConfigLut;
typedef YamlKnobConfig<CPN_MAX_SWITCHES, switchesLut, switchConfigLut> YamlSwitchConfig;
// S1:
// type: with_detent
// name:
extern const YamlLookupTable potsLut;
extern const YamlLookupTable potConfigLut;
typedef YamlKnobConfig<CPN_MAX_KNOBS, potsLut, potConfigLut> YamlPotConfig;
// S1:
// type: with_detent
// name:
extern const YamlLookupTable slidersLut;
extern const YamlLookupTable sliderConfigLut;
typedef YamlKnobConfig<CPN_MAX_SLIDERS, slidersLut, sliderConfigLut> YamlSliderConfig;
namespace YAML
{
template <unsigned int N, const YamlLookupTable& name_lut>
struct convert<YamlNameConfig<N, name_lut> > {
static bool decode(const Node& node, YamlNameConfig<N, name_lut>& 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 <unsigned int N, const YamlLookupTable& name_lut, const YamlLookupTable& cfg_lut>
struct convert<YamlKnobConfig<N, name_lut, cfg_lut> > {
static bool decode(const Node& node, YamlKnobConfig<N, name_lut, cfg_lut>& 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