Add support for radio calibration

This commit is contained in:
Raphael Coeffic
2021-12-31 10:53:09 +01:00
parent d98a697aca
commit f57a1fd6c3
7 changed files with 271 additions and 83 deletions
+3
View File
@@ -30,6 +30,9 @@ set(firmwares_SRCS
opentx/opentxeeprom.cpp
opentx/opentxinterface.cpp
edgetx/edgetxinterface.cpp
edgetx/yaml_ops.cpp
edgetx/yaml_generalsettings.cpp
edgetx/yaml_calibdata.cpp
datahelpers.cpp
customisation_data.cpp
)
@@ -0,0 +1,57 @@
/*
* 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_calibdata.h"
// TODO: we need a function that
// does the opposite of Boards::getAnalogInputName()
//
// This is only valid for X10, T16, TX16S (not X12S)
//
const YamlLookupTable calibIdxLut = {
{ 0, "Rud" },
{ 1, "Ele" },
{ 2, "Thr" },
{ 3, "Ail" },
{ 4, "S1" },
{ 5, "6POS" },
{ 6, "S2" },
{ 7, "EXT1" },
{ 8, "EXT2" },
// not yet supported in Companion:
// { 9, "EXT3" },
// { 10, "EXT4" },
{ 9, "LS" },
{ 10, "RS" },
{ 11, "MOUSE1" },
{ 12, "MOUSE2" },
};
YamlCalibData::YamlCalibData() { memset(calib, 0, sizeof(calib)); }
void YamlCalibData::copy(int* calibMid, int* calibSpanNeg,
int* calibSpanPos) const
{
for (int i = 0; i < CPN_MAX_ANALOGS; i++) {
calibMid[i] = calib[i].mid;
calibSpanNeg[i] = calib[i].spanNeg;
calibSpanPos[i] = calib[i].spanPos;
}
}
@@ -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_ops.h"
#include "generalsettings.h"
struct CalibData {
int16_t mid;
int16_t spanNeg;
int16_t spanPos;
};
struct YamlCalibData {
CalibData calib[CPN_MAX_ANALOGS];
YamlCalibData();
void copy(int* calibMid, int* calibSpanNeg, int* calibSpanPos) const;
};
extern const YamlLookupTable calibIdxLut;
namespace YAML {
template<>
struct convert<CalibData> {
static bool decode(const Node& node, CalibData& rhs) {
if (!node.IsMap()) return false;
node["mid"] >> rhs.mid;
node["spanNeg"] >> rhs.spanNeg;
node["spanPos"] >> rhs.spanPos;
return true;
}
};
template<>
struct convert<YamlCalibData> {
static bool decode(const Node& node, YamlCalibData& rhs) {
if (!node.IsMap()) return false;
int idx = 0;
for (const auto& kv : node) {
kv.first >> calibIdxLut >> idx;
kv.second >> rhs.calib[idx];
}
return true;
}
};
}
@@ -0,0 +1,66 @@
/*
* 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_generalsettings.h"
const YamlLookupTable beeperModeLut = {
{ GeneralSettings::BEEPER_QUIET, "mode_quiet" },
{ GeneralSettings::BEEPER_ALARMS_ONLY, "mode_alarms" },
{ GeneralSettings::BEEPER_NOKEYS, "mode_nokeys" },
{ GeneralSettings::BEEPER_ALL, "mode_all" },
};
enum BacklightMode {
e_backlight_mode_off = 0,
e_backlight_mode_keys = 1,
e_backlight_mode_sticks = 2,
e_backlight_mode_all = e_backlight_mode_keys+e_backlight_mode_sticks,
e_backlight_mode_on
};
const YamlLookupTable backlightModeLut = {
{ e_backlight_mode_off, "backlight_mode_off" },
{ e_backlight_mode_keys, "backlight_mode_keys" },
{ e_backlight_mode_sticks, "backlight_mode_sticks" },
{ e_backlight_mode_all, "backlight_mode_all" },
{ e_backlight_mode_on, "backlight_mode_on" },
};
const YamlLookupTable bluetoothModeLut = {
{ GeneralSettings::BLUETOOTH_MODE_OFF, "OFF" },
{ GeneralSettings::BLUETOOTH_MODE_TELEMETRY, "TELEMETRY" },
{ GeneralSettings::BLUETOOTH_MODE_TRAINER, "TRAINER" },
};
const YamlLookupTable uartModeLut = {
{ GeneralSettings::AUX_SERIAL_OFF, "MODE_NONE" },
{ GeneralSettings::AUX_SERIAL_TELE_MIRROR, "MODE_TELEMETRY_MIRROR" },
{ GeneralSettings::AUX_SERIAL_TELE_IN, "MODE_TELEMETRY" },
{ GeneralSettings::AUX_SERIAL_SBUS_TRAINER, "MODE_SBUS_TRAINER" },
{ GeneralSettings::AUX_SERIAL_LUA, "MODE_LUA" },
};
const YamlLookupTable antennaModeLut = {
{ GeneralSettings::ANTENNA_MODE_INTERNAL, "MODE_INTERNAL" },
{ GeneralSettings::ANTENNA_MODE_ASK, "MODE_ASK" },
{ GeneralSettings::ANTENNA_MODE_PER_MODEL, "MODE_PER_MODEL" },
{ GeneralSettings::ANTENNA_MODE_EXTERNAL, "MODE_EXTERNAL" },
{ GeneralSettings::ANTENNA_MODE_INTERNAL_EXTERNAL, "MODE_INTERNAL_EXTERNAL" },
};
@@ -21,54 +21,13 @@
#include "yaml_ops.h"
#include "generalsettings.h"
#include "yaml_trainerdata.h"
#include "yaml_calibdata.h"
typedef std::pair<int, std::string> YamlLookupTableElmt;
typedef std::vector<YamlLookupTableElmt> YamlLookupTable;
const YamlLookupTable beeperModeLut = {
{ GeneralSettings::BEEPER_QUIET, "mode_quiet" },
{ GeneralSettings::BEEPER_ALARMS_ONLY, "mode_alarms" },
{ GeneralSettings::BEEPER_NOKEYS, "mode_nokeys" },
{ GeneralSettings::BEEPER_ALL, "mode_all" },
};
enum BacklightMode {
e_backlight_mode_off = 0,
e_backlight_mode_keys = 1,
e_backlight_mode_sticks = 2,
e_backlight_mode_all = e_backlight_mode_keys+e_backlight_mode_sticks,
e_backlight_mode_on
};
const YamlLookupTable backlightModeLut = {
{ e_backlight_mode_off, "backlight_mode_off" },
{ e_backlight_mode_keys, "backlight_mode_keys" },
{ e_backlight_mode_sticks, "backlight_mode_sticks" },
{ e_backlight_mode_all, "backlight_mode_all" },
{ e_backlight_mode_on, "backlight_mode_on" },
};
const YamlLookupTable bluetoothModeLut = {
{ GeneralSettings::BLUETOOTH_MODE_OFF, "OFF" },
{ GeneralSettings::BLUETOOTH_MODE_TELEMETRY, "TELEMETRY" },
{ GeneralSettings::BLUETOOTH_MODE_TRAINER, "TRAINER" },
};
const YamlLookupTable uartModeLut = {
{ GeneralSettings::AUX_SERIAL_OFF, "MODE_NONE" },
{ GeneralSettings::AUX_SERIAL_TELE_MIRROR, "MODE_TELEMETRY_MIRROR" },
{ GeneralSettings::AUX_SERIAL_TELE_IN, "MODE_TELEMETRY" },
{ GeneralSettings::AUX_SERIAL_SBUS_TRAINER, "MODE_SBUS_TRAINER" },
{ GeneralSettings::AUX_SERIAL_LUA, "MODE_LUA" },
};
const YamlLookupTable antennaModeLut = {
{ GeneralSettings::ANTENNA_MODE_INTERNAL, "MODE_INTERNAL" },
{ GeneralSettings::ANTENNA_MODE_ASK, "MODE_ASK" },
{ GeneralSettings::ANTENNA_MODE_PER_MODEL, "MODE_PER_MODEL" },
{ GeneralSettings::ANTENNA_MODE_EXTERNAL, "MODE_EXTERNAL" },
{ GeneralSettings::ANTENNA_MODE_INTERNAL_EXTERNAL, "MODE_INTERNAL_EXTERNAL" },
};
extern const YamlLookupTable beeperModeLut;
extern const YamlLookupTable backlightModeLut;
extern const YamlLookupTable bluetoothModeLut;
extern const YamlLookupTable uartModeLut;
extern const YamlLookupTable antennaModeLut;
namespace YAML {
@@ -85,11 +44,18 @@ namespace YAML {
static bool decode(const Node& node, GeneralSettings& rhs) {
// TODO: check board string and fetch Board instance
std::string board;
node["board"] >> board;
node["version"] >> rhs.version;
node["versionBla"] >> rhs.version;
// // calib
// Radio calib
YamlCalibData calib;
node["calib"] >> calib;
calib.copy(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos);
node["currModel"] >> rhs.currModelIndex;
// // filename
node["currModelFilename"] >> rhs.currModelFilename;
node["contrast"] >> rhs.contrast;
node["vBatWarn"] >> rhs.vBatWarn;
node["txVoltageCalibration"] >> rhs.txVoltageCalibration;
@@ -153,13 +119,18 @@ namespace YAML {
// }
// TODO:
// char stickName[CPN_MAX_STICKS][HARDWARE_NAME_LEN + 1];
// char switchName[CPN_MAX_SWITCHES][HARDWARE_NAME_LEN + 1];
// unsigned int switchConfig[CPN_MAX_SWITCHES];
// char stickName[CPN_MAX_STICKS][HARDWARE_NAME_LEN + 1];
// char potName[CPN_MAX_KNOBS][HARDWARE_NAME_LEN + 1];
// unsigned int potConfig[CPN_MAX_KNOBS];
// char sliderName[CPN_MAX_SLIDERS][HARDWARE_NAME_LEN + 1];
// unsigned int sliderConfig[CPN_MAX_SLIDERS];
// Color lcd theme settings are probably obsolete
// RadioTheme::ThemeData themeData;
node["ownerRegistrationID"] >> rhs.registrationId;
@@ -0,0 +1,55 @@
/*
* 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_ops.h"
YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut)
{
if (node) {
std::string str = node.as<std::string>();
const auto& it =
find_if(lut.begin(), lut.end(), [=](const YamlLookupTableElmt& elmt) {
if (elmt.second == str) return true;
return false;
});
if (it != lut.end()) {
return YAML::Node(it->first);
}
return YAML::Node();
}
return node;
}
void operator >> (const YAML::Node& node, const ioffset_int& value)
{
if (node && node.IsScalar()) {
value.assign(node.as<int>());
}
}
template <>
void operator >> (const YAML::Node& node, bool& value)
{
if (node && node.IsScalar()) {
value = node.as<int>();
}
}
+4 -32
View File
@@ -42,31 +42,8 @@ private:
};
YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut)
{
if (node) {
std::string str = node.as<std::string>();
const auto& it =
find_if(lut.begin(), lut.end(), [=](const YamlLookupTableElmt& elmt) {
if (elmt.second == str) return true;
return false;
});
if (it != lut.end()) {
return YAML::Node(it->first);
}
return YAML::Node();
}
return node;
}
void operator >> (const YAML::Node& node, const ioffset_int& value)
{
if (node && node.IsScalar()) {
value.assign(node.as<int>());
}
}
YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut);
void operator >> (const YAML::Node& node, const ioffset_int& value);
template <typename T>
void operator >> (const YAML::Node& node, T& value)
@@ -76,13 +53,8 @@ void operator >> (const YAML::Node& node, T& value)
}
}
template <>
void operator >> (const YAML::Node& node, bool& value)
{
if (node && node.IsScalar()) {
value = node.as<int>();
}
}
// type specialisation
template <> void operator >> (const YAML::Node& node, bool& value);
template <size_t N>
void operator >> (const YAML::Node& node, char (&value)[N])