Merge pull request #8336 from opentx/elecpower/cpn-custfunc-data-mdls
Add data models to global and special functions to improve look up refresh in Companion
This commit is contained in:
@@ -22,6 +22,17 @@
|
||||
#include "eeprominterface.h"
|
||||
#include "radiodata.h"
|
||||
#include "radiodataconversionstate.h"
|
||||
#include "compounditemmodels.h"
|
||||
|
||||
void CustomFunctionData::convert(RadioDataConversionState & cstate)
|
||||
{
|
||||
cstate.setComponent(tr("CFN"), 8);
|
||||
cstate.setSubComp(nameToString(cstate.subCompIdx, (cstate.toModel() ? false : true)));
|
||||
swtch.convert(cstate);
|
||||
if (func == FuncVolume || func == FuncBacklight || func == FuncPlayValue || (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast && adjustMode == 1)) {
|
||||
param = RawSource(param).convert(cstate.withComponentField("PARAM")).toValue();
|
||||
}
|
||||
}
|
||||
|
||||
void CustomFunctionData::clear()
|
||||
{
|
||||
@@ -36,12 +47,19 @@ bool CustomFunctionData::isEmpty() const
|
||||
return (swtch.type == SWITCH_TYPE_NONE);
|
||||
}
|
||||
|
||||
QString CustomFunctionData::nameToString(int index, bool globalContext) const
|
||||
// static
|
||||
QString CustomFunctionData::nameToString(const int index, const bool globalContext)
|
||||
{
|
||||
return RadioData::getElementName((globalContext ? tr("GF") : tr("SF")), index + 1, 0, true);
|
||||
}
|
||||
|
||||
QString CustomFunctionData::funcToString(const ModelData * model) const
|
||||
{
|
||||
return funcToString(func, model);
|
||||
}
|
||||
|
||||
// static
|
||||
QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData * model)
|
||||
{
|
||||
if (func >= FuncOverrideCH1 && func <= FuncOverrideCHLast)
|
||||
return tr("Override %1").arg(RawSource(SOURCE_TYPE_CH, func).toString(model));
|
||||
@@ -76,7 +94,7 @@ QString CustomFunctionData::funcToString(const ModelData * model) const
|
||||
else if (func == FuncPlayValue)
|
||||
return tr("Play Value");
|
||||
else if (func == FuncPlayScript)
|
||||
return tr("Play Script");
|
||||
return tr("Lua Script");
|
||||
else if (func == FuncLogs)
|
||||
return tr("SD Logs");
|
||||
else if (func == FuncVolume)
|
||||
@@ -94,9 +112,9 @@ QString CustomFunctionData::funcToString(const ModelData * model) const
|
||||
else if (func == FuncSetFailsafe)
|
||||
return tr("Set Failsafe");
|
||||
else if (func == FuncRangeCheckInternalModule)
|
||||
return tr("RangeCheck Int. Module");
|
||||
return tr("Range Check Int. Module");
|
||||
else if (func == FuncRangeCheckExternalModule)
|
||||
return tr("RangeCheck Ext. Module");
|
||||
return tr("Range Check Ext. Module");
|
||||
else if (func == FuncBindInternalModule)
|
||||
return tr("Bind Int. Module");
|
||||
else if (func == FuncBindExternalModule)
|
||||
@@ -106,53 +124,6 @@ QString CustomFunctionData::funcToString(const ModelData * model) const
|
||||
}
|
||||
}
|
||||
|
||||
void CustomFunctionData::populateResetParams(const ModelData * model, QComboBox * b, unsigned int value = 0)
|
||||
{
|
||||
int val = 0;
|
||||
Firmware * firmware = Firmware::getCurrentVariant();
|
||||
|
||||
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++);
|
||||
}
|
||||
else if (reCount == 2) {
|
||||
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()) {
|
||||
RawSource item = RawSource(SOURCE_TYPE_TELEMETRY, 3 * i);
|
||||
b->addItem(item.toString(model), val + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b->setCurrentIndex(b->findData(value));
|
||||
}
|
||||
|
||||
void CustomFunctionData::populatePlaySoundParams(QStringList & qs)
|
||||
{
|
||||
qs <<"Beep 1" << "Beep 2" << "Beep 3" << "Warn1" << "Warn2" << "Cheep" << "Ratata" << "Tick" << "Siren" << "Ring" ;
|
||||
qs << "SciFi" << "Robot" << "Chirp" << "Tada" << "Crickt" << "AlmClk" ;
|
||||
}
|
||||
|
||||
void CustomFunctionData::populateHapticParams(QStringList & qs)
|
||||
{
|
||||
qs << "0" << "1" << "2" << "3";
|
||||
}
|
||||
|
||||
QString CustomFunctionData::paramToString(const ModelData * model) const
|
||||
{
|
||||
QStringList qs;
|
||||
@@ -163,31 +134,16 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
|
||||
return QString("%1").arg(param / 10.0) + tr("s");
|
||||
}
|
||||
else if (func == FuncPlaySound) {
|
||||
CustomFunctionData::populatePlaySoundParams(qs);
|
||||
if (param >= 0 && param < (int)qs.count())
|
||||
return qs.at(param);
|
||||
else
|
||||
return tr("<font color=red><b>Inconsistent parameter</b></font>");
|
||||
return playSoundToString(param);
|
||||
}
|
||||
else if (func == FuncPlayHaptic) {
|
||||
CustomFunctionData::populateHapticParams(qs);
|
||||
if (param >= 0 && param < (int)qs.count())
|
||||
return qs.at(param);
|
||||
else
|
||||
return tr("<font color=red><b>Inconsistent parameter</b></font>");
|
||||
return harpicToString(param);
|
||||
}
|
||||
else if (func == FuncReset) {
|
||||
QComboBox cb;
|
||||
CustomFunctionData::populateResetParams(model, &cb);
|
||||
int pos = cb.findData(param);
|
||||
if (pos >= 0)
|
||||
return cb.itemText(pos);
|
||||
else
|
||||
return tr("<font color=red><b>Inconsistent parameter</b></font>");
|
||||
return resetToString(param, model);
|
||||
}
|
||||
else if (func == FuncVolume || func == FuncPlayValue || func == FuncBacklight) {
|
||||
RawSource item(param);
|
||||
return item.toString(model);
|
||||
return RawSource(param).toString(model);
|
||||
}
|
||||
else if (func == FuncPlayPrompt || func == FuncPlayBoth) {
|
||||
if ( getCurrentFirmware()->getCapability(VoicesAsNumbers)) {
|
||||
@@ -200,16 +156,14 @@ 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 gvarAdjustModeToString(adjustMode) + QString(" %1").arg(param);
|
||||
case FUNC_ADJUST_GVAR_SOURCE:
|
||||
case FUNC_ADJUST_GVAR_GVAR:
|
||||
return RawSource(param).toString();
|
||||
case FUNC_ADJUST_GVAR_INCDEC:
|
||||
float val;
|
||||
QString unit;
|
||||
val = param * model->gvarData[func - FuncAdjustGV1].multiplierGet();
|
||||
unit = model->gvarData[func - FuncAdjustGV1].unitToString();
|
||||
return QString("Increment: %1%2").arg(val).arg(unit);
|
||||
const float val = param * model->gvarData[func - FuncAdjustGV1].multiplierGet();
|
||||
const QString unit = model->gvarData[func - FuncAdjustGV1].unitToString();
|
||||
return gvarAdjustModeToString(adjustMode) + QString(": %1%2").arg(val).arg(unit);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
@@ -217,15 +171,20 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
|
||||
|
||||
QString CustomFunctionData::repeatToString() const
|
||||
{
|
||||
if (repeatParam == -1) {
|
||||
return tr("played once, not during startup");
|
||||
return repeatToString(repeatParam);
|
||||
}
|
||||
|
||||
// static
|
||||
QString CustomFunctionData::repeatToString(const int value)
|
||||
{
|
||||
if (value == -1) {
|
||||
return tr("Played once, not during startup");
|
||||
}
|
||||
else if (repeatParam == 0) {
|
||||
return "";
|
||||
else if (value == 0) {
|
||||
return tr("No repeat");
|
||||
}
|
||||
else {
|
||||
unsigned int step = 1;
|
||||
return tr("repeat(%1s)").arg(step * repeatParam);
|
||||
return tr("Repeat %1s").arg(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +205,7 @@ QString CustomFunctionData::enabledToString() const
|
||||
}
|
||||
|
||||
// static
|
||||
bool CustomFunctionData::isFuncAvailable(int index)
|
||||
bool CustomFunctionData::isFuncAvailable(const int index)
|
||||
{
|
||||
Firmware * fw = getCurrentFirmware();
|
||||
|
||||
@@ -265,7 +224,7 @@ bool CustomFunctionData::isFuncAvailable(int index)
|
||||
}
|
||||
|
||||
// static
|
||||
int CustomFunctionData::funcContext(int index)
|
||||
int CustomFunctionData::funcContext(const int index)
|
||||
{
|
||||
int ret = AllFunctionContexts;
|
||||
|
||||
@@ -276,16 +235,42 @@ int CustomFunctionData::funcContext(int index)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// static
|
||||
int CustomFunctionData::resetParamCount(const ModelData * model)
|
||||
QString CustomFunctionData::resetToString(const int value, const ModelData * model)
|
||||
{
|
||||
QComboBox cb;
|
||||
CustomFunctionData::populateResetParams(model, &cb);
|
||||
return cb.count();
|
||||
Firmware * firmware = getCurrentFirmware();
|
||||
int step = CPN_MAX_TIMERS;
|
||||
|
||||
if (value < step) {
|
||||
if (value < firmware->getCapability(Timers))
|
||||
return RawSource(SOURCE_TYPE_SPECIAL, value + SOURCE_TYPE_SPECIAL_TIMER1_IDX).toString(model);
|
||||
else
|
||||
return QString(CPN_STR_UNKNOWN_ITEM);
|
||||
}
|
||||
|
||||
if (value < ++step)
|
||||
return tr("Flight");
|
||||
|
||||
if (value < ++step)
|
||||
return tr("Telemetry");
|
||||
|
||||
if (value < step + firmware->getCapability(Sensors))
|
||||
return RawSource(SOURCE_TYPE_TELEMETRY, 3 * (value - step)).toString(model);
|
||||
|
||||
return QString(CPN_STR_UNKNOWN_ITEM);
|
||||
}
|
||||
|
||||
// static
|
||||
bool CustomFunctionData::isResetParamAvailable(const ModelData * model, int index)
|
||||
int CustomFunctionData::resetParamCount()
|
||||
{
|
||||
Firmware * firmware = getCurrentFirmware();
|
||||
|
||||
return CPN_MAX_TIMERS + 2 + firmware->getCapability(Sensors);
|
||||
}
|
||||
|
||||
// static
|
||||
bool CustomFunctionData::isResetParamAvailable(const int index, const ModelData * model)
|
||||
{
|
||||
Firmware * firmware = getCurrentFirmware();
|
||||
|
||||
@@ -295,20 +280,121 @@ bool CustomFunctionData::isResetParamAvailable(const ModelData * model, int inde
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (index < CPN_MAX_TIMERS + firmware->getCapability(RotaryEncoders))
|
||||
else if (index < CPN_MAX_TIMERS + 2)
|
||||
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();
|
||||
else if (model && index < resetParamCount())
|
||||
return model->sensorData[index - (CPN_MAX_TIMERS + 2)].isAvailable();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CustomFunctionData::convert(RadioDataConversionState & cstate)
|
||||
QString CustomFunctionData::harpicToString() const
|
||||
{
|
||||
cstate.setComponent(tr("CFN"), 8);
|
||||
cstate.setSubComp(nameToString(cstate.subCompIdx, (cstate.toModel() ? false : true)));
|
||||
swtch.convert(cstate);
|
||||
if (func == FuncVolume || func == FuncBacklight || func == FuncPlayValue || (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast && adjustMode == 1)) {
|
||||
param = RawSource(param).convert(cstate.withComponentField("PARAM")).toValue();
|
||||
return harpicToString(param);
|
||||
}
|
||||
|
||||
// static
|
||||
QString CustomFunctionData::harpicToString(const int value)
|
||||
{
|
||||
return QString("%1").arg(value);
|
||||
}
|
||||
|
||||
// static
|
||||
QStringList CustomFunctionData::playSoundStringList()
|
||||
{
|
||||
return QStringList({ tr("Beep 1"), tr("Beep 2"), tr("Beep 3"), tr("Warn 1"), tr("Warn 2"), tr("Cheep"), tr("Ratata"), tr("Tick"),
|
||||
tr("Siren"), tr("Ring"), tr("Sci Fi"), tr("Robot"), tr("Chirp"), tr("Tada"), tr("Cricket"), tr("Alarm Clock") });
|
||||
}
|
||||
|
||||
QString CustomFunctionData::playSoundToString() const
|
||||
{
|
||||
return playSoundToString(param);
|
||||
}
|
||||
|
||||
// static
|
||||
QString CustomFunctionData::playSoundToString(const int value)
|
||||
{
|
||||
const QStringList strl = playSoundStringList();
|
||||
if (value < strl.count())
|
||||
return strl.at(value);
|
||||
else
|
||||
return QString(CPN_STR_UNKNOWN_ITEM);
|
||||
}
|
||||
|
||||
QString CustomFunctionData::gvarAdjustModeToString() const
|
||||
{
|
||||
return gvarAdjustModeToString(adjustMode);
|
||||
}
|
||||
|
||||
// static
|
||||
QString CustomFunctionData::gvarAdjustModeToString(const int value)
|
||||
{
|
||||
switch (value) {
|
||||
case FUNC_ADJUST_GVAR_CONSTANT:
|
||||
return tr("Value");
|
||||
case FUNC_ADJUST_GVAR_SOURCE:
|
||||
return tr("Source");
|
||||
case FUNC_ADJUST_GVAR_GVAR:
|
||||
return tr("Global Variable");
|
||||
case FUNC_ADJUST_GVAR_INCDEC:
|
||||
return tr("Inc/Decrement");
|
||||
default:
|
||||
return QString(CPN_STR_UNKNOWN_ITEM);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
AbstractStaticItemModel * CustomFunctionData::repeatItemModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName("customfunctiondata.repeat");
|
||||
|
||||
for (int i = -1; i <= 60; i++) {
|
||||
mdl->appendToItemList(repeatToString(i), i);
|
||||
}
|
||||
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
|
||||
// static
|
||||
AbstractStaticItemModel * CustomFunctionData::playSoundItemModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName("customfunctiondata.playsound");
|
||||
|
||||
for (int i = 0; i < playSoundStringList().count(); i++) {
|
||||
mdl->appendToItemList(playSoundToString(i), i);
|
||||
}
|
||||
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
|
||||
// static
|
||||
AbstractStaticItemModel * CustomFunctionData::harpicItemModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName("customfunctiondata.harpic");
|
||||
|
||||
for (int i = 0; i <= 3; i++) {
|
||||
mdl->appendToItemList(harpicToString(i), i);
|
||||
}
|
||||
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
|
||||
// static
|
||||
AbstractStaticItemModel * CustomFunctionData::gvarAdjustModeItemModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName("customfunctiondata.gvaradjustmode");
|
||||
|
||||
for (int i = 0; i < FUNC_ADJUST_GVAR_COUNT; i++) {
|
||||
mdl->appendToItemList(gvarAdjustModeToString(i), i);
|
||||
}
|
||||
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMFUNCTIONDATA_H
|
||||
#define CUSTOMFUNCTIONDATA_H
|
||||
#pragma once
|
||||
|
||||
#include "boards.h"
|
||||
#include "constants.h"
|
||||
@@ -32,6 +31,7 @@ class Firmware;
|
||||
class ModelData;
|
||||
class GeneralSettings;
|
||||
class RadioDataConversionState;
|
||||
class AbstractStaticItemModel;
|
||||
|
||||
enum AssignFunc {
|
||||
FuncOverrideCH1 = 0,
|
||||
@@ -78,7 +78,8 @@ enum GVarAdjustModes
|
||||
FUNC_ADJUST_GVAR_CONSTANT,
|
||||
FUNC_ADJUST_GVAR_SOURCE,
|
||||
FUNC_ADJUST_GVAR_GVAR,
|
||||
FUNC_ADJUST_GVAR_INCDEC
|
||||
FUNC_ADJUST_GVAR_INCDEC,
|
||||
FUNC_ADJUST_GVAR_COUNT
|
||||
};
|
||||
|
||||
class CustomFunctionData {
|
||||
@@ -102,25 +103,33 @@ class CustomFunctionData {
|
||||
unsigned int adjustMode;
|
||||
int repeatParam;
|
||||
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
QString nameToString(int index, bool globalContext = false) const;
|
||||
QString funcToString(const ModelData * model = nullptr) const;
|
||||
QString paramToString(const ModelData * model) const;
|
||||
QString repeatToString() const;
|
||||
QString enabledToString() const;
|
||||
|
||||
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);
|
||||
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
QString funcToString(const ModelData * model = nullptr) const;
|
||||
QString paramToString(const ModelData * model = nullptr) const;
|
||||
QString repeatToString() const;
|
||||
QString enabledToString() const;
|
||||
QString playSoundToString() const;
|
||||
QString harpicToString() const;
|
||||
QString gvarAdjustModeToString() const;
|
||||
|
||||
static QString nameToString(const int index, const bool globalContext = false);
|
||||
static QString funcToString(const AssignFunc func, const ModelData * model = nullptr);
|
||||
static bool isFuncAvailable(const int index);
|
||||
static int funcContext(const int index);
|
||||
static QString resetToString(const int value, const ModelData * model = nullptr);
|
||||
static int resetParamCount();
|
||||
static bool isResetParamAvailable(const int index, const ModelData * model = nullptr);
|
||||
static QString repeatToString(const int value);
|
||||
static QStringList playSoundStringList();
|
||||
static QString playSoundToString(const int value);
|
||||
static QString harpicToString(const int value);
|
||||
static QStringList gvarAdjustModeStringList();
|
||||
static QString gvarAdjustModeToString(const int value);
|
||||
static AbstractStaticItemModel * repeatItemModel();
|
||||
static AbstractStaticItemModel * playSoundItemModel();
|
||||
static AbstractStaticItemModel * harpicItemModel();
|
||||
static AbstractStaticItemModel * gvarAdjustModeItemModel();
|
||||
};
|
||||
|
||||
|
||||
#endif // CUSTOMFUNCTIONDATA_H
|
||||
|
||||
Reference in New Issue
Block a user