Merge remote-tracking branch 'origin/elecpower/dynamic-datamodels' into elecpower/cpn-telemetry-edit

This commit is contained in:
elecpower
2021-01-09 06:55:33 +11:00
50 changed files with 2575 additions and 1138 deletions
@@ -19,7 +19,7 @@
*/
#include "adjustmentreference.h"
#include "radiodata.h" // for ModelData
#include "modeldata.h"
AdjustmentReference::AdjustmentReference(int value)
{
@@ -76,3 +76,8 @@ QString AdjustmentReference::toString(const ModelData * model, const bool sign)
}
return ret;
}
const bool AdjustmentReference::isAvailable() const
{
return true;
}
@@ -45,6 +45,7 @@ class AdjustmentReference {
bool isSet() const { return type != ADJUST_REF_VALUE || value != 0; }
bool isValid(const int value) const;
QString toString(const ModelData * model = nullptr, const bool sign = false) const;
const bool isAvailable() const;
inline const int toValue() const
{
+75 -99
View File
@@ -22,7 +22,7 @@
#include "adjustmentreference.h"
#include "helpers.h"
#include "modeldata.h"
#include "rawitemfilteredmodel.h"
#include "filtereditemmodels.h"
const QString CurveReference::toString(const ModelData * model, bool verbose) const
{
@@ -63,6 +63,11 @@ const bool CurveReference::isValueNumber() const
return (type == CURVE_REF_DIFF || type == CURVE_REF_EXPO) && AdjustmentReference(value).type == AdjustmentReference::ADJUST_REF_VALUE;
}
const bool CurveReference::isAvailable() const
{
return true;
}
// static
int CurveReference::getDefaultValue(const CurveRefType type, const bool isGVar)
{
@@ -86,8 +91,6 @@ QString CurveReference::typeToString(const CurveRefType type)
return strl.at(idx);
}
constexpr int MAX_CURVE_REF_FUNC { 6 };
// static
QString CurveReference::functionToString(const int value)
{
@@ -100,76 +103,65 @@ QString CurveReference::functionToString(const int value)
return strl.at(idx);
}
// static
bool CurveReference::isTypeAvailable(const CurveRefType type)
{
bool ret = false;
Firmware * fw = getCurrentFirmware();
switch(type) {
case CURVE_REF_DIFF:
if (fw->getCapability(HasInputDiff))
ret = true;
break;
case CURVE_REF_EXPO:
if (fw->getCapability(HasMixerExpo))
ret = true;
break;
case CURVE_REF_FUNC:
case CURVE_REF_CUSTOM:
ret = true;
break;
}
return ret;
}
// static
bool CurveReference::isFunctionAvailable(const int value)
{
return true;
}
// static
int CurveReference::functionCount()
{
return 6;
}
/*
* CurveReferenceUIManager
*/
constexpr int CURVE_REF_UI_HIDE_DIFF { 0x01 };
constexpr int CURVE_REF_UI_HIDE_EXPO { 0x02 };
constexpr int CURVE_REF_UI_HIDE_NEGATIVE_CURVES { 0x04 };
// static
bool CurveReferenceUIManager::firsttime { true };
int CurveReferenceUIManager::flags { 0 };
bool CurveReferenceUIManager::hasCapabilityGvars { false };
int CurveReferenceUIManager::numCurves { 0 };
RawItemFilteredModel * CurveReferenceUIManager::curveItemModel { nullptr };
QStandardItemModel * CurveReferenceUIManager::tempModel { nullptr };
CurveReferenceUIManager::CurveReferenceUIManager(QComboBox * curveValueCB, CurveReference & curve, const ModelData & model,
RawItemFilteredModel * curveItemModel, QObject * parent) :
QObject(parent),
curveTypeCB(nullptr),
curveGVarCB(nullptr),
curveValueSB(nullptr),
curveValueCB(curveValueCB),
curve(curve),
model(model),
lock(false)
{
init(curveItemModel);
}
CurveReferenceUIManager::CurveReferenceUIManager(QComboBox * curveTypeCB, QCheckBox * curveGVarCB, QSpinBox * curveValueSB,
QComboBox * curveValueCB, CurveReference & curve, const ModelData & model,
RawItemFilteredModel * curveItemModel, QObject * parent) :
QComboBox * curveValueCB, CurveReference & curveRef, const ModelData & model,
CurveRefFilteredFactory * curveRefFilteredFactory, QObject * parent) :
QObject(parent),
curveTypeCB(curveTypeCB),
curveGVarCB(curveGVarCB),
curveValueSB(curveValueSB),
curveValueCB(curveValueCB),
curve(curve),
curveRef(curveRef),
model(model),
lock(false)
lock(false),
filteredModelFactory(curveRefFilteredFactory)
{
init(curveItemModel);
}
CurveReferenceUIManager::~CurveReferenceUIManager()
{
delete tempModel;
}
void CurveReferenceUIManager::init(RawItemFilteredModel * curveModel)
{
tempModel = new QStandardItemModel();
if (firsttime) {
firsttime = false;
Firmware * fw = getCurrentFirmware();
hasCapabilityGvars = fw->getCapability(Gvars);
numCurves = fw->getCapability(NumCurves);
curveItemModel = curveModel;
if (!fw->getCapability(HasInputDiff))
flags |= (CURVE_REF_UI_HIDE_DIFF | CURVE_REF_UI_HIDE_NEGATIVE_CURVES);
if (!fw->getCapability(HasMixerExpo))
flags |= CURVE_REF_UI_HIDE_EXPO;
}
hasCapabilityGvars = getCurrentFirmware()->getCapability(Gvars);
if (curveTypeCB) {
populateTypeCB(curveTypeCB, curve);
curveTypeCB->setModel(filteredModelFactory->getItemModel(CurveRefFilteredFactory::CRFIM_TYPE));
curveTypeCB->setCurrentIndex(curveTypeCB->findData((int)curveRef.type));
connect(curveTypeCB, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int)));
}
@@ -182,13 +174,20 @@ void CurveReferenceUIManager::init(RawItemFilteredModel * curveModel)
connect(curveValueSB, SIGNAL(editingFinished()), this, SLOT(valueSBChanged()));
}
curveValueCB->setSizeAdjustPolicy(QComboBox::AdjustToContents);
curveValueCB->setMaxVisibleItems(10);
connect(curveValueCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valueCBChanged()));
if (curveValueCB) {
curveValueCB->setSizeAdjustPolicy(QComboBox::AdjustToContents);
curveValueCB->setMaxVisibleItems(10);
connect(curveValueCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valueCBChanged()));
}
update();
}
CurveReferenceUIManager::~CurveReferenceUIManager()
{
delete filteredModelFactory;
}
#define CURVE_REF_UI_GVAR_SHOW (1<<0)
#define CURVE_REF_UI_VALUE_SHOW (1<<1)
#define CURVE_REF_UI_REF_SHOW (1<<2)
@@ -198,12 +197,12 @@ void CurveReferenceUIManager::update()
lock = true;
int widgetsMask = 0;
if (curve.type == CurveReference::CURVE_REF_DIFF || curve.type == CurveReference::CURVE_REF_EXPO) {
if (curveRef.type == CurveReference::CURVE_REF_DIFF || curveRef.type == CurveReference::CURVE_REF_EXPO) {
if (hasCapabilityGvars)
widgetsMask |= CURVE_REF_UI_GVAR_SHOW;
if (curve.isValueNumber()) {
if (curveRef.isValueNumber()) {
curveGVarCB->setChecked(false);
curveValueSB->setValue(curve.value);
curveValueSB->setValue(curveRef.value);
widgetsMask |= CURVE_REF_UI_VALUE_SHOW;
}
else {
@@ -216,7 +215,7 @@ void CurveReferenceUIManager::update()
}
if(curveTypeCB) {
curveTypeCB->setCurrentIndex(curveTypeCB->findData(curve.type));
curveTypeCB->setCurrentIndex(curveTypeCB->findData(curveRef.type));
curveTypeCB->show();
}
if(curveGVarCB)
@@ -224,8 +223,8 @@ void CurveReferenceUIManager::update()
if(curveValueSB)
curveValueSB->setVisible(widgetsMask & CURVE_REF_UI_VALUE_SHOW);
if(curveValueCB) {
if (curve.isValueReference())
populateValueCB(curveValueCB, curve, &model);
if (curveRef.isValueReference())
populateValueCB(curveValueCB);
curveValueCB->setVisible(widgetsMask & CURVE_REF_UI_REF_SHOW);
}
@@ -235,7 +234,7 @@ void CurveReferenceUIManager::update()
void CurveReferenceUIManager::gvarCBChanged(int state)
{
if (!lock) {
curve.value = CurveReference::getDefaultValue(curve.type, state);
curveRef.value = CurveReference::getDefaultValue(curveRef.type, state);
update();
}
}
@@ -244,7 +243,7 @@ void CurveReferenceUIManager::typeChanged(int value)
{
if (!lock) {
CurveReference::CurveRefType type = (CurveReference::CurveRefType)curveTypeCB->itemData(curveTypeCB->currentIndex()).toInt();
curve = CurveReference(type, CurveReference::getDefaultValue(type));
curveRef = CurveReference(type, CurveReference::getDefaultValue(type));
update();
}
}
@@ -252,7 +251,7 @@ void CurveReferenceUIManager::typeChanged(int value)
void CurveReferenceUIManager::valueSBChanged()
{
if (!lock) {
curve.value = curveValueSB->value();
curveRef.value = curveValueSB->value();
update();
}
}
@@ -260,47 +259,24 @@ void CurveReferenceUIManager::valueSBChanged()
void CurveReferenceUIManager::valueCBChanged()
{
if (!lock) {
curve.value = curveValueCB->itemData(curveValueCB->currentIndex()).toInt();
curveRef.value = curveValueCB->itemData(curveValueCB->currentIndex()).toInt();
update();
}
}
// static
void CurveReferenceUIManager::populateTypeCB(QComboBox * cb, const CurveReference & curveRef)
void CurveReferenceUIManager::populateValueCB(QComboBox * cb)
{
if (cb) {
cb->clear();
for (int i = 0; i <= CurveReference::MAX_CURVE_REF_TYPE; i++) {
if ((curveRef.type == CurveReference::CURVE_REF_DIFF && !(flags & CURVE_REF_UI_HIDE_DIFF)) ||
(curveRef.type == CurveReference::CURVE_REF_EXPO && !(flags & CURVE_REF_UI_HIDE_EXPO)) ||
(curveRef.type != CurveReference::CURVE_REF_DIFF && curveRef.type != CurveReference::CURVE_REF_EXPO))
cb->addItem(CurveReference::typeToString((CurveReference::CurveRefType)i), i);
}
cb->setCurrentIndex(cb->findData((int)curveRef.type));
}
}
// static
void CurveReferenceUIManager::populateValueCB(QComboBox * cb, const CurveReference & curveRef, const ModelData * model)
{
if (cb) {
cb->setModel(tempModel); // do not want to clear/alter the shared curves model and set to nullptr is invalid
switch (curveRef.type) {
case CurveReference::CURVE_REF_DIFF:
case CurveReference::CURVE_REF_EXPO:
cb->clear();
Helpers::populateGVCB(*cb, curveRef.value, *model);
cb->setModel(filteredModelFactory->getItemModel(CurveRefFilteredFactory::CRFIM_GVARREF));
break;
case CurveReference::CURVE_REF_FUNC:
cb->clear();
for (int i = 1; i <= MAX_CURVE_REF_FUNC; i++) {
cb->addItem(CurveReference::functionToString(i), i);
}
cb->setModel(filteredModelFactory->getItemModel(CurveRefFilteredFactory::CRFIM_FUNC));
break;
case CurveReference::CURVE_REF_CUSTOM:
cb->setModel(curveItemModel);
cb->setModel(filteredModelFactory->getItemModel(CurveRefFilteredFactory::CRFIM_CURVE));
break;
default:
break;
+19 -19
View File
@@ -29,7 +29,7 @@
class ModelData;
class RawItemFilteredModel;
class CurveRefFilteredFactory;
class CurveReference {
@@ -63,6 +63,7 @@ class CurveReference {
const bool isValueNumber() const;
const bool isValueReference() const { return !isValueNumber(); }
const QString toString(const ModelData * model = nullptr, bool verbose = true) const;
const bool isAvailable() const;
CurveRefType type;
int value;
@@ -78,6 +79,9 @@ class CurveReference {
static int getDefaultValue(const CurveRefType type, const bool isGVar = false);
static QString typeToString(const CurveRefType type);
static QString functionToString(const int value);
static bool isTypeAvailable(const CurveRefType type);
static bool isFunctionAvailable(const int value);
static int functionCount();
};
class CurveReferenceUIManager : public QObject {
@@ -85,38 +89,34 @@ class CurveReferenceUIManager : public QObject {
Q_OBJECT
public:
CurveReferenceUIManager(QComboBox *curveValueCB, CurveReference & curve, const ModelData & model,
RawItemFilteredModel * curveItemModel, QObject * parent = nullptr);
CurveReferenceUIManager(QComboBox *curveTypeCB, QCheckBox *curveGVarCB, QSpinBox *curveValueSB, QComboBox *curveValueCB,
CurveReference & curve, const ModelData & model, RawItemFilteredModel * curveItemModel, QObject * parent = nullptr);
explicit CurveReferenceUIManager(QComboBox *curveTypeCB, QCheckBox *curveGVarCB, QSpinBox *curveValueSB, QComboBox *curveValueCB,
CurveReference & curve, const ModelData & model, CurveRefFilteredFactory * curveRefFilteredFactory,
QObject * parent = nullptr);
explicit CurveReferenceUIManager(QComboBox *curveValueCB, CurveReference & curve, const ModelData & model,
CurveRefFilteredFactory * curveRefFilteredFactory, QObject * parent = nullptr) :
CurveReferenceUIManager(nullptr, nullptr, nullptr, curveValueCB, curve, model, curveRefFilteredFactory, parent) {}
virtual ~CurveReferenceUIManager();
void init(RawItemFilteredModel * curveModel);
void update();
protected slots:
void gvarCBChanged(int);
void typeChanged(int);
void valueSBChanged();
void valueCBChanged();
void update();
protected:
private:
QComboBox *curveTypeCB;
QCheckBox *curveGVarCB;
QSpinBox *curveValueSB;
QComboBox *curveValueCB;
CurveReference & curve;
CurveReference & curveRef;
const ModelData & model;
bool lock;
static bool firsttime;
static int flags;
static bool hasCapabilityGvars;
static int numCurves;
static RawItemFilteredModel * curveItemModel;
static QStandardItemModel * tempModel;
static void populateTypeCB(QComboBox * cb, const CurveReference & curveRef);
static void populateValueCB(QComboBox * cb, const CurveReference & curveRef, const ModelData * model = nullptr);
bool hasCapabilityGvars;
CurveRefFilteredFactory *filteredModelFactory;
void populateValueCB(QComboBox * cb);
};
#endif // CURVEREFERENCE_H
+81 -16
View File
@@ -38,12 +38,12 @@ bool CustomFunctionData::isEmpty() const
QString CustomFunctionData::nameToString(int index, bool globalContext) const
{
return RadioData::getElementName((globalContext ? tr("GF") : tr("SF")), index+1, 0, true);
return RadioData::getElementName((globalContext ? tr("GF") : tr("SF")), index + 1, 0, true);
}
QString CustomFunctionData::funcToString(const ModelData * model) const
{
if (func >= FuncOverrideCH1 && func <= FuncOverrideCH32)
if (func >= FuncOverrideCH1 && func <= FuncOverrideCHLast)
return tr("Override %1").arg(RawSource(SOURCE_TYPE_CH, func).toString(model));
else if (func == FuncTrainer)
return tr("Trainer Sticks");
@@ -65,8 +65,8 @@ QString CustomFunctionData::funcToString(const ModelData * model) const
return tr("Haptic");
else if (func == FuncReset)
return tr("Reset");
else if (func >= FuncSetTimer1 && func <= FuncSetTimer3)
return tr("Set Timer %1").arg(func-FuncSetTimer1+1);
else if (func >= FuncSetTimer1 && func <= FuncSetTimerLast)
return tr("Set %1").arg(RawSource(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_TIMER1_IDX + func - FuncSetTimer1).toString(model));
else if (func == FuncVario)
return tr("Vario");
else if (func == FuncPlayPrompt)
@@ -90,7 +90,7 @@ QString CustomFunctionData::funcToString(const ModelData * model) const
else if (func == FuncBackgroundMusicPause)
return tr("Background Music Pause");
else if (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast)
return tr("Adjust %1").arg(RawSource(SOURCE_TYPE_GVAR, func-FuncAdjustGV1).toString(model));
return tr("Adjust %1").arg(RawSource(SOURCE_TYPE_GVAR, func - FuncAdjustGV1).toString(model));
else if (func == FuncSetFailsafe)
return tr("Set Failsafe");
else if (func == FuncRangeCheckInternalModule)
@@ -102,7 +102,7 @@ QString CustomFunctionData::funcToString(const ModelData * model) const
else if (func == FuncBindExternalModule)
return tr("Bind Ext. Module");
else {
return QString("???"); // Highlight unknown functions with output of question marks.(BTW should not happen that we do not know what a function is)
return QString(CPN_STR_UNKNOWN_ITEM);
}
}
@@ -111,11 +111,16 @@ void CustomFunctionData::populateResetParams(const ModelData * model, QComboBox
int val = 0;
Firmware * firmware = Firmware::getCurrentVariant();
b->addItem(tr("Timer1"), val++);
b->addItem(tr("Timer2"), val++);
b->addItem( tr("Timer3"), val++);
for (int i = 0; i < CPN_MAX_TIMERS; i++, val++) {
if (i < firmware->getCapability(Timers)) {
RawSource item = RawSource(SOURCE_TYPE_SPECIAL, i + SOURCE_TYPE_SPECIAL_TIMER1_IDX);
b->addItem(item.toString(model), val);
}
}
b->addItem(tr("Flight"), val++);
b->addItem(tr("Telemetry"), val++);
int reCount = firmware->getCapability(RotaryEncoders);
if (reCount == 1) {
b->addItem(tr("Rotary Encoder"), val++);
@@ -124,6 +129,7 @@ void CustomFunctionData::populateResetParams(const ModelData * model, QComboBox
b->addItem(tr("REa"), val++);
b->addItem(tr("REb"), val++);
}
if (model) {
for (int i = 0; i < firmware->getCapability(Sensors); ++i) {
if (model->sensorData[i].isAvailable()) {
@@ -132,6 +138,7 @@ void CustomFunctionData::populateResetParams(const ModelData * model, QComboBox
}
}
}
b->setCurrentIndex(b->findData(value));
}
@@ -153,18 +160,18 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
return QString("%1").arg(param);
}
else if (func == FuncLogs) {
return QString("%1").arg(param/10.0) + tr("s");
return QString("%1").arg(param / 10.0) + tr("s");
}
else if (func == FuncPlaySound) {
CustomFunctionData::populatePlaySoundParams(qs);
if (param>=0 && param<(int)qs.count())
if (param >= 0 && param < (int)qs.count())
return qs.at(param);
else
return tr("<font color=red><b>Inconsistent parameter</b></font>");
}
else if (func == FuncPlayHaptic) {
CustomFunctionData::populateHapticParams(qs);
if (param>=0 && param<(int)qs.count())
if (param >= 0 && param < (int)qs.count())
return qs.at(param);
else
return tr("<font color=red><b>Inconsistent parameter</b></font>");
@@ -193,7 +200,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
else if (func >= FuncAdjustGV1 && func < FuncCount) {
switch (adjustMode) {
case FUNC_ADJUST_GVAR_CONSTANT:
return tr("Value ")+QString("%1").arg(param);
return tr("Value ") + QString("%1").arg(param);
case FUNC_ADJUST_GVAR_SOURCE:
case FUNC_ADJUST_GVAR_GVAR:
return RawSource(param).toString();
@@ -218,16 +225,16 @@ QString CustomFunctionData::repeatToString() const
}
else {
unsigned int step = 1;
return tr("repeat(%1s)").arg(step*repeatParam);
return tr("repeat(%1s)").arg(step * repeatParam);
}
}
QString CustomFunctionData::enabledToString() const
{
if ((func >= FuncOverrideCH1 && func <= FuncOverrideCH32) ||
if ((func >= FuncOverrideCH1 && func <= FuncOverrideCHLast) ||
(func >= FuncAdjustGV1 && func <= FuncAdjustGVLast) ||
(func == FuncReset) ||
(func >= FuncSetTimer1 && func <= FuncSetTimer2) ||
(func >= FuncSetTimer1 && func <= FuncSetTimerLast) ||
(func == FuncVolume) ||
(func == FuncBacklight) ||
(func <= FuncInstantTrim)) {
@@ -238,6 +245,64 @@ QString CustomFunctionData::enabledToString() const
return "";
}
// static
bool CustomFunctionData::isFuncAvailable(int index)
{
Firmware * fw = getCurrentFirmware();
bool ret = (((index >= FuncOverrideCH1 && index <= FuncOverrideCHLast) && !fw->getCapability(SafetyChannelCustomFunction)) ||
((index == FuncVolume || index == FuncBackgroundMusic || index == FuncBackgroundMusicPause) && !fw->getCapability(HasVolume)) ||
((index == FuncPlayScript && !IS_HORUS_OR_TARANIS(fw->getBoard()))) ||
((index == FuncPlayHaptic) && !fw->getCapability(Haptic)) ||
((index == FuncPlayBoth) && !fw->getCapability(HasBeeper)) ||
((index == FuncLogs) && !fw->getCapability(HasSDLogs)) ||
((index >= FuncSetTimer1 && index <= FuncSetTimerLast) && index > FuncSetTimer1 + fw->getCapability(Timers)) ||
((index == FuncScreenshot) && !IS_HORUS_OR_TARANIS(fw->getBoard())) ||
((index >= FuncRangeCheckInternalModule && index <= FuncBindExternalModule) && !fw->getCapability(DangerousFunctions)) ||
((index >= FuncAdjustGV1 && index <= FuncAdjustGVLast) && !fw->getCapability(Gvars))
);
return !ret;
}
// static
int CustomFunctionData::funcContext(int index)
{
int ret = AllFunctionContexts;
if ((index >= FuncOverrideCH1 && index <= FuncOverrideCHLast) ||
(index >= FuncRangeCheckInternalModule && index <= FuncBindExternalModule) ||
(index >= FuncAdjustGV1 && index <= FuncAdjustGVLast))
ret &= ~GlobalFunctionsContext;
return ret;
}
// static
int CustomFunctionData::resetParamCount(const ModelData * model)
{
QComboBox cb;
CustomFunctionData::populateResetParams(model, &cb);
return cb.count();
}
// static
bool CustomFunctionData::isResetParamAvailable(const ModelData * model, int index)
{
Firmware * firmware = getCurrentFirmware();
if (index < CPN_MAX_TIMERS) {
if (index < firmware->getCapability(Timers))
return true;
else
return false;
}
else if (index < CPN_MAX_TIMERS + firmware->getCapability(RotaryEncoders))
return true;
else if (model && index < CPN_MAX_TIMERS + firmware->getCapability(RotaryEncoders) + firmware->getCapability(Sensors))
return model->sensorData[index - CPN_MAX_TIMERS - firmware->getCapability(RotaryEncoders)].isAvailable();
return false;
}
void CustomFunctionData::convert(RadioDataConversionState & cstate)
{
cstate.setComponent(tr("CFN"), 8);
+20 -6
View File
@@ -35,7 +35,8 @@ class RadioDataConversionState;
enum AssignFunc {
FuncOverrideCH1 = 0,
FuncOverrideCH32 = FuncOverrideCH1+CPN_MAX_CHNOUT-1,
FuncOverrideCHLast = FuncOverrideCH1 + CPN_MAX_CHNOUT - 1,
FuncOverrideCH32 = FuncOverrideCHLast, // TODO remove
FuncTrainer,
FuncTrainerRUD,
FuncTrainerELE,
@@ -47,8 +48,9 @@ enum AssignFunc {
FuncPlayHaptic,
FuncReset,
FuncSetTimer1,
FuncSetTimer2,
FuncSetTimer3,
FuncSetTimer2, // TODO remove
FuncSetTimer3, // TODO remove
FuncSetTimerLast = FuncSetTimer1 + CPN_MAX_TIMERS - 1,
FuncVario,
FuncPlayPrompt,
FuncPlayBoth,
@@ -61,7 +63,7 @@ enum AssignFunc {
FuncBackgroundMusic,
FuncBackgroundMusicPause,
FuncAdjustGV1,
FuncAdjustGVLast = FuncAdjustGV1+CPN_MAX_GVARS-1,
FuncAdjustGVLast = FuncAdjustGV1 + CPN_MAX_GVARS - 1,
FuncSetFailsafe,
FuncRangeCheckInternalModule,
FuncRangeCheckExternalModule,
@@ -83,7 +85,15 @@ class CustomFunctionData {
Q_DECLARE_TR_FUNCTIONS(CustomFunctionData)
public:
CustomFunctionData(AssignFunc func=FuncOverrideCH1) { clear(); this->func = func; }
enum CustomFunctionContext
{
GlobalFunctionsContext = 0x01,
SpecialFunctionsContext = 0x02,
AllFunctionContexts = GlobalFunctionsContext | SpecialFunctionsContext
};
CustomFunctionData(AssignFunc func = FuncOverrideCH1) { clear(); this->func = func; }
RawSwitch swtch;
AssignFunc func;
int param;
@@ -95,7 +105,7 @@ class CustomFunctionData {
void clear();
bool isEmpty() const;
QString nameToString(int index, bool globalContext = false) const;
QString funcToString(const ModelData * model = NULL) const;
QString funcToString(const ModelData * model = nullptr) const;
QString paramToString(const ModelData * model) const;
QString repeatToString() const;
QString enabledToString() const;
@@ -103,6 +113,10 @@ class CustomFunctionData {
static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value);
static void populatePlaySoundParams(QStringList & qs);
static void populateHapticParams(QStringList & qs);
static bool isFuncAvailable(int index);
static int funcContext(int index);
static int resetParamCount(const ModelData * model);
static bool isResetParamAvailable(const ModelData * model, int index);
void convert(RadioDataConversionState & cstate);
+39
View File
@@ -1439,3 +1439,42 @@ void ModelData::updateResetParam(CustomFunctionData * cfd)
updRefInfo.updcnt++;
}
}
QString ModelData::thrTraceSrcToString() const
{
return thrTraceSrcToString((int)thrTraceSrc);
}
QString ModelData::thrTraceSrcToString(const int index) const
{
Firmware * firmware = getCurrentFirmware();
const Boards board = Boards(getCurrentBoard());
const int pscnt = board.getCapability(Board::Pots) + board.getCapability(Board::Sliders);
if (index == 0)
return tr("THR");
else if (index <= pscnt)
return board.getAnalogInputName(index + board.getCapability(Board::Sticks) - 1);
else if (index <= pscnt + firmware->getCapability(Outputs))
return RawSource(SOURCE_TYPE_CH, index - pscnt - 1).toString(this);
return QString(CPN_STR_UNKNOWN_ITEM);
}
int ModelData::thrTraceSrcCount() const
{
const Boards board = Boards(getCurrentBoard());
Firmware * firmware = getCurrentFirmware();
return 1 + board.getCapability(Board::Pots) + board.getCapability(Board::Sliders) + firmware->getCapability(Outputs);
}
bool ModelData::isThrTraceSrcAvailable(const GeneralSettings * generalSettings, const int index) const
{
const Boards board = Boards(getCurrentBoard());
if (index > 0 && index <= board.getCapability(Board::Pots) + board.getCapability(Board::Sliders))
return RawSource(SOURCE_TYPE_STICK, index + board.getCapability(Board::Sticks) - 1).isAvailable(this, generalSettings, board.getBoardType());
else
return true;
}
+4
View File
@@ -283,6 +283,10 @@ class ModelData {
bool hasExpoChildren(const int index);
bool hasExpoSiblings(const int index);
void removeMix(const int idx);
QString thrTraceSrcToString() const;
QString thrTraceSrcToString(const int index) const;
int thrTraceSrcCount() const;
bool isThrTraceSrcAvailable(const GeneralSettings * generalSettings, const int index) const;
protected:
void removeGlobalVar(int & var);
+14 -18
View File
@@ -143,14 +143,14 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
static const QString rotary[] = { tr("REa"), tr("REb") };
if (index<0) {
return tr("???");
return QString(CPN_STR_UNKNOWN_ITEM);
}
QString result;
int genAryIdx = 0;
switch (type) {
case SOURCE_TYPE_NONE:
return tr("----");
return QString(CPN_STR_NONE_ITEM);
case SOURCE_TYPE_VIRTUAL_INPUT:
{
@@ -161,7 +161,7 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
}
case SOURCE_TYPE_LUA_OUTPUT:
return tr("LUA%1%2").arg(index/16+1).arg(QChar('a'+index%16));
return tr("LUA%1%2").arg(index / 16 + 1).arg(QChar('a' + index % 16));
case SOURCE_TYPE_STICK:
if (generalSettings) {
@@ -193,10 +193,10 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
return result;
case SOURCE_TYPE_CUSTOM_SWITCH:
return RawSwitch(SWITCH_TYPE_VIRTUAL, index+1).toString();
return RawSwitch(SWITCH_TYPE_VIRTUAL, index + 1).toString();
case SOURCE_TYPE_CYC:
return tr("CYC%1").arg(index+1);
return tr("CYC%1").arg(index + 1);
case SOURCE_TYPE_PPM:
return RadioData::getElementName(tr("TR", "as in Trainer"), index + 1);
@@ -208,18 +208,15 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
return LimitData().nameToString(index);
case SOURCE_TYPE_SPECIAL:
result = CHECK_IN_ARRAY(special, index);
// TODO refactor timers into own source type
if (result.startsWith("Timer")) {
bool ok;
int n = result.right(1).toInt(&ok);
if (ok) {
if (model)
result = model->timers[n - 1].nameToString(n - 1);
else
result = TimerData().nameToString(n - 1);
}
if (index >= SOURCE_TYPE_SPECIAL_TIMER1_IDX && index <= SOURCE_TYPE_SPECIAL_TIMER1_IDX + CPN_MAX_TIMERS - 1) {
if (model)
result = model->timers[index - SOURCE_TYPE_SPECIAL_TIMER1_IDX].nameToString(index - SOURCE_TYPE_SPECIAL_TIMER1_IDX);
else
result = TimerData().nameToString(index - SOURCE_TYPE_SPECIAL_TIMER1_IDX);
}
else
result = CHECK_IN_ARRAY(special, index);
return result;
case SOURCE_TYPE_TELEMETRY:
@@ -241,7 +238,7 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
return GVarData().nameToString(index);
default:
return tr("???");
return QString(CPN_STR_UNKNOWN_ITEM);
}
}
@@ -409,4 +406,3 @@ QStringList RawSource::getSwitchList(Boards board) const
}
return ret;
}
+3
View File
@@ -178,6 +178,9 @@ enum RawSourceType {
MAX_SOURCE_TYPE
};
constexpr int SOURCE_TYPE_STICK_THR_IDX { 3 }; // TODO is there a function to determine index?
constexpr int SOURCE_TYPE_SPECIAL_TIMER1_IDX { 2 }; // TODO temp const until Timers own source type
class RawSourceRange
{
Q_DECLARE_TR_FUNCTIONS(RawSourceRange)
+176 -2
View File
@@ -22,6 +22,8 @@
#include "radiodata.h"
#include "modeldata.h"
#include "eeprominterface.h"
#include "compounditemmodels.h"
void SensorData::updateUnit()
{
@@ -31,9 +33,18 @@ void SensorData::updateUnit()
}
}
// TODO depreciated
QString SensorData::unitString() const
{
switch (unit) {
return unitToString(unit);
}
// static
QString SensorData::unitToString(const int value)
{
switch (value) {
case UNIT_RAW:
return tr("Raw (-)");
case UNIT_VOLTS:
return tr("V");
case UNIT_AMPS:
@@ -91,7 +102,7 @@ QString SensorData::unitString() const
case UNIT_US:
return tr("uS");
default:
return "";
return CPN_STR_UNKNOWN_ITEM;
}
}
@@ -118,3 +129,166 @@ bool SensorData::isEmpty() const
{
return (!isAvailable() && type == 0 && id == 0 && subid == 0 && instance == 0 && rxIdx == 0 && moduleIdx == 0 && unit == 0 && ratio == 0 && prec == 0 && offset == 0 && autoOffset == 0 && filter == 0 && onlyPositive == 0 && logs == 0);
}
// static
QString SensorData::typeToString(const int value)
{
switch(value) {
case TELEM_TYPE_CUSTOM:
return tr("Custom");
case TELEM_TYPE_CALCULATED:
return tr("Calculated");
default:
return CPN_STR_UNKNOWN_ITEM;
}
}
// static
QString SensorData::formulaToString(const int value)
{
switch(value) {
case TELEM_FORMULA_ADD:
return tr("Add");
case TELEM_FORMULA_AVERAGE:
return tr("Average");
case TELEM_FORMULA_MIN:
return tr("Minimum");
case TELEM_FORMULA_MAX:
return tr("Maximum");
case TELEM_FORMULA_MULTIPLY:
return tr("Multiply");
case TELEM_FORMULA_TOTALIZE:
return tr("Totalize");
case TELEM_FORMULA_CELL:
return tr("Cell");
case TELEM_FORMULA_CONSUMPTION:
return tr("Consumption");
case TELEM_FORMULA_DIST:
return tr("Distance");
default:
return CPN_STR_UNKNOWN_ITEM;
}
}
// static
QString SensorData::cellIndexToString(const int value)
{
if (value == TELEM_CELL_INDEX_LOWEST)
return tr("Lowest");
if (value > TELEM_CELL_INDEX_LOWEST && value < TELEM_CELL_INDEX_HIGHEST)
return tr("Cell %1").arg(value - TELEM_CELL_INDEX_LOWEST);
if (value== TELEM_CELL_INDEX_HIGHEST)
return tr("Highest");
if (value == TELEM_CELL_INDEX_DELTA)
return tr("Delta");
return CPN_STR_UNKNOWN_ITEM;
}
// static
QString SensorData::precisionToString(const int value)
{
return QString("0.%1").arg(QString(value, '0'));
}
// static
QString SensorData::sourceToString(const ModelData * model, const int index, const bool sign)
{
if (model) {
const QString prfx = sign ? index < 0 ? "-" : "+" : "";
if (abs(index) > 0) {
const SensorData &sd = model->sensorData[abs(index) - 1];
if (sd.type == SensorData::TELEM_TYPE_CUSTOM)
return QString("%1%2 (%3)").arg(prfx).arg(sd.label).arg(sd.getOrigin(model));
else
return QString("%1%2").arg(prfx).arg(sd.label);
}
else
return CPN_STR_NONE_ITEM;
}
return "";
}
// static
bool SensorData::isSourceAvailable(const ModelData * model, const int index)
{
Firmware * firmware = getCurrentFirmware();
const int sensorcnt = firmware->getCapability(Sensors);
const int i = abs(index);
if (model && sensorcnt > 0 and i <= sensorcnt) {
if (i > 0)
return model->sensorData[i - 1].isAvailable();
else
return true;
}
return false;
}
// static
AbstractStaticItemModel * SensorData::typeItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("sensordata.type");
for (int i = 0; i <= TELEM_TYPE_LAST; i++) {
mdl->appendToItemList(typeToString(i), i);
}
mdl->loadItemList();
return mdl;
}
// static
AbstractStaticItemModel * SensorData::formulaItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("sensordata.formula");
for (int i = 0; i <= TELEM_FORMULA_LAST; i++) {
mdl->appendToItemList(formulaToString(i), i);
}
mdl->loadItemList();
return mdl;
}
// static
AbstractStaticItemModel * SensorData::cellIndexItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("sensordata.cellindex");
for (int i = 0; i <= TELEM_CELL_INDEX_LAST; i++) {
mdl->appendToItemList(cellIndexToString(i), i);
}
mdl->loadItemList();
return mdl;
}
// static
AbstractStaticItemModel * SensorData::unitItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("sensordata.unit");
for (int i = 0; i <= UNIT_MAX; i++) {
QString str = unitToString(i);
if (str != CPN_STR_UNKNOWN_ITEM)
mdl->appendToItemList(str, i);
}
mdl->loadItemList();
return mdl;
}
// static
PrecisionItemModel * SensorData::precisionItemModel()
{
PrecisionItemModel * mdl = new PrecisionItemModel(0, 2);
mdl->setName("sensordata.precision");
return mdl;
}
+19 -1
View File
@@ -27,6 +27,8 @@ constexpr int CPN_MAX_SENSORS = 60;
constexpr int SENSOR_LABEL_LEN = 4;
class ModelData;
class AbstractStaticItemModel;
class PrecisionItemModel;
class SensorData {
Q_DECLARE_TR_FUNCTIONS(SensorData)
@@ -36,7 +38,8 @@ class SensorData {
enum
{
TELEM_TYPE_CUSTOM,
TELEM_TYPE_CALCULATED
TELEM_TYPE_CALCULATED,
TELEM_TYPE_LAST = TELEM_TYPE_CALCULATED
};
enum
@@ -63,6 +66,7 @@ class SensorData {
TELEM_CELL_INDEX_6,
TELEM_CELL_INDEX_HIGHEST,
TELEM_CELL_INDEX_DELTA,
TELEM_CELL_INDEX_LAST = TELEM_CELL_INDEX_DELTA
};
enum
@@ -168,6 +172,20 @@ class SensorData {
QString getOrigin(const ModelData* model) const;
void clear() { memset(this, 0, sizeof(SensorData)); }
bool isEmpty() const;
static QString sourceToString(const ModelData * model, const int index, const bool sign = false);
static bool isSourceAvailable(const ModelData * model, const int index);
static QString typeToString(const int value);
static QString formulaToString(const int value);
static QString cellIndexToString(const int value);
static QString unitToString(const int value);
static QString precisionToString(const int value);
static AbstractStaticItemModel * typeItemModel();
static AbstractStaticItemModel * formulaItemModel();
static AbstractStaticItemModel * cellIndexItemModel();
static AbstractStaticItemModel * unitItemModel();
static PrecisionItemModel * precisionItemModel();
};
#endif // SENSORDATA_H