[Companion] Adjust source value ranges and editors in LS/CF/Telemetry (#5437)
* [Companion] RawSourceRange: Fix for timers and RTC; Remove unused "single precision" flag and logic; Add logic for "short" timer handling. * [Companion] Add TimerEdit class for editing negative times; Implement TimerEdit in LS, CF, and Telemetry (bars) editors; * [Companion] Refactor LogicalSwitchesPanel for fewer & more efficient updates; Fix newly-added LS not being available in source lists; Fix bug with timer/rtc comparison values getting reset to value of spin box instead of time editor. * Add forgotten #include. * [Companion] LogicalSwitchesPanel: Update raw sources list upon screen refresh (fixes #5374); Improve data entry in spin boxes (fixes #5375). * Make gcc happy. * [Companion] Set proper RawSourceRange for GVars, trims, mixer scripts, and sticks/switches/cyclic/MAX. * [Companion] Fix backwards precision/range logic on telemetry sensors offset spinbox; Fix other minor range issues with ratio & offset. * [Companion] Remove short limit on min/max timer values for LS & telem. bars. * Switch to TimerEdit in maxLibQt. * Fix gcc build. * Remove unused files. * Caps fix.
This commit is contained in:
committed by
Bertrand Songis
parent
b69f36afe4
commit
76ce186bd4
@@ -23,6 +23,8 @@
|
||||
#include "helpers.h"
|
||||
#include "appdata.h"
|
||||
|
||||
#include <TimerEdit>
|
||||
|
||||
RepeatComboBox::RepeatComboBox(QWidget *parent, int & repeatParam):
|
||||
QComboBox(parent),
|
||||
repeatParam(repeatParam)
|
||||
@@ -178,10 +180,8 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
|
||||
connect(fswtchParam[i], SIGNAL(editingFinished()), this, SLOT(customFunctionEdited()));
|
||||
paramLayout->addWidget(fswtchParam[i]);
|
||||
|
||||
fswtchParamTime[i] = new QTimeEdit(this);
|
||||
fswtchParamTime[i] = new TimerEdit(this);
|
||||
fswtchParamTime[i]->setProperty("index", i);
|
||||
fswtchParamTime[i]->setAccelerated(true);
|
||||
fswtchParamTime[i]->setDisplayFormat("hh:mm:ss");
|
||||
connect(fswtchParamTime[i], SIGNAL(editingFinished()), this, SLOT(customFunctionEdited()));
|
||||
paramLayout->addWidget(fswtchParamTime[i]);
|
||||
|
||||
@@ -450,10 +450,10 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
}
|
||||
else if (func>=FuncSetTimer1 && func<=FuncSetTimer3) {
|
||||
if (modified)
|
||||
cfn.param = QTimeS(fswtchParamTime[i]->time()).seconds();
|
||||
fswtchParamTime[i]->setMinimumTime(QTime(0, 0, 0));
|
||||
fswtchParamTime[i]->setMaximumTime(firmware->getMaxTimerStart());
|
||||
fswtchParamTime[i]->setTime(QTimeS(cfn.param));
|
||||
cfn.param = fswtchParamTime[i]->timeInSeconds();
|
||||
RawSourceRange range = RawSource(SOURCE_TYPE_SPECIAL, func - FuncSetTimer1 + 2).getRange(model, generalSettings);
|
||||
fswtchParamTime[i]->setTimeRange((int)range.min, (int)range.max);
|
||||
fswtchParamTime[i]->setTime(cfn.param);
|
||||
widgetsMask |= CUSTOM_FUNCTION_TIME_PARAM | CUSTOM_FUNCTION_ENABLE;
|
||||
}
|
||||
else if (func>=FuncSetFailsafeInternalModule && func<=FuncBindExternalModule) {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "eeprominterface.h"
|
||||
|
||||
class RawSwitchFilterItemModel;
|
||||
class TimerEdit;
|
||||
|
||||
class RepeatComboBox: public QComboBox
|
||||
{
|
||||
@@ -87,7 +88,7 @@ class CustomFunctionsPanel : public GenericPanel
|
||||
QComboBox * fswtchFunc[CPN_MAX_SPECIAL_FUNCTIONS];
|
||||
QCheckBox * fswtchParamGV[CPN_MAX_SPECIAL_FUNCTIONS];
|
||||
QDoubleSpinBox * fswtchParam[CPN_MAX_SPECIAL_FUNCTIONS];
|
||||
QTimeEdit * fswtchParamTime[CPN_MAX_SPECIAL_FUNCTIONS];
|
||||
TimerEdit * fswtchParamTime[CPN_MAX_SPECIAL_FUNCTIONS];
|
||||
QPushButton * playBT[CPN_MAX_SPECIAL_FUNCTIONS];
|
||||
QComboBox * fswtchParamT[CPN_MAX_SPECIAL_FUNCTIONS];
|
||||
QComboBox * fswtchParamArmT[CPN_MAX_SPECIAL_FUNCTIONS];
|
||||
|
||||
@@ -22,17 +22,19 @@
|
||||
#include "switchitemmodel.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#include <TimerEdit>
|
||||
|
||||
LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
rawSourceItemModel(NULL),
|
||||
selectedSwitch(0)
|
||||
{
|
||||
Stopwatch s1("LogicalSwitchesPanel");
|
||||
|
||||
int channelsMax = model.getChannelsMax(true);
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, LogicalSwitchesContext);
|
||||
int srcFlags = POPULATE_NONE | POPULATE_SOURCES | POPULATE_SCRIPT_OUTPUTS | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | POPULATE_TELEMETRY | (firmware->getCapability(GvarsInCS) ? POPULATE_GVARS : 0);
|
||||
rawSourceItemModel = Helpers::getRawSourceItemModel(&generalSettings, &model, srcFlags);
|
||||
rawSourceItemModel->setParent(this);
|
||||
|
||||
setDataModels();
|
||||
|
||||
QStringList headerLabels;
|
||||
headerLabels << "#" << tr("Function") << tr("V1") << tr("V2") << tr("AND Switch");
|
||||
@@ -58,7 +60,8 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
|
||||
// The function
|
||||
csw[i] = new QComboBox(this);
|
||||
csw[i]->setProperty("index", i);
|
||||
connect(csw[i], SIGNAL(currentIndexChanged(int)), this, SLOT(edited()));
|
||||
populateCSWCB(csw[i]);
|
||||
connect(csw[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionChanged()));
|
||||
tableLayout->addWidget(i, 1, csw[i]);
|
||||
|
||||
// V1
|
||||
@@ -74,7 +77,7 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
|
||||
cswitchValue[i]->setAccelerated(true);
|
||||
cswitchValue[i]->setDecimals(0);
|
||||
cswitchValue[i]->setProperty("index", i);
|
||||
connect(cswitchValue[i], SIGNAL(valueChanged(double)), this, SLOT(edited()));
|
||||
connect(cswitchValue[i], SIGNAL(editingFinished()), this, SLOT(offsetEdited()));
|
||||
v1Layout->addWidget(cswitchValue[i]);
|
||||
cswitchValue[i]->setVisible(false);
|
||||
tableLayout->addLayout(i, 2, v1Layout);
|
||||
@@ -92,7 +95,7 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
|
||||
cswitchOffset[i]->setMinimum(-channelsMax);
|
||||
cswitchOffset[i]->setAccelerated(true);
|
||||
cswitchOffset[i]->setDecimals(0);
|
||||
connect(cswitchOffset[i], SIGNAL(valueChanged(double)), this, SLOT(edited()));
|
||||
connect(cswitchOffset[i], SIGNAL(editingFinished()), this, SLOT(offsetEdited()));
|
||||
cswitchOffset[i]->setVisible(false);
|
||||
v2Layout->addWidget(cswitchOffset[i]);
|
||||
cswitchOffset2[i] = new QDoubleSpinBox(this);
|
||||
@@ -101,13 +104,13 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
|
||||
cswitchOffset2[i]->setMinimum(-channelsMax);
|
||||
cswitchOffset2[i]->setAccelerated(true);
|
||||
cswitchOffset2[i]->setDecimals(0);
|
||||
connect(cswitchOffset2[i], SIGNAL(valueChanged(double)), this, SLOT(edited()));
|
||||
cswitchOffset2[i]->setSpecialValueText(" " + tr("(instant)"));
|
||||
connect(cswitchOffset2[i], SIGNAL(editingFinished()), this, SLOT(offsetEdited()));
|
||||
cswitchOffset2[i]->setVisible(false);
|
||||
v2Layout->addWidget(cswitchOffset2[i]);
|
||||
cswitchTOffset[i] = new QTimeEdit(this);
|
||||
cswitchTOffset[i] = new TimerEdit(this);
|
||||
cswitchTOffset[i]->setProperty("index",i);
|
||||
cswitchTOffset[i]->setAccelerated(true);
|
||||
connect(cswitchTOffset[i],SIGNAL(editingFinished()),this,SLOT(edited()));
|
||||
connect(cswitchTOffset[i],SIGNAL(editingFinished()),this,SLOT(offsetEdited()));
|
||||
v2Layout->addWidget(cswitchTOffset[i]);
|
||||
cswitchTOffset[i]->setVisible(false);
|
||||
tableLayout->addLayout(i, 3, v2Layout);
|
||||
@@ -115,6 +118,7 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
|
||||
// AND
|
||||
cswitchAnd[i] = new QComboBox(this);
|
||||
cswitchAnd[i]->setProperty("index", i);
|
||||
populateAndSwitchCB(cswitchAnd[i]);
|
||||
connect(cswitchAnd[i], SIGNAL(currentIndexChanged(int)), this, SLOT(andEdited(int)));
|
||||
tableLayout->addWidget(i, 4, cswitchAnd[i]);
|
||||
|
||||
@@ -157,18 +161,55 @@ LogicalSwitchesPanel::~LogicalSwitchesPanel()
|
||||
{
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::setDataModels()
|
||||
{
|
||||
if (rawSourceItemModel)
|
||||
rawSourceItemModel->deleteLater();
|
||||
|
||||
int srcFlags = POPULATE_NONE | POPULATE_SOURCES | POPULATE_SCRIPT_OUTPUTS | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | POPULATE_TELEMETRY | (firmware->getCapability(GvarsInCS) ? POPULATE_GVARS : 0);
|
||||
rawSourceItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, srcFlags);
|
||||
rawSourceItemModel->setParent(this);
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::functionChanged()
|
||||
{
|
||||
int i = sender()->property("index").toInt();
|
||||
unsigned newFunc = csw[i]->currentData().toUInt();
|
||||
|
||||
if (model->logicalSw[i].func == newFunc)
|
||||
return;
|
||||
|
||||
CSFunctionFamily oldFuncFamily = model->logicalSw[i].getFunctionFamily();
|
||||
model->logicalSw[i].func = newFunc;
|
||||
CSFunctionFamily newFuncFamily = model->logicalSw[i].getFunctionFamily();
|
||||
|
||||
if (oldFuncFamily != newFuncFamily) {
|
||||
model->logicalSw[i].clear();
|
||||
model->logicalSw[i].func = newFunc;
|
||||
if (newFuncFamily == LS_FAMILY_TIMER) {
|
||||
model->logicalSw[i].val1 = -119;
|
||||
model->logicalSw[i].val2 = -119;
|
||||
}
|
||||
else if (newFuncFamily == LS_FAMILY_EDGE) {
|
||||
model->logicalSw[i].val2 = -129;
|
||||
}
|
||||
}
|
||||
updateLine(i);
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::v1Edited(int value)
|
||||
{
|
||||
if (!lock) {
|
||||
int i = sender()->property("index").toInt();
|
||||
model->logicalSw[i].val1 = cswitchSource1[i]->itemData(value).toInt();
|
||||
if (model->logicalSw[i].getFunctionFamily() == LS_FAMILY_VOFS) {
|
||||
RawSource source = RawSource(model->logicalSw[i].val1);
|
||||
RawSourceRange range = source.getRange(model, generalSettings, model->logicalSw[i].getRangeFlags());
|
||||
model->logicalSw[i].val2 = (cswitchOffset[i]->value() - range.offset) / range.step;
|
||||
setSwitchWidgetVisibility(i);
|
||||
if (!offsetEditedAt(i))
|
||||
updateLine(i);
|
||||
}
|
||||
else {
|
||||
emit modified();
|
||||
}
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,75 +249,65 @@ void LogicalSwitchesPanel::delayEdited(double delay)
|
||||
}
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::edited()
|
||||
void LogicalSwitchesPanel::offsetEdited()
|
||||
{
|
||||
if (!lock) {
|
||||
lock = true;
|
||||
int i = sender()->property("index").toInt();
|
||||
CSFunctionFamily oldFuncFamily = model->logicalSw[i].getFunctionFamily();
|
||||
model->logicalSw[i].func = csw[i]->itemData(csw[i]->currentIndex()).toInt();
|
||||
CSFunctionFamily newFuncFamily = model->logicalSw[i].getFunctionFamily();
|
||||
offsetEditedAt(sender()->property("index").toInt());
|
||||
}
|
||||
|
||||
if (oldFuncFamily != newFuncFamily) {
|
||||
model->logicalSw[i].clear();
|
||||
model->logicalSw[i].func = csw[i]->currentData().toInt();
|
||||
if (newFuncFamily == LS_FAMILY_TIMER) {
|
||||
model->logicalSw[i].val1 = -119;
|
||||
model->logicalSw[i].val2 = -119;
|
||||
}
|
||||
else if (newFuncFamily == LS_FAMILY_EDGE) {
|
||||
model->logicalSw[i].val2 = -129;
|
||||
}
|
||||
setSwitchWidgetVisibility(i);
|
||||
}
|
||||
bool LogicalSwitchesPanel::offsetEditedAt(int index)
|
||||
{
|
||||
if (lock)
|
||||
return false;
|
||||
|
||||
RawSource source;
|
||||
lock = true;
|
||||
bool mod = false;
|
||||
int value;
|
||||
|
||||
switch (newFuncFamily)
|
||||
switch (model->logicalSw[index].getFunctionFamily())
|
||||
{
|
||||
case LS_FAMILY_VOFS:
|
||||
{
|
||||
case LS_FAMILY_VOFS:
|
||||
{
|
||||
source = RawSource(model->logicalSw[i].val1);
|
||||
RawSourceRange range = source.getRange(model, generalSettings, model->logicalSw[i].getRangeFlags());
|
||||
double value = source.isTimeBased() ? QTimeS(cswitchTOffset[i]->time()).seconds() : cswitchOffset[i]->value();
|
||||
model->logicalSw[i].val2 = round((value-range.offset)/range.step);;
|
||||
value = model->logicalSw[i].val2*range.step + range.offset;
|
||||
if (source.isTimeBased())
|
||||
cswitchTOffset[i]->setTime(QTimeS(round(value)));
|
||||
else
|
||||
cswitchOffset[i]->setValue(value);
|
||||
break;
|
||||
}
|
||||
case LS_FAMILY_TIMER:
|
||||
model->logicalSw[i].val1 = TimToVal(cswitchValue[i]->value());
|
||||
model->logicalSw[i].val2 = TimToVal(cswitchOffset[i]->value());
|
||||
updateTimerParam(cswitchValue[i], model->logicalSw[i].val1, 0.1);
|
||||
updateTimerParam(cswitchOffset[i], model->logicalSw[i].val2, 0.1);
|
||||
break;
|
||||
case LS_FAMILY_EDGE:
|
||||
cswitchOffset2[i]->setSpecialValueText(" " + tr("(instant)"));
|
||||
if (sender() == cswitchOffset[i]) {
|
||||
model->logicalSw[i].val2 = TimToVal(cswitchOffset[i]->value());
|
||||
updateTimerParam(cswitchOffset[i], model->logicalSw[i].val2, 0.0);
|
||||
}
|
||||
else {
|
||||
model->logicalSw[i].val3 = TimToVal(cswitchOffset2[i]->value()) - model->logicalSw[i].val2;
|
||||
}
|
||||
updateTimerParam(cswitchOffset2[i], model->logicalSw[i].val2+model->logicalSw[i].val3, ValToTim(TimToVal(cswitchOffset[i]->value())-1));
|
||||
if (model->logicalSw[i].val3 == 0) {
|
||||
cswitchOffset2[i]->setSuffix(" " + tr("(infinite)"));
|
||||
}
|
||||
else {
|
||||
cswitchOffset2[i]->setSuffix("");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
RawSource source = RawSource(model->logicalSw[index].val1);
|
||||
RawSourceRange range = source.getRange(model, generalSettings, model->logicalSw[index].getRangeFlags());
|
||||
double currVal = source.isTimeBased() ? cswitchTOffset[index]->timeInSeconds() : cswitchOffset[index]->value();
|
||||
value = round((currVal - range.offset) / range.step);
|
||||
mod = (mod || value != model->logicalSw[index].val2);
|
||||
model->logicalSw[index].val2 = value;
|
||||
break;
|
||||
}
|
||||
emit modified();
|
||||
lock = false;
|
||||
updateLine(i);
|
||||
|
||||
case LS_FAMILY_TIMER:
|
||||
value = TimToVal(cswitchValue[index]->value());
|
||||
mod = (mod || value != model->logicalSw[index].val1);
|
||||
model->logicalSw[index].val1 = value;
|
||||
value = TimToVal(cswitchOffset[index]->value());
|
||||
mod = (mod || value != model->logicalSw[index].val2);
|
||||
model->logicalSw[index].val2 = value;
|
||||
break;
|
||||
|
||||
case LS_FAMILY_EDGE:
|
||||
if (sender() == cswitchOffset[index]) {
|
||||
value = TimToVal(cswitchOffset[index]->value());
|
||||
mod = (mod || value != model->logicalSw[index].val2);
|
||||
model->logicalSw[index].val2 = value;
|
||||
}
|
||||
else {
|
||||
value = TimToVal(cswitchOffset2[index]->value()) - model->logicalSw[index].val2;
|
||||
mod = (mod || value != model->logicalSw[index].val3);
|
||||
model->logicalSw[index].val3 = value;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
lock = false;
|
||||
|
||||
if (mod) {
|
||||
updateLine(index);
|
||||
emit modified();
|
||||
}
|
||||
return mod;
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::updateTimerParam(QDoubleSpinBox *sb, int timer, double minimum)
|
||||
@@ -303,17 +334,22 @@ void LogicalSwitchesPanel::updateTimerParam(QDoubleSpinBox *sb, int timer, doubl
|
||||
#define VALUE_TO_VISIBLE 0x20
|
||||
#define DELAY_ENABLED 0x40
|
||||
#define DURATION_ENABLED 0x80
|
||||
#define LINE_ENABLED 0x100
|
||||
|
||||
void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||
void LogicalSwitchesPanel::updateLine(int i)
|
||||
{
|
||||
lock = true;
|
||||
unsigned int mask;
|
||||
|
||||
csw[i]->setCurrentIndex(csw[i]->findData(model->logicalSw[i].func));
|
||||
cswitchAnd[i]->setCurrentIndex(cswitchAnd[i]->findData(RawSwitch(model->logicalSw[i].andsw).toValue()));
|
||||
|
||||
if (!model->logicalSw[i].func) {
|
||||
mask = 0;
|
||||
}
|
||||
else {
|
||||
mask = DELAY_ENABLED | DURATION_ENABLED;
|
||||
mask = LINE_ENABLED | DELAY_ENABLED | DURATION_ENABLED;
|
||||
|
||||
switch (model->logicalSw[i].getFunctionFamily())
|
||||
{
|
||||
case LS_FAMILY_VOFS:
|
||||
@@ -321,20 +357,16 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||
mask |= SOURCE1_VISIBLE;
|
||||
RawSource source = RawSource(model->logicalSw[i].val1);
|
||||
RawSourceRange range = source.getRange(model, generalSettings, model->logicalSw[i].getRangeFlags());
|
||||
double value = range.step * model->logicalSw[i].val2 + range.offset; /* TODO+source.getRawOffset(model)*/
|
||||
cswitchSource1[i]->setModel(rawSourceItemModel);
|
||||
cswitchSource1[i]->setCurrentIndex(cswitchSource1[i]->findData(source.toValue()));
|
||||
cswitchOffset[i]->setDecimals(range.decimals);
|
||||
cswitchOffset[i]->setSingleStep(range.step);
|
||||
if (source.isTimeBased()) {
|
||||
mask |= VALUE_TO_VISIBLE;
|
||||
int maxTime = round(range.max);
|
||||
int value = round(range.step*model->logicalSw[i].val2 + range.offset);
|
||||
cswitchTOffset[i]->setMaximumTime(QTimeS(maxTime));
|
||||
QString format = (maxTime>=3600) ? "hh:mm:ss" : "mm:ss";
|
||||
if (!range.unit.isEmpty())
|
||||
format += QString("' [%1]'").arg(range.unit);
|
||||
cswitchTOffset[i]->setDisplayFormat(format);
|
||||
cswitchTOffset[i]->setTime(QTimeS(value));
|
||||
cswitchTOffset[i]->setTimeRange(range.min, range.max);
|
||||
cswitchTOffset[i]->setSingleStep(range.step);
|
||||
cswitchTOffset[i]->setPageStep(range.step * 60);
|
||||
cswitchTOffset[i]->setShowSeconds(range.step != 60);
|
||||
cswitchTOffset[i]->setTime((int)value);
|
||||
}
|
||||
else {
|
||||
mask |= VALUE2_VISIBLE;
|
||||
@@ -342,13 +374,16 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||
cswitchOffset[i]->setSuffix("");
|
||||
else
|
||||
cswitchOffset[i]->setSuffix(" " + range.unit);
|
||||
cswitchOffset[i]->setDecimals(range.decimals);
|
||||
cswitchOffset[i]->setMinimum(range.min);
|
||||
cswitchOffset[i]->setMaximum(range.max);
|
||||
cswitchOffset[i]->setValue(range.step*(model->logicalSw[i].val2/* TODO+source.getRawOffset(model)*/)+range.offset);
|
||||
cswitchOffset[i]->setSingleStep(range.step);
|
||||
cswitchOffset[i]->setValue(value);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case LS_FAMILY_STICKY: // no break
|
||||
case LS_FAMILY_VBOOL:
|
||||
mask |= SOURCE1_VISIBLE | SOURCE2_VISIBLE;
|
||||
@@ -357,6 +392,7 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||
cswitchSource2[i]->setModel(rawSwitchItemModel);
|
||||
cswitchSource2[i]->setCurrentIndex(cswitchSource2[i]->findData(model->logicalSw[i].val2));
|
||||
break;
|
||||
|
||||
case LS_FAMILY_EDGE:
|
||||
mask |= SOURCE1_VISIBLE | VALUE2_VISIBLE | VALUE3_VISIBLE;
|
||||
mask &= ~DELAY_ENABLED;
|
||||
@@ -364,14 +400,9 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||
cswitchSource1[i]->setCurrentIndex(cswitchSource1[i]->findData(model->logicalSw[i].val1));
|
||||
updateTimerParam(cswitchOffset[i], model->logicalSw[i].val2, 0.0);
|
||||
updateTimerParam(cswitchOffset2[i], model->logicalSw[i].val2+model->logicalSw[i].val3, ValToTim(TimToVal(cswitchOffset[i]->value())-1));
|
||||
cswitchOffset2[i]->setSpecialValueText(tr("(instant)"));
|
||||
if (model->logicalSw[i].val3 == 0) {
|
||||
cswitchOffset2[i]->setSuffix(tr("(infinite)"));
|
||||
}
|
||||
else {
|
||||
cswitchOffset2[i]->setSuffix("");
|
||||
}
|
||||
cswitchOffset2[i]->setSuffix((model->logicalSw[i].val3) ? "" : tr(" (infinite)"));
|
||||
break;
|
||||
|
||||
case LS_FAMILY_VCOMP:
|
||||
mask |= SOURCE1_VISIBLE | SOURCE2_VISIBLE;
|
||||
cswitchSource1[i]->setModel(rawSourceItemModel);
|
||||
@@ -379,6 +410,7 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||
cswitchSource2[i]->setModel(rawSourceItemModel);
|
||||
cswitchSource2[i]->setCurrentIndex(cswitchSource2[i]->findData(model->logicalSw[i].val2));
|
||||
break;
|
||||
|
||||
case LS_FAMILY_TIMER:
|
||||
mask |= VALUE1_VISIBLE | VALUE2_VISIBLE;
|
||||
updateTimerParam(cswitchValue[i], model->logicalSw[i].val1, 0.1);
|
||||
@@ -393,6 +425,7 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||
cswitchOffset[i]->setVisible(mask & VALUE2_VISIBLE);
|
||||
cswitchOffset2[i]->setVisible(mask & VALUE3_VISIBLE);
|
||||
cswitchTOffset[i]->setVisible(mask & VALUE_TO_VISIBLE);
|
||||
cswitchAnd[i]->setVisible(mask & LINE_ENABLED);
|
||||
if (firmware->getCapability(LogicalSwitchesExt)) {
|
||||
cswitchDuration[i]->setVisible(mask & DURATION_ENABLED);
|
||||
cswitchDelay[i]->setVisible(mask & DELAY_ENABLED);
|
||||
@@ -401,10 +434,12 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||
if (mask & DELAY_ENABLED)
|
||||
cswitchDelay[i]->setValue(model->logicalSw[i].delay/10.0);
|
||||
}
|
||||
|
||||
rawSwitchItemModel->update();
|
||||
lock = false;
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::populateCSWCB(QComboBox *b, int value)
|
||||
void LogicalSwitchesPanel::populateCSWCB(QComboBox *b)
|
||||
{
|
||||
int order[] = {
|
||||
LS_FN_OFF,
|
||||
@@ -441,23 +476,14 @@ void LogicalSwitchesPanel::populateCSWCB(QComboBox *b, int value)
|
||||
continue;
|
||||
}
|
||||
b->addItem(LogicalSwitchData(func).funcToString(), func);
|
||||
if (value == func) {
|
||||
b->setCurrentIndex(b->count()-1);
|
||||
}
|
||||
}
|
||||
b->setMaxVisibleItems(10);
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::populateAndSwitchCB(QComboBox *b, const RawSwitch & value, const int idx)
|
||||
void LogicalSwitchesPanel::populateAndSwitchCB(QComboBox *b)
|
||||
{
|
||||
if (!model->logicalSw[idx].func) {
|
||||
b->setVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IS_ARM(firmware->getBoard())) {
|
||||
b->setModel(rawSwitchItemModel);
|
||||
b->setCurrentIndex(b->findData(value.toValue()));
|
||||
}
|
||||
else {
|
||||
RawSwitch item;
|
||||
@@ -466,36 +492,23 @@ void LogicalSwitchesPanel::populateAndSwitchCB(QComboBox *b, const RawSwitch & v
|
||||
|
||||
item = RawSwitch(SWITCH_TYPE_NONE);
|
||||
b->addItem(item.toString(), item.toValue());
|
||||
if (item == value) b->setCurrentIndex(b->count()-1);
|
||||
|
||||
for (int i=1; i <= Boards::getCapability(firmware->getBoard(), Board::SwitchPositions); i++) {
|
||||
item = RawSwitch(SWITCH_TYPE_SWITCH, i);
|
||||
b->addItem(item.toString(), item.toValue());
|
||||
if (item == value) b->setCurrentIndex(b->count()-1);
|
||||
}
|
||||
|
||||
for (int i=1; i<=6; i++) {
|
||||
item = RawSwitch(SWITCH_TYPE_VIRTUAL, i);
|
||||
b->addItem(item.toString(), item.toValue());
|
||||
if (item == value) b->setCurrentIndex(b->count()-1);
|
||||
}
|
||||
}
|
||||
b->setVisible(true);
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::updateLine(int i)
|
||||
{
|
||||
lock = true;
|
||||
populateCSWCB(csw[i], model->logicalSw[i].func);
|
||||
lock = true;
|
||||
setSwitchWidgetVisibility(i);
|
||||
lock = true;
|
||||
populateAndSwitchCB(cswitchAnd[i], RawSwitch(model->logicalSw[i].andsw), i);
|
||||
lock = false;
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::update()
|
||||
{
|
||||
setDataModels();
|
||||
for (int i=0; i<firmware->getCapability(LogicalSwitches); i++) {
|
||||
updateLine(i);
|
||||
}
|
||||
@@ -510,7 +523,6 @@ void LogicalSwitchesPanel::cswPaste()
|
||||
LogicalSwitchData *csw = &model->logicalSw[selectedSwitch];
|
||||
memcpy(csw, cswData.constData(), sizeof(LogicalSwitchData));
|
||||
emit modified();
|
||||
rawSwitchItemModel->update();
|
||||
updateLine(selectedSwitch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "radiodata.h"
|
||||
|
||||
class RawSwitchFilterItemModel;
|
||||
class TimerEdit;
|
||||
|
||||
class LogicalSwitchesPanel : public ModelPanel
|
||||
{
|
||||
@@ -37,12 +38,16 @@ class LogicalSwitchesPanel : public ModelPanel
|
||||
virtual void update();
|
||||
|
||||
private slots:
|
||||
void edited();
|
||||
void setDataModels();
|
||||
void functionChanged();
|
||||
void v1Edited(int value);
|
||||
void v2Edited(int value);
|
||||
void andEdited(int value);
|
||||
void durationEdited(double duration);
|
||||
void delayEdited(double delay);
|
||||
void offsetEdited();
|
||||
bool offsetEditedAt(int index);
|
||||
void updateLine(int index);
|
||||
void csw_customContextMenuRequested(QPoint pos);
|
||||
void cswDelete();
|
||||
void cswCopy();
|
||||
@@ -54,7 +59,7 @@ class LogicalSwitchesPanel : public ModelPanel
|
||||
QDoubleSpinBox * cswitchValue[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QDoubleSpinBox * cswitchOffset[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QDoubleSpinBox * cswitchOffset2[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QTimeEdit * cswitchTOffset[CPN_MAX_LOGICAL_SWITCHES];
|
||||
TimerEdit * cswitchTOffset[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QComboBox * cswitchAnd[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QDoubleSpinBox * cswitchDuration[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QDoubleSpinBox * cswitchDelay[CPN_MAX_LOGICAL_SWITCHES];
|
||||
@@ -62,12 +67,10 @@ class LogicalSwitchesPanel : public ModelPanel
|
||||
QComboBox * cswitchSource2[CPN_MAX_LOGICAL_SWITCHES];
|
||||
RawSwitchFilterItemModel * rawSwitchItemModel;
|
||||
QStandardItemModel * rawSourceItemModel;
|
||||
void setSwitchWidgetVisibility(int i);
|
||||
int selectedSwitch;
|
||||
|
||||
void populateCSWCB(QComboBox *b, int value);
|
||||
void populateAndSwitchCB(QComboBox *b, const RawSwitch & value, const int idx);
|
||||
void updateLine(int index);
|
||||
void populateCSWCB(QComboBox *b);
|
||||
void populateAndSwitchCB(QComboBox *b);
|
||||
void updateTimerParam(QDoubleSpinBox *sb, int timer, double minimum=0);
|
||||
|
||||
};
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "helpers.h"
|
||||
#include "appdata.h"
|
||||
|
||||
#include <TimerEdit>
|
||||
|
||||
TelemetryAnalog::TelemetryAnalog(QWidget *parent, FrSkyChannelData & analog, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::TelemetryAnalog),
|
||||
@@ -324,6 +326,13 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
|
||||
connect(minSB[l], SIGNAL(valueChanged(double)), this, SLOT(barMinChanged(double)));
|
||||
ui->screenBarsLayout->addWidget(minSB[l], l, 1, 1, 1);
|
||||
|
||||
minTime[l] = new TimerEdit(this);
|
||||
minTime[l]->setProperty("index", l);
|
||||
minTime[l]->setProperty("type", "min");
|
||||
connect(minTime[l], SIGNAL(editingFinished()), this, SLOT(barTimeChanged()));
|
||||
ui->screenBarsLayout->addWidget(minTime[l], l, 1, 1, 1);
|
||||
minTime[l]->hide();
|
||||
|
||||
QLabel * label = new QLabel(this);
|
||||
label->setAutoFillBackground(false);
|
||||
label->setStyleSheet(QString::fromUtf8("Background:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 128, 255), stop:0.339795 rgba(0, 0, 128, 255), stop:0.339799 rgba(255, 255, 255, 255), stop:0.662444 rgba(255, 255, 255, 255),)\n"""));
|
||||
@@ -336,6 +345,13 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
|
||||
maxSB[l]->setProperty("index", l);
|
||||
connect(maxSB[l], SIGNAL(valueChanged(double)), this, SLOT(barMaxChanged(double)));
|
||||
ui->screenBarsLayout->addWidget(maxSB[l], l, 3, 1, 1);
|
||||
|
||||
maxTime[l] = new TimerEdit(this);
|
||||
maxTime[l]->setProperty("index", l);
|
||||
maxTime[l]->setProperty("type", "max");
|
||||
connect(maxTime[l], SIGNAL(editingFinished()), this, SLOT(barTimeChanged()));
|
||||
ui->screenBarsLayout->addWidget(maxTime[l], l, 3, 1, 1);
|
||||
maxTime[l]->hide();
|
||||
}
|
||||
|
||||
disableMouseScrolling();
|
||||
@@ -410,30 +426,58 @@ void TelemetryCustomScreen::updateBar(int line)
|
||||
lock = true;
|
||||
|
||||
RawSource source = screen.body.bars[line].source;
|
||||
|
||||
minTime[line]->setVisible(false);
|
||||
maxTime[line]->setVisible(false);
|
||||
|
||||
if (source.type != SOURCE_TYPE_NONE) {
|
||||
RawSourceRange range = source.getRange(model, generalSettings, RANGE_SINGLE_PRECISION);
|
||||
RawSourceRange range = source.getRange(model, generalSettings);
|
||||
if (!IS_ARM(getCurrentBoard())) {
|
||||
int max = round((range.max - range.min) / range.step);
|
||||
if (int(255-screen.body.bars[line].barMax) > max) {
|
||||
screen.body.bars[line].barMax = 255 - max;
|
||||
}
|
||||
}
|
||||
minSB[line]->setEnabled(true);
|
||||
minSB[line]->setDecimals(range.decimals);
|
||||
minSB[line]->setMinimum(range.min);
|
||||
minSB[line]->setMaximum(range.max);
|
||||
minSB[line]->setSingleStep(range.step);
|
||||
minSB[line]->setValue(range.getValue(screen.body.bars[line].barMin));
|
||||
maxSB[line]->setEnabled(true);
|
||||
maxSB[line]->setDecimals(range.decimals);
|
||||
maxSB[line]->setMinimum(range.min);
|
||||
maxSB[line]->setMaximum(range.max);
|
||||
maxSB[line]->setSingleStep(range.step);
|
||||
if (IS_ARM(getCurrentBoard())) {
|
||||
maxSB[line]->setValue(range.getValue(screen.body.bars[line].barMax));
|
||||
float minVal = range.getValue(screen.body.bars[line].barMin);
|
||||
float maxVal = IS_ARM(getCurrentBoard()) ? screen.body.bars[line].barMax : 255 - screen.body.bars[line].barMax;
|
||||
maxVal = range.getValue(maxVal);
|
||||
|
||||
if (source.isTimeBased()) {
|
||||
minTime[line]->setVisible(true);
|
||||
minTime[line]->setTimeRange(range.min, range.max);
|
||||
minTime[line]->setSingleStep(range.step);
|
||||
minTime[line]->setPageStep(range.step * 60);
|
||||
minTime[line]->setShowSeconds(range.step != 60);
|
||||
minTime[line]->setTime((int)minVal);
|
||||
|
||||
maxTime[line]->setVisible(true);
|
||||
maxTime[line]->setTimeRange(range.min, range.max);
|
||||
maxTime[line]->setSingleStep(range.step);
|
||||
maxTime[line]->setPageStep(range.step * 60);
|
||||
maxTime[line]->setShowSeconds(range.step != 60);
|
||||
maxTime[line]->setTime((int)maxVal);
|
||||
|
||||
minSB[line]->setVisible(false);
|
||||
maxSB[line]->setVisible(false);
|
||||
}
|
||||
else {
|
||||
maxSB[line]->setValue(range.getValue(255 - screen.body.bars[line].barMax));
|
||||
minSB[line]->setVisible(true);
|
||||
minSB[line]->setEnabled(true);
|
||||
minSB[line]->setDecimals(range.decimals);
|
||||
minSB[line]->setMinimum(range.min);
|
||||
minSB[line]->setMaximum(range.max);
|
||||
minSB[line]->setSingleStep(range.step);
|
||||
minSB[line]->setSuffix(" " + range.unit);
|
||||
minSB[line]->setValue(minVal);
|
||||
|
||||
maxSB[line]->setVisible(true);
|
||||
maxSB[line]->setEnabled(true);
|
||||
maxSB[line]->setDecimals(range.decimals);
|
||||
maxSB[line]->setMinimum(range.min);
|
||||
maxSB[line]->setMaximum(range.max);
|
||||
maxSB[line]->setSingleStep(range.step);
|
||||
maxSB[line]->setSuffix(" " + range.unit);
|
||||
maxSB[line]->setValue(maxVal);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -511,6 +555,24 @@ void TelemetryCustomScreen::barMaxChanged(double value)
|
||||
}
|
||||
}
|
||||
|
||||
void TelemetryCustomScreen::barTimeChanged()
|
||||
{
|
||||
if (!lock) {
|
||||
int line = sender()->property("index").toInt();
|
||||
int & valRef = (sender()->property("type").toString() == "min" ? screen.body.bars[line].barMin : screen.body.bars[line].barMax);
|
||||
TimerEdit * te = qobject_cast<TimerEdit *>(sender());
|
||||
if (!te)
|
||||
return;
|
||||
|
||||
if (IS_ARM(getCurrentBoard()))
|
||||
valRef = round(te->timeInSeconds() / te->singleStep());
|
||||
else
|
||||
valRef = round((te->timeInSeconds() - te->minimumTime()) / te->singleStep());
|
||||
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::TelemetrySensor),
|
||||
@@ -598,23 +660,27 @@ void TelemetrySensorPanel::update()
|
||||
ui->formula->hide();
|
||||
isConfigurable = sensor.unit < SensorData::UNIT_FIRST_VIRTUAL;
|
||||
ratioFieldsDisplayed = (sensor.unit < SensorData::UNIT_FIRST_VIRTUAL);
|
||||
ui->offset->setMaximum((sensor.prec > 0 ? sensor.prec == 2 ? 30000 : 3000 : 300));
|
||||
ui->offset->setMinimum((sensor.prec > 0 ? sensor.prec == 2 ? -30000 : -3000 : -300));
|
||||
|
||||
if (sensor.unit == SensorData::UNIT_RPMS) {
|
||||
ui->offset->setDecimals(0);
|
||||
ui->offset->setSingleStep(1);
|
||||
ui->ratio->setDecimals(0);
|
||||
ui->ratio->setSingleStep(1);
|
||||
ui->autoOffset->hide();
|
||||
ui->ratio->setMinimum(1);
|
||||
ui->offset->setMinimum(1);
|
||||
if (ui->ratio->decimals()) {
|
||||
ui->ratio->setMaximum(30000);
|
||||
ui->ratio->setMinimum(1);
|
||||
ui->ratio->setDecimals(0);
|
||||
ui->ratio->setSingleStep(1);
|
||||
ui->offset->setMaximum(30000);
|
||||
ui->offset->setMinimum(1);
|
||||
ui->offset->setDecimals(0);
|
||||
ui->offset->setSingleStep(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui->offset->setDecimals(sensor.prec);
|
||||
ui->offset->setSingleStep(pow(0.1, (int)sensor.prec));
|
||||
else if (ui->ratio->decimals() != 1) {
|
||||
ui->ratio->setMaximum(3000);
|
||||
ui->ratio->setMinimum(0);
|
||||
ui->ratio->setDecimals(1);
|
||||
ui->ratio->setSingleStep(0.1);
|
||||
ui->offset->setMaximum(30000.0f / powf(10.0f, sensor.prec));
|
||||
ui->offset->setMinimum(-ui->offset->maximum());
|
||||
ui->offset->setDecimals(sensor.prec);
|
||||
ui->offset->setSingleStep(pow(0.1, sensor.prec));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "eeprominterface.h"
|
||||
|
||||
class AutoComboBox;
|
||||
class TimerEdit;
|
||||
|
||||
namespace Ui {
|
||||
class TelemetryAnalog;
|
||||
@@ -82,6 +83,7 @@ class TelemetryCustomScreen: public ModelPanel
|
||||
void barSourceChanged(int index);
|
||||
void barMinChanged(double value);
|
||||
void barMaxChanged(double value);
|
||||
void barTimeChanged();
|
||||
|
||||
protected:
|
||||
void populateTelemetrySourceCB(QComboBox * b, RawSource & source, bool last=false);
|
||||
@@ -94,6 +96,8 @@ class TelemetryCustomScreen: public ModelPanel
|
||||
QComboBox * barsCB[4];
|
||||
QDoubleSpinBox * minSB[4];
|
||||
QDoubleSpinBox * maxSB[4];
|
||||
TimerEdit * minTime[4];
|
||||
TimerEdit * maxTime[4];
|
||||
};
|
||||
|
||||
class TelemetrySensorPanel: public ModelPanel
|
||||
|
||||
Reference in New Issue
Block a user