feat: use any source for expo/weight/offset (#5220)
Co-authored-by: philmoz <phil.a.mitchell@gmail.com> Co-authored-by: 3djc <3djc@gh.com> Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
co-authored by
philmoz
3djc
elecpower
parent
326c58a7fd
commit
4b917b762c
@@ -28,6 +28,7 @@ set(${PROJECT_NAME}_NAMES
|
||||
rawsource
|
||||
rawswitch
|
||||
sensordata
|
||||
sourcenumref
|
||||
telem_data
|
||||
timerdata
|
||||
ersky9x/ersky9xeeprom
|
||||
|
||||
@@ -19,14 +19,16 @@
|
||||
*/
|
||||
|
||||
#include "curvereference.h"
|
||||
#include "adjustmentreference.h"
|
||||
#include "helpers.h"
|
||||
#include "modeldata.h"
|
||||
#include "generalsettings.h"
|
||||
#include "filtereditemmodels.h"
|
||||
#include "curveimagewidget.h"
|
||||
#include "curvedialog.h"
|
||||
#include "sourcenumref.h"
|
||||
|
||||
const QString CurveReference::toString(const ModelData * model, bool verbose) const
|
||||
const QString CurveReference::toString(const ModelData * model, bool verbose, const GeneralSettings * const generalSettings,
|
||||
Board::Type board, bool prefixCustomName) const
|
||||
{
|
||||
if (value == 0)
|
||||
return CPN_STR_NONE_ITEM;
|
||||
@@ -37,7 +39,7 @@ const QString CurveReference::toString(const ModelData * model, bool verbose) co
|
||||
switch(type) {
|
||||
case CURVE_REF_DIFF:
|
||||
case CURVE_REF_EXPO:
|
||||
ret = AdjustmentReference(value).toString(model);
|
||||
ret = SourceNumRef(value).toString(model, generalSettings, board, prefixCustomName);
|
||||
break;
|
||||
case CURVE_REF_FUNC:
|
||||
ret = functionToString(value);
|
||||
@@ -48,7 +50,7 @@ const QString CurveReference::toString(const ModelData * model, bool verbose) co
|
||||
else
|
||||
ret = CurveData().nameToString(idx);
|
||||
if (value < 0)
|
||||
ret.prepend(CPN_STR_SW_INDICATOR_REV);
|
||||
ret.prepend(CPN_STR_SRC_INDICATOR_NEG);
|
||||
break;
|
||||
default:
|
||||
return CPN_STR_UNKNOWN_ITEM;
|
||||
@@ -62,7 +64,7 @@ const QString CurveReference::toString(const ModelData * model, bool verbose) co
|
||||
|
||||
const bool CurveReference::isValueNumber() const
|
||||
{
|
||||
return (type == CURVE_REF_DIFF || type == CURVE_REF_EXPO) && AdjustmentReference(value).type == AdjustmentReference::ADJUST_REF_VALUE;
|
||||
return (type == CURVE_REF_DIFF || type == CURVE_REF_EXPO) && SourceNumRef(value).isNumber();
|
||||
}
|
||||
|
||||
const bool CurveReference::isAvailable() const
|
||||
@@ -74,7 +76,7 @@ const bool CurveReference::isAvailable() const
|
||||
int CurveReference::getDefaultValue(const CurveRefType type, const bool isGVar)
|
||||
{
|
||||
if (isGVar && (type == CURVE_REF_DIFF || type == CURVE_REF_EXPO))
|
||||
return AdjustmentReference(AdjustmentReference::ADJUST_REF_GVAR, 1).toValue();
|
||||
return SourceNumRef(SOURCE_TYPE_GVAR, 1).toValue();
|
||||
else if (type == CURVE_REF_FUNC)
|
||||
return 1;
|
||||
else
|
||||
@@ -146,54 +148,50 @@ int CurveReference::functionCount()
|
||||
* CurveReferenceUIManager
|
||||
*/
|
||||
|
||||
CurveReferenceUIManager::CurveReferenceUIManager(QComboBox * curveTypeCB, QCheckBox * curveGVarCB, QSpinBox * curveValueSB,
|
||||
QComboBox * curveValueCB, QLabel * curveLabelImage,
|
||||
CurveReferenceUIManager::CurveReferenceUIManager(QComboBox * cboType, QCheckBox * chkUseSource, QSpinBox * sbxValue,
|
||||
QComboBox * cboSource, QComboBox * cboCurveFunc, CurveImageWidget * curveImage,
|
||||
CurveReference & curveRef, ModelData & model, CompoundItemModelFactory * sharedItemModels,
|
||||
CurveRefFilteredFactory * curveRefFilteredFactory, QObject * parent) :
|
||||
CurveRefFilteredFactory * curveRefFilteredFactory, FilteredItemModel * sourceItemModel,
|
||||
QObject * parent) :
|
||||
QObject(parent),
|
||||
curveTypeCB(curveTypeCB),
|
||||
curveGVarCB(curveGVarCB),
|
||||
curveValueSB(curveValueSB),
|
||||
curveValueCB(curveValueCB),
|
||||
cboType(cboType),
|
||||
chkUseSource(chkUseSource),
|
||||
sbxValue(sbxValue),
|
||||
cboSource(cboSource),
|
||||
cboCurveFunc(cboCurveFunc),
|
||||
curveImage(curveImage),
|
||||
curveRef(curveRef),
|
||||
model(model),
|
||||
sharedItemModels(sharedItemModels),
|
||||
filteredModelFactory(curveRefFilteredFactory),
|
||||
lock(false),
|
||||
curveImageWidget(nullptr)
|
||||
srcNumRefEditor(nullptr)
|
||||
{
|
||||
connectItemModelEvents(filteredModelFactory->getItemModel(CurveRefFilteredFactory::CRFIM_CURVE));
|
||||
|
||||
hasCapabilityGvars = getCurrentFirmware()->getCapability(Gvars);
|
||||
if (chkUseSource || sbxValue || cboSource)
|
||||
srcNumRefEditor = new SourceNumRefEditor(curveRef.value, chkUseSource, sbxValue, cboSource, 0, -100, 100, 1, model, sourceItemModel);
|
||||
|
||||
if (curveTypeCB) {
|
||||
curveTypeCB->setModel(filteredModelFactory->getItemModel(CurveRefFilteredFactory::CRFIM_TYPE));
|
||||
curveTypeCB->setCurrentIndex(curveTypeCB->findData((int)curveRef.type));
|
||||
connect(curveTypeCB, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int)));
|
||||
if (cboType) {
|
||||
cboType->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
cboType->setModel(filteredModelFactory->getItemModel(CurveRefFilteredFactory::CRFIM_TYPE));
|
||||
cboType->setCurrentIndex(cboType->findData((int)curveRef.type));
|
||||
connect(cboType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CurveReferenceUIManager::cboTypeChanged);
|
||||
}
|
||||
|
||||
if (curveGVarCB)
|
||||
connect(curveGVarCB, SIGNAL(stateChanged(int)), this, SLOT(gvarCBChanged(int)));
|
||||
|
||||
if (curveValueSB) {
|
||||
curveValueSB->setMinimum(-100);
|
||||
curveValueSB->setMaximum(100);
|
||||
connect(curveValueSB, SIGNAL(editingFinished()), this, SLOT(valueSBChanged()));
|
||||
}
|
||||
|
||||
if (curveValueCB) {
|
||||
curveValueCB->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
curveValueCB->setMaxVisibleItems(10);
|
||||
connect(curveValueCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valueCBChanged()));
|
||||
|
||||
if (curveLabelImage) {
|
||||
curveImageWidget = qobject_cast<CurveImageWidget *>(curveLabelImage);
|
||||
if (curveImageWidget) {
|
||||
curveImageWidget->set(&model, getCurrentFirmware(), sharedItemModels, abs(curveRef.value) - 1, Qt::black, 3);
|
||||
curveImageWidget->setGrid(Qt::gray, 2);
|
||||
connect(curveImageWidget, &CurveImageWidget::doubleClicked, this, &CurveReferenceUIManager::curveImageDoubleClicked);
|
||||
}
|
||||
if (cboCurveFunc) {
|
||||
if (!cboType) {
|
||||
cboCurveFunc->setModel(filteredModelFactory->getItemModel(CurveRefFilteredFactory::CRFIM_CURVE));
|
||||
cboCurveFunc->setCurrentIndex(cboCurveFunc->findData(curveRef.value));
|
||||
}
|
||||
cboCurveFunc->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
cboCurveFunc->setMaxVisibleItems(10);
|
||||
connect(cboCurveFunc, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CurveReferenceUIManager::cboCurveFuncChanged);
|
||||
}
|
||||
|
||||
if (curveImage) {
|
||||
curveImage->set(&model, getCurrentFirmware(), sharedItemModels, curveRef.value, Qt::black, 3);
|
||||
curveImage->setGrid(Qt::gray, 2);
|
||||
connect(curveImage, &CurveImageWidget::doubleClicked, this, &CurveReferenceUIManager::curveImageDoubleClicked);
|
||||
}
|
||||
|
||||
update();
|
||||
@@ -201,10 +199,10 @@ CurveReferenceUIManager::CurveReferenceUIManager(QComboBox * curveTypeCB, QCheck
|
||||
|
||||
CurveReferenceUIManager::~CurveReferenceUIManager()
|
||||
{
|
||||
|
||||
delete srcNumRefEditor;
|
||||
}
|
||||
|
||||
#define CURVE_REF_UI_GVAR_SHOW (1 << 0)
|
||||
#define CURVE_REF_UI_SRC_SHOW (1 << 0)
|
||||
#define CURVE_REF_UI_VALUE_SHOW (1 << 1)
|
||||
#define CURVE_REF_UI_REF_SHOW (1 << 2)
|
||||
#define CURVE_REF_UI_CURVE_SHOW (1 << 3)
|
||||
@@ -212,89 +210,72 @@ CurveReferenceUIManager::~CurveReferenceUIManager()
|
||||
void CurveReferenceUIManager::update()
|
||||
{
|
||||
lock = true;
|
||||
|
||||
if (srcNumRefEditor)
|
||||
srcNumRefEditor->setLock(true);
|
||||
|
||||
int widgetsMask = 0;
|
||||
|
||||
if (curveRef.type == CurveReference::CURVE_REF_DIFF || curveRef.type == CurveReference::CURVE_REF_EXPO) {
|
||||
if (hasCapabilityGvars)
|
||||
widgetsMask |= CURVE_REF_UI_GVAR_SHOW;
|
||||
if (curveRef.isValueNumber()) {
|
||||
curveGVarCB->setChecked(false);
|
||||
curveValueSB->setValue(curveRef.value);
|
||||
widgetsMask |= CURVE_REF_UI_VALUE_SHOW;
|
||||
if (srcNumRefEditor) {
|
||||
if (curveRef.type == CurveReference::CURVE_REF_DIFF || curveRef.type == CurveReference::CURVE_REF_EXPO) {
|
||||
srcNumRefEditor->setVisible(true);
|
||||
srcNumRefEditor->update();
|
||||
}
|
||||
else {
|
||||
curveGVarCB->setChecked(true);
|
||||
srcNumRefEditor->setVisible(false);
|
||||
widgetsMask |= CURVE_REF_UI_REF_SHOW;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
widgetsMask |= CURVE_REF_UI_REF_SHOW;
|
||||
}
|
||||
|
||||
if (curveRef.type == CurveReference::CURVE_REF_CUSTOM)
|
||||
if (curveRef.type == CurveReference::CURVE_REF_CUSTOM && curveRef.value != 0)
|
||||
widgetsMask |= CURVE_REF_UI_CURVE_SHOW;
|
||||
|
||||
if (cboType)
|
||||
cboType->setCurrentIndex(cboType->findData(curveRef.type));
|
||||
|
||||
if (curveTypeCB) {
|
||||
curveTypeCB->setCurrentIndex(curveTypeCB->findData(curveRef.type));
|
||||
curveTypeCB->show();
|
||||
}
|
||||
|
||||
if (curveGVarCB)
|
||||
curveGVarCB->setVisible(widgetsMask & CURVE_REF_UI_GVAR_SHOW);
|
||||
|
||||
if (curveValueSB)
|
||||
curveValueSB->setVisible(widgetsMask & CURVE_REF_UI_VALUE_SHOW);
|
||||
|
||||
if (curveValueCB) {
|
||||
if (cboCurveFunc) {
|
||||
if (curveRef.isValueReference())
|
||||
populateValueCB(curveValueCB);
|
||||
curveValueCB->setVisible(widgetsMask & CURVE_REF_UI_REF_SHOW);
|
||||
populateValueCB(cboCurveFunc);
|
||||
cboCurveFunc->setVisible(widgetsMask & CURVE_REF_UI_REF_SHOW);
|
||||
}
|
||||
|
||||
if (curveValueCB && curveImageWidget) {
|
||||
curveImageWidget->draw();
|
||||
curveImageWidget->setVisible(widgetsMask & CURVE_REF_UI_CURVE_SHOW);
|
||||
if (curveImage) {
|
||||
if (widgetsMask & CURVE_REF_UI_CURVE_SHOW) {
|
||||
curveImage->setIndex(curveRef.value);
|
||||
if (abs(curveRef.value) > 0 && abs(curveRef.value) <= CPN_MAX_CURVES)
|
||||
curveImage->setPen(colors[abs(curveRef.value) - 1], 3);
|
||||
else
|
||||
curveImage->setPen(Qt::black, 3);
|
||||
}
|
||||
curveImage->draw();
|
||||
curveImage->setVisible(widgetsMask & CURVE_REF_UI_CURVE_SHOW);
|
||||
}
|
||||
|
||||
emit resized();
|
||||
|
||||
if (srcNumRefEditor)
|
||||
srcNumRefEditor->setLock(false);
|
||||
|
||||
lock = false;
|
||||
}
|
||||
|
||||
void CurveReferenceUIManager::gvarCBChanged(int state)
|
||||
void CurveReferenceUIManager::cboTypeChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
curveRef.value = CurveReference::getDefaultValue(curveRef.type, state);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void CurveReferenceUIManager::typeChanged(int value)
|
||||
{
|
||||
if (!lock) {
|
||||
CurveReference::CurveRefType type = (CurveReference::CurveRefType)curveTypeCB->itemData(curveTypeCB->currentIndex()).toInt();
|
||||
CurveReference::CurveRefType type = (CurveReference::CurveRefType)cboType->itemData(index).toInt();
|
||||
curveRef = CurveReference(type, CurveReference::getDefaultValue(type));
|
||||
if (curveImageWidget && curveRef.type == CurveReference::CURVE_REF_CUSTOM)
|
||||
curveImageWidget->setIndex(abs(curveRef.value) - 1);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void CurveReferenceUIManager::valueSBChanged()
|
||||
void CurveReferenceUIManager::cboCurveFuncChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
curveRef.value = curveValueSB->value();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void CurveReferenceUIManager::valueCBChanged()
|
||||
{
|
||||
if (!lock) {
|
||||
curveRef.value = curveValueCB->itemData(curveValueCB->currentIndex()).toInt();
|
||||
if (curveImageWidget && curveRef.type == CurveReference::CURVE_REF_CUSTOM)
|
||||
curveImageWidget->setIndex(abs(curveRef.value) - 1);
|
||||
if (!cboType)
|
||||
curveRef.type = CurveReference::CURVE_REF_CUSTOM;
|
||||
curveRef.value = cboCurveFunc->itemData(index).toInt();
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -303,10 +284,6 @@ void CurveReferenceUIManager::populateValueCB(QComboBox * cb)
|
||||
{
|
||||
if (cb) {
|
||||
switch (curveRef.type) {
|
||||
case CurveReference::CURVE_REF_DIFF:
|
||||
case CurveReference::CURVE_REF_EXPO:
|
||||
cb->setModel(filteredModelFactory->getItemModel(CurveRefFilteredFactory::CRFIM_GVARREF));
|
||||
break;
|
||||
case CurveReference::CURVE_REF_FUNC:
|
||||
cb->setModel(filteredModelFactory->getItemModel(CurveRefFilteredFactory::CRFIM_FUNC));
|
||||
break;
|
||||
@@ -324,7 +301,7 @@ void CurveReferenceUIManager::populateValueCB(QComboBox * cb)
|
||||
void CurveReferenceUIManager::curveImageDoubleClicked()
|
||||
{
|
||||
if (curveRef.type == CurveReference::CURVE_REF_CUSTOM && abs(curveRef.value) > 0)
|
||||
curveImageWidget->edit();
|
||||
curveImage->edit();
|
||||
}
|
||||
|
||||
void CurveReferenceUIManager::connectItemModelEvents(const FilteredItemModel * itemModel)
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "rawsource.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
@@ -27,11 +29,13 @@
|
||||
#include <QSpinBox>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
class GeneralSettings;
|
||||
class ModelData;
|
||||
class CurveRefFilteredFactory;
|
||||
class CompoundItemModelFactory;
|
||||
class FilteredItemModel;
|
||||
class CurveImageWidget;
|
||||
class SourceNumRefEditor;
|
||||
|
||||
class CurveReference {
|
||||
|
||||
@@ -64,7 +68,8 @@ class CurveReference {
|
||||
const bool isSet() const { return !isEmpty(); }
|
||||
const bool isValueNumber() const;
|
||||
const bool isValueReference() const { return !isValueNumber(); }
|
||||
const QString toString(const ModelData * model = nullptr, bool verbose = true) const;
|
||||
const QString toString(const ModelData * model = nullptr, bool verbose = true, const GeneralSettings * const generalSettings = nullptr,
|
||||
Board::Type board = Board::BOARD_UNKNOWN, bool prefixCustomName = true) const;
|
||||
const bool isAvailable() const;
|
||||
|
||||
CurveRefType type;
|
||||
@@ -91,13 +96,17 @@ class CurveReferenceUIManager : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CurveReferenceUIManager(QComboBox *curveTypeCB, QCheckBox *curveGVarCB, QSpinBox *curveValueSB, QComboBox *curveValueCB,
|
||||
QLabel *curveImage, CurveReference & curve, ModelData & model, CompoundItemModelFactory * sharedItemModels,
|
||||
CurveRefFilteredFactory * curveRefFilteredFactory, QObject * parent = nullptr);
|
||||
explicit CurveReferenceUIManager(QComboBox * cboType, QCheckBox * chkUseSource, QSpinBox * sbxValue, QComboBox * cboSource,
|
||||
QComboBox * cboCurveFunc, CurveImageWidget * curveImage, CurveReference & curveRef,
|
||||
ModelData & model, CompoundItemModelFactory * sharedItemModels,
|
||||
CurveRefFilteredFactory * curveRefFilteredFactory, FilteredItemModel * sourceItemModel,
|
||||
QObject * parent = nullptr);
|
||||
|
||||
explicit CurveReferenceUIManager(QComboBox *curveValueCB, CurveReference & curve, ModelData & model, CompoundItemModelFactory * sharedItemModels,
|
||||
CurveRefFilteredFactory * curveRefFilteredFactory, QObject * parent = nullptr) :
|
||||
CurveReferenceUIManager(nullptr, nullptr, nullptr, curveValueCB, nullptr, curve, model, sharedItemModels, curveRefFilteredFactory, parent) {}
|
||||
explicit CurveReferenceUIManager(QComboBox *cboCurveFunc, CurveImageWidget * curveImage, CurveReference & curveRef, ModelData & model,
|
||||
CompoundItemModelFactory * sharedItemModels, CurveRefFilteredFactory * curveRefFilteredFactory,
|
||||
QObject * parent = nullptr) :
|
||||
CurveReferenceUIManager(nullptr, nullptr, nullptr, nullptr, cboCurveFunc, curveImage, curveRef, model, sharedItemModels,
|
||||
curveRefFilteredFactory, nullptr, parent) {}
|
||||
|
||||
virtual ~CurveReferenceUIManager();
|
||||
|
||||
@@ -105,28 +114,25 @@ class CurveReferenceUIManager : public QObject {
|
||||
void resized();
|
||||
|
||||
protected slots:
|
||||
void gvarCBChanged(int);
|
||||
void typeChanged(int);
|
||||
void valueSBChanged();
|
||||
void valueCBChanged();
|
||||
void cboTypeChanged(int);
|
||||
void cboCurveFuncChanged(int);
|
||||
void update();
|
||||
void curveImageDoubleClicked();
|
||||
void onItemModelAboutToBeUpdated();
|
||||
void onItemModelUpdateComplete();
|
||||
|
||||
private:
|
||||
QComboBox *curveTypeCB;
|
||||
QCheckBox *curveGVarCB;
|
||||
QSpinBox *curveValueSB;
|
||||
QComboBox *curveValueCB;
|
||||
CurveReference & curveRef;
|
||||
ModelData & model;
|
||||
CompoundItemModelFactory *sharedItemModels;
|
||||
QComboBox *cboType;
|
||||
QCheckBox *chkUseSource;
|
||||
QSpinBox *sbxValue;
|
||||
QComboBox *cboSource;
|
||||
QComboBox *cboCurveFunc;
|
||||
CurveImageWidget *curveImage;
|
||||
CurveReference &curveRef;
|
||||
ModelData &model;
|
||||
CurveRefFilteredFactory *filteredModelFactory;
|
||||
bool lock;
|
||||
CurveImageWidget *curveImageWidget = nullptr;
|
||||
|
||||
bool hasCapabilityGvars;
|
||||
SourceNumRefEditor *srcNumRefEditor;
|
||||
|
||||
void connectItemModelEvents(const FilteredItemModel * itemModel);
|
||||
void populateValueCB(QComboBox * cb);
|
||||
|
||||
@@ -35,8 +35,8 @@ Node convert<ExpoData>::encode(const ExpoData& rhs)
|
||||
node["chn"] = rhs.chn;
|
||||
node["swtch"] = rhs.swtch;
|
||||
node["flightModes"] = YamlWriteFlightModes(rhs.flightModes);
|
||||
node["weight"] = YamlWriteMixWeight(rhs.weight);
|
||||
node["offset"] = YamlWriteMixWeight(rhs.offset);
|
||||
node["weight"] = YamlSourceNumRefEncode(rhs.weight);
|
||||
node["offset"] = YamlSourceNumRefEncode(rhs.offset);
|
||||
node["curve"] = rhs.curve;
|
||||
node["trimSource"] = rhs.carryTrim; // temporary for 2.8.1, trimSource in 2.9
|
||||
node["name"] = rhs.name;
|
||||
@@ -54,10 +54,10 @@ bool convert<ExpoData>::decode(const Node& node, ExpoData& rhs)
|
||||
rhs.flightModes = YamlReadFlightModes(node["flightModes"]);
|
||||
}
|
||||
if (node["weight"]) {
|
||||
rhs.weight = YamlReadMixWeight(node["weight"]);
|
||||
rhs.weight = YamlSourceNumRefDecode(node["weight"]);
|
||||
}
|
||||
if (node["offset"]) {
|
||||
rhs.offset = YamlReadMixWeight(node["offset"]);
|
||||
rhs.offset = YamlSourceNumRefDecode(node["offset"]);
|
||||
}
|
||||
node["curve"] >> rhs.curve;
|
||||
if (node["carryTrim"]) { // 2.9 - change bugged carryTrim to trimSource
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "yaml_rawswitch.h"
|
||||
#include "yaml_rawsource.h"
|
||||
#include "curvereference.h"
|
||||
#include "sourcenumref.h"
|
||||
|
||||
static const YamlLookupTable mixMultiplexLut = {
|
||||
{ MLTPX_ADD, "ADD" },
|
||||
@@ -32,46 +33,55 @@ static const YamlLookupTable mixMultiplexLut = {
|
||||
#define GVAR_SMALL 128
|
||||
#define CPN_GV1 1024
|
||||
|
||||
int32_t YamlReadMixWeight(const YAML::Node& node)
|
||||
int32_t YamlSourceNumRefDecode(const YAML::Node& node)
|
||||
{
|
||||
std::string val = node.as<std::string>();
|
||||
if ((val.size() >= 4)
|
||||
|
||||
if (modelSettingsVersion < SemanticVersion(QString("2.11.0"))) {
|
||||
if ((val.size() >= 4)
|
||||
&& (val[0] == '-')
|
||||
&& (val[1] == 'G')
|
||||
&& (val[2] == 'V')
|
||||
&& (val[3] >= '1')
|
||||
&& (val[3] <= '9')) {
|
||||
|
||||
return -10000 - std::stoi(val.substr(3));
|
||||
}
|
||||
std::stringstream src(val.substr(3));
|
||||
int gv = 0;
|
||||
src >> gv;
|
||||
return RawSource(SOURCE_TYPE_GVAR, gv).toValue() * -1;
|
||||
}
|
||||
|
||||
if ((val.size() >= 3)
|
||||
if ((val.size() >= 3)
|
||||
&& (val[0] == 'G')
|
||||
&& (val[1] == 'V')
|
||||
&& (val[2] >= '1')
|
||||
&& (val[2] <= '9')) {
|
||||
|
||||
return 10000 + std::stoi(val.substr(2));
|
||||
std::stringstream src(val.substr(2));
|
||||
int gv = 0;
|
||||
src >> gv;
|
||||
return RawSource(SOURCE_TYPE_GVAR, gv).toValue();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return std::stoi(val);
|
||||
} catch(...) {
|
||||
throw YAML::TypedBadConversion<int>(node.Mark());
|
||||
}
|
||||
int i = val[0] == '-' ? 1 : 0;
|
||||
|
||||
if (val[i] >= '0' && val[i] <= '9')
|
||||
try {
|
||||
return std::stoi(val);
|
||||
} catch(...) {
|
||||
throw YAML::TypedBadConversion<int>(node.Mark());
|
||||
}
|
||||
else
|
||||
return YamlRawSourceDecode(val).toValue();
|
||||
}
|
||||
|
||||
std::string YamlWriteMixWeight(int32_t sval)
|
||||
std::string YamlSourceNumRefEncode(int32_t sval)
|
||||
{
|
||||
if (sval < -10000) {
|
||||
int n = -sval - 10000;
|
||||
return std::string("-GV") + std::to_string(n);
|
||||
} else if (sval > 10000) {
|
||||
int n = sval - 10000;
|
||||
return std::string("GV") + std::to_string(n);
|
||||
}
|
||||
|
||||
return std::to_string(sval);
|
||||
if (SourceNumRef(sval).isNumber())
|
||||
return std::to_string(sval);
|
||||
else
|
||||
return YamlRawSourceEncode(RawSource(sval));
|
||||
}
|
||||
|
||||
uint32_t YamlReadFlightModes(const YAML::Node& node)
|
||||
@@ -108,7 +118,7 @@ Node convert<CurveReference>::encode(const CurveReference& rhs)
|
||||
{
|
||||
Node node;
|
||||
node["type"] = (int)rhs.type;
|
||||
node["value"] = YamlWriteMixWeight(rhs.value);
|
||||
node["value"] = YamlSourceNumRefEncode(rhs.value);
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -119,7 +129,7 @@ bool convert<CurveReference>::decode(const Node& node, CurveReference& rhs)
|
||||
node["type"] >> type;
|
||||
rhs.type = (CurveReference::CurveRefType)type;
|
||||
if (node["value"]) {
|
||||
rhs.value = YamlReadMixWeight(node["value"]);
|
||||
rhs.value = YamlSourceNumRefDecode(node["value"]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -129,7 +139,7 @@ Node convert<MixData>::encode(const MixData& rhs)
|
||||
Node node;
|
||||
node["destCh"] = rhs.destCh - 1;
|
||||
node["srcRaw"] = rhs.srcRaw;
|
||||
node["weight"] = YamlWriteMixWeight(rhs.weight);
|
||||
node["weight"] = YamlSourceNumRefEncode(rhs.weight);
|
||||
node["swtch"] = rhs.swtch;
|
||||
node["curve"] = rhs.curve;
|
||||
node["delayUp"] = rhs.delayUp;
|
||||
@@ -141,7 +151,7 @@ Node convert<MixData>::encode(const MixData& rhs)
|
||||
node["mltpx"] = rhs.mltpx;
|
||||
node["mixWarn"] = rhs.mixWarn;
|
||||
node["flightModes"] = YamlWriteFlightModes(rhs.flightModes);
|
||||
node["offset"] = YamlWriteMixWeight(rhs.sOffset);
|
||||
node["offset"] = YamlSourceNumRefEncode(rhs.sOffset);
|
||||
node["name"] = rhs.name;
|
||||
return node;
|
||||
}
|
||||
@@ -151,7 +161,7 @@ bool convert<MixData>::decode(const Node& node, MixData& rhs)
|
||||
node["destCh"] >> ioffset_int((int&)rhs.destCh, -1);
|
||||
node["srcRaw"] >> rhs.srcRaw;
|
||||
if (node["weight"]) {
|
||||
rhs.weight = YamlReadMixWeight(node["weight"]);
|
||||
rhs.weight = YamlSourceNumRefDecode(node["weight"]);
|
||||
}
|
||||
node["swtch"] >> rhs.swtch;
|
||||
node["curve"] >> rhs.curve;
|
||||
@@ -167,7 +177,7 @@ bool convert<MixData>::decode(const Node& node, MixData& rhs)
|
||||
rhs.flightModes = YamlReadFlightModes(node["flightModes"]);
|
||||
}
|
||||
if (node["offset"]) {
|
||||
rhs.sOffset = YamlReadMixWeight(node["offset"]);
|
||||
rhs.sOffset = YamlSourceNumRefDecode(node["offset"]);
|
||||
}
|
||||
node["name"] >> rhs.name;
|
||||
return true;
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#include "yaml_ops.h"
|
||||
#include "mixdata.h"
|
||||
|
||||
int32_t YamlReadMixWeight(const YAML::Node& node);
|
||||
std::string YamlWriteMixWeight(int32_t sval);
|
||||
int32_t YamlSourceNumRefDecode(const YAML::Node& node);
|
||||
std::string YamlSourceNumRefEncode(int32_t sval);
|
||||
|
||||
uint32_t YamlReadFlightModes(const YAML::Node& node);
|
||||
std::string YamlWriteFlightModes(uint32_t val);
|
||||
|
||||
@@ -546,6 +546,7 @@ struct convert<LimitData> {
|
||||
node["symetrical"] = (int)rhs.symetrical;
|
||||
node["name"] = rhs.name;
|
||||
node["curve"] = rhs.curve.value;
|
||||
// rhs.curve.type is not encoded
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -565,6 +566,7 @@ struct convert<LimitData> {
|
||||
node["symetrical"] >> rhs.symetrical;
|
||||
node["name"] >> rhs.name;
|
||||
node["curve"] >> rhs.curve.value;
|
||||
rhs.curve.type = CurveReference::CURVE_REF_CUSTOM; // this is not encoded but needed internally so force type
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "opentxeeprom.h"
|
||||
#include "customdebug.h"
|
||||
#include "opentxinterface.h"
|
||||
#include "sourcenumref.h"
|
||||
#include "adjustmentreference.h"
|
||||
|
||||
using namespace Board;
|
||||
|
||||
@@ -805,6 +807,11 @@ class CurveReferenceField: public TransformedField {
|
||||
{
|
||||
curve.type = (CurveReference::CurveRefType)_curve_type;
|
||||
curve.value = smallGvarExport(_curve_value);
|
||||
// 2,11 num or gvar changed to SourceNumRef
|
||||
if ((curve.type == CurveReference::CURVE_REF_DIFF || curve.type == CurveReference::CURVE_REF_EXPO) &&
|
||||
AdjustmentReference(curve.value).type == AdjustmentReference::ADJUST_REF_GVAR)
|
||||
curve.value = RawSource(SOURCE_TYPE_GVAR, AdjustmentReference(curve.value).value).toValue();
|
||||
|
||||
qCDebug(eepromImport) << QString("imported CurveReference(%1)").arg(curve.toString());
|
||||
}
|
||||
|
||||
@@ -1114,8 +1121,20 @@ class MixField: public TransformedField {
|
||||
}
|
||||
}
|
||||
|
||||
// 2.11
|
||||
if ((mix.curve.type == CurveReference::CURVE_REF_DIFF || mix.curve.type == CurveReference::CURVE_REF_EXPO) &&
|
||||
AdjustmentReference(mix.curve.value).type == AdjustmentReference::ADJUST_REF_GVAR)
|
||||
mix.curve.value = RawSource(SOURCE_TYPE_GVAR, AdjustmentReference(mix.curve.value).value).toValue();
|
||||
|
||||
importGvarParam(mix.weight, _weight, version);
|
||||
// 2.11
|
||||
if (AdjustmentReference(mix.weight).type == AdjustmentReference::ADJUST_REF_GVAR)
|
||||
mix.weight = RawSource(SOURCE_TYPE_GVAR, AdjustmentReference(mix.weight).value).toValue();
|
||||
|
||||
importGvarParam(mix.sOffset, _offset, version);
|
||||
// 2.11
|
||||
if (AdjustmentReference(mix.sOffset).type == AdjustmentReference::ADJUST_REF_GVAR)
|
||||
mix.sOffset = RawSource(SOURCE_TYPE_GVAR, AdjustmentReference(mix.sOffset).value).toValue();
|
||||
|
||||
qCDebug(eepromImport) << QString("imported %1: ch %2, name '%3'").arg(internalField.getName()).arg(mix.destCh).arg(mix.name);
|
||||
}
|
||||
@@ -1222,9 +1241,15 @@ class InputField: public TransformedField {
|
||||
}
|
||||
|
||||
expo.weight = smallGvarExport(_weight);
|
||||
// 2.11
|
||||
if (AdjustmentReference(expo.weight).type == AdjustmentReference::ADJUST_REF_GVAR)
|
||||
expo.weight = RawSource(SOURCE_TYPE_GVAR, AdjustmentReference(expo.weight).value).toValue();
|
||||
|
||||
if (IS_STM32(board) || version >= 218) {
|
||||
expo.offset = smallGvarExport(_offset);
|
||||
// 2.11
|
||||
if (AdjustmentReference(expo.offset).type == AdjustmentReference::ADJUST_REF_GVAR)
|
||||
expo.offset = RawSource(SOURCE_TYPE_GVAR, AdjustmentReference(expo.offset).value).toValue();
|
||||
}
|
||||
|
||||
if (!IS_TARANIS(board) && version < 218) {
|
||||
@@ -1235,6 +1260,13 @@ class InputField: public TransformedField {
|
||||
else
|
||||
expo.curve = CurveReference(CurveReference::CURVE_REF_FUNC, _curveParam);
|
||||
}
|
||||
|
||||
// 2.11
|
||||
if ((expo.curve.type == CurveReference::CURVE_REF_DIFF || expo.curve.type == CurveReference::CURVE_REF_EXPO) &&
|
||||
AdjustmentReference(expo.curve.value).type == AdjustmentReference::ADJUST_REF_GVAR)
|
||||
expo.curve.value = RawSource(SOURCE_TYPE_GVAR, AdjustmentReference(expo.curve.value).value).toValue();
|
||||
|
||||
|
||||
qCDebug(eepromImport) << QString("imported %1: ch %2 name '%3'").arg(internalField.getName()).arg(expo.chn).arg(expo.name);
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting
|
||||
QString RawSource::toString(const ModelData * model, const GeneralSettings * const generalSettings, Board::Type board, bool prefixCustomName) const
|
||||
{
|
||||
if (index < 0)
|
||||
return CPN_STR_SRC_INDICATOR_INVERT % RawSource(type, -index).toString(model, generalSettings, board, prefixCustomName);
|
||||
return CPN_STR_SRC_INDICATOR_NEG % RawSource(type, -index).toString(model, generalSettings, board, prefixCustomName);
|
||||
|
||||
if (board == Board::BOARD_UNKNOWN)
|
||||
board = getCurrentBoard();
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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 "sourcenumref.h"
|
||||
#include "filtereditemmodels.h"
|
||||
#include "helpers.h"
|
||||
|
||||
QString SourceNumRef::toString(const ModelData * model, const GeneralSettings * const generalSettings,
|
||||
Board::Type board, bool prefixCustomName) const
|
||||
{
|
||||
if (srcNum.type == SOURCE_TYPE_NONE)
|
||||
return QString::number(srcNum.index);
|
||||
else
|
||||
return srcNum.toString(model, generalSettings, board, prefixCustomName);
|
||||
}
|
||||
|
||||
// static
|
||||
int SourceNumRef::getDefault(int useSource, int dflt)
|
||||
{
|
||||
if (useSource)
|
||||
return 0;
|
||||
else
|
||||
return dflt;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SourceNumRefEditor
|
||||
*/
|
||||
|
||||
SourceNumRefEditor::SourceNumRefEditor(int & srcNumValue, QCheckBox * chkUseSource, QSpinBox * sbxValue, QComboBox * cboValue,
|
||||
int defValue, int minValue, int maxValue, int step,
|
||||
ModelData & model, FilteredItemModel * sourceItemModel, QObject * parent) :
|
||||
QObject(parent),
|
||||
srcNumValue(srcNumValue),
|
||||
chkUseSource(chkUseSource),
|
||||
sbxValue(sbxValue),
|
||||
cboValue(cboValue),
|
||||
defValue(defValue),
|
||||
model(model),
|
||||
lock(false)
|
||||
{
|
||||
if (chkUseSource) {
|
||||
connect(chkUseSource, &QCheckBox::stateChanged, this, &SourceNumRefEditor::chkUseSourceChanged);
|
||||
}
|
||||
|
||||
if (sbxValue) {
|
||||
sbxValue->setMinimum(minValue);
|
||||
sbxValue->setMaximum(maxValue);
|
||||
sbxValue->setSingleStep(step);
|
||||
sbxValue->setValue(defValue);
|
||||
connect(sbxValue, &QSpinBox::editingFinished, this, &SourceNumRefEditor::sbxValueChanged);
|
||||
}
|
||||
|
||||
if (cboValue) {
|
||||
cboValue->setModel(sourceItemModel);
|
||||
cboValue->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
cboValue->setMaxVisibleItems(10);
|
||||
cboValue->setCurrentIndex(Helpers::getFirstPosValueIndex(cboValue));
|
||||
connect(cboValue, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SourceNumRefEditor::cboValueChanged);
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void SourceNumRefEditor::chkUseSourceChanged(int state)
|
||||
{
|
||||
if (!lock) {
|
||||
srcNumValue = SourceNumRef::getDefault(state, defValue);
|
||||
|
||||
if (state == Qt::Checked) {
|
||||
cboValue->setCurrentIndex(cboValue->findData(srcNumValue));
|
||||
if (cboValue->currentIndex() < 0)
|
||||
cboValue->setCurrentIndex(Helpers::getFirstPosValueIndex(cboValue));
|
||||
}
|
||||
else
|
||||
sbxValue->setValue(srcNumValue);
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void SourceNumRefEditor::sbxValueChanged()
|
||||
{
|
||||
if (!lock) {
|
||||
srcNumValue = sbxValue->value();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void SourceNumRefEditor::cboValueChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
srcNumValue = cboValue->itemData(index).toInt();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void SourceNumRefEditor::setVisible(bool state)
|
||||
{
|
||||
chkUseSource->setVisible(state);
|
||||
cboValue->setVisible(state);
|
||||
sbxValue->setVisible(state);
|
||||
}
|
||||
|
||||
void SourceNumRefEditor::update()
|
||||
{
|
||||
lock = true;
|
||||
|
||||
if (SourceNumRef(srcNumValue).isNumber()) {
|
||||
if (chkUseSource)
|
||||
chkUseSource->setChecked(false);
|
||||
|
||||
if (sbxValue) {
|
||||
sbxValue->setValue(srcNumValue);
|
||||
sbxValue->setVisible(true);
|
||||
}
|
||||
|
||||
if (cboValue)
|
||||
cboValue->setVisible(false);
|
||||
}
|
||||
else {
|
||||
if (chkUseSource)
|
||||
chkUseSource->setChecked(true);
|
||||
|
||||
if (sbxValue)
|
||||
sbxValue->setVisible(false);
|
||||
|
||||
if (cboValue) {
|
||||
cboValue->setCurrentIndex(cboValue->findData(srcNumValue));
|
||||
cboValue->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
emit resized();
|
||||
|
||||
lock = false;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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 "rawsource.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QSpinBox>
|
||||
|
||||
class FilteredItemModel;
|
||||
|
||||
/*
|
||||
This class takes advantage of RawSource's assumption that small values must be SOURCE_TYPE_NONE ie zero
|
||||
albeit anything other than value zero is unexpected. However there is no setter validation to stop unknown values.
|
||||
|
||||
Also SOURCE_TYPE_NONE must be excluded from selection lists.
|
||||
It would not make sense anyway as it equates to value 0 and thus ambiguous.
|
||||
*/
|
||||
|
||||
class SourceNumRef {
|
||||
|
||||
Q_DECLARE_TR_FUNCTIONS(SourceNumRef)
|
||||
|
||||
public:
|
||||
SourceNumRef() : srcNum(RawSource()) {}
|
||||
explicit SourceNumRef(int value) : srcNum(RawSource(value)) {}
|
||||
SourceNumRef(RawSourceType type, int index = 0) : srcNum(RawSource(type, index)) {}
|
||||
|
||||
virtual ~SourceNumRef() {}
|
||||
|
||||
int toValue() { return srcNum.toValue(); }
|
||||
|
||||
QString toString(const ModelData * model = nullptr, const GeneralSettings * const generalSettings = nullptr,
|
||||
Board::Type board = Board::BOARD_UNKNOWN, bool prefixCustomName = true) const;
|
||||
|
||||
const bool isNumber() const { return srcNum.type == SOURCE_TYPE_NONE; }
|
||||
const bool isSource() const { return srcNum.type != SOURCE_TYPE_NONE; }
|
||||
static int getDefault(int useSource, int dflt);
|
||||
|
||||
private:
|
||||
RawSource srcNum;
|
||||
};
|
||||
|
||||
class SourceNumRefEditor : public QObject {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SourceNumRefEditor(int & srcNumValue, QCheckBox * chkUseSource, QSpinBox * sbxValue, QComboBox * cboValue,
|
||||
int defValue, int minValue, int maxValue, int step,
|
||||
ModelData & model, FilteredItemModel * sourceItemModel, QObject * parent = nullptr);
|
||||
|
||||
virtual ~SourceNumRefEditor() {}
|
||||
|
||||
void setLock(bool state) { lock = state; }
|
||||
void setVisible(bool state);
|
||||
void update();
|
||||
|
||||
signals:
|
||||
void resized();
|
||||
|
||||
protected slots:
|
||||
void chkUseSourceChanged(int state);
|
||||
void sbxValueChanged();
|
||||
void cboValueChanged(int index);
|
||||
|
||||
protected:
|
||||
int &srcNumValue;
|
||||
QCheckBox *chkUseSource;
|
||||
QSpinBox *sbxValue;
|
||||
QComboBox *cboValue;
|
||||
int defValue;
|
||||
ModelData &model;
|
||||
bool lock;
|
||||
};
|
||||
Reference in New Issue
Block a user