1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-17 21:35:27 +03:00

Fixes #1266 - Companion timer value not in time format

This commit is contained in:
Damjan Adamic 2014-06-13 23:29:07 +02:00
parent e3df420f8e
commit 37ec428efc
5 changed files with 73 additions and 16 deletions

View file

@ -459,6 +459,11 @@ CSFunctionFamily LogicalSwitchData::getFunctionFamily()
return LS_FAMILY_VCOMP; return LS_FAMILY_VCOMP;
} }
bool LogicalSwitchData::isDeltaFunction()
{
return (func == LS_FN_DPOS || func == LS_FN_DAPOS);
}
QString LogicalSwitchData::funcToString() QString LogicalSwitchData::funcToString()
{ {
switch (func) { switch (func) {
@ -545,7 +550,7 @@ QString LogicalSwitchData::toString(const ModelData & model)
else if (func == LS_FN_DPOS) result = "d(" + res + ")"; else if (func == LS_FN_DPOS) result = "d(" + res + ")";
result += res; result += res;
if (func == LS_FN_APOS || func == LS_FN_VPOS || func == LS_FN_DAPOS || func == LS_FN_DPOS) if (func == LS_FN_APOS || func == LS_FN_VPOS || isDeltaFunction())
result += " > "; result += " > ";
else if (func == LS_FN_ANEG || func == LS_FN_VNEG) else if (func == LS_FN_ANEG || func == LS_FN_VNEG)
result += " < "; result += " < ";

View file

@ -370,6 +370,11 @@ class RawSource {
return (this->type != other.type) || (this->index != other.index); return (this->type != other.type) || (this->index != other.index);
} }
bool isTimeBased() const
{
return (type==SOURCE_TYPE_TELEMETRY && (index==1 || index==2 || index==3));
}
RawSourceType type; RawSourceType type;
int index; int index;
const ModelData * model; const ModelData * model;
@ -710,6 +715,7 @@ class LogicalSwitchData { // Logical Switches data
int andsw; int andsw;
void clear() { memset(this, 0, sizeof(LogicalSwitchData)); } void clear() { memset(this, 0, sizeof(LogicalSwitchData)); }
CSFunctionFamily getFunctionFamily(); CSFunctionFamily getFunctionFamily();
bool isDeltaFunction();
QString funcToString(); QString funcToString();
QString toString(const ModelData & model); QString toString(const ModelData & model);
}; };

View file

@ -132,4 +132,12 @@ QPixmap makePixMap( QImage image, QString firmwareType );
int version2index(QString version); int version2index(QString version);
QString index2version(int index); QString index2version(int index);
class QTimeS : public QTime
{
public:
QTimeS(int s) { int h = s/3600; s %= 3600; int m = s/60; s %=60; setHMS(h, m, s); };
QTimeS(const QTime & q) : QTime(q) {};
int seconds() const { return hour()*3600 + minute()*60 + second(); };
};
#endif // HELPERS_H #endif // HELPERS_H

View file

@ -82,6 +82,12 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
connect(cswitchOffset2[i], SIGNAL(editingFinished()), this, SLOT(edited())); connect(cswitchOffset2[i], SIGNAL(editingFinished()), this, SLOT(edited()));
cswitchOffset2[i]->setVisible(false); cswitchOffset2[i]->setVisible(false);
v2Layout->addWidget(cswitchOffset2[i]); v2Layout->addWidget(cswitchOffset2[i]);
cswitchTOffset[i] = new QTimeEdit(this);
cswitchTOffset[i]->setProperty("index",i);
cswitchTOffset[i]->setAccelerated(true);
connect(cswitchTOffset[i],SIGNAL(editingFinished()),this,SLOT(edited()));
v2Layout->addWidget(cswitchTOffset[i]);
cswitchTOffset[i]->setVisible(false);
gridLayout->addLayout(v2Layout, i+1, 3); gridLayout->addLayout(v2Layout, i+1, 3);
// AND // AND
@ -134,7 +140,7 @@ void LogicalSwitchesPanel::v1Edited(int value)
if (model.customSw[i].getFunctionFamily() == LS_FAMILY_VOFS) { if (model.customSw[i].getFunctionFamily() == LS_FAMILY_VOFS) {
RawSource source = RawSource(model.customSw[i].val1, &model); RawSource source = RawSource(model.customSw[i].val1, &model);
RawSourceRange range = source.getRange(); RawSourceRange range = source.getRange();
if (model.customSw[i].func == LS_FN_DPOS || model.customSw[i].func == LS_FN_DAPOS) { if (model.customSw[i].isDeltaFunction()) {
model.customSw[i].val2 = (cswitchOffset[i]->value() / range.step); model.customSw[i].val2 = (cswitchOffset[i]->value() / range.step);
} }
else { else {
@ -185,6 +191,7 @@ void LogicalSwitchesPanel::edited()
int i = sender()->property("index").toInt(); int i = sender()->property("index").toInt();
int newFunc = csw[i]->itemData(csw[i]->currentIndex()).toInt(); int newFunc = csw[i]->itemData(csw[i]->currentIndex()).toInt();
bool chAr = (model.customSw[i].getFunctionFamily() != LogicalSwitchData(newFunc).getFunctionFamily()); bool chAr = (model.customSw[i].getFunctionFamily() != LogicalSwitchData(newFunc).getFunctionFamily());
bool chDelta = (model.customSw[i].isDeltaFunction() ^ LogicalSwitchData(newFunc).isDeltaFunction());
model.customSw[i].func = newFunc; model.customSw[i].func = newFunc;
if (chAr) { if (chAr) {
if (model.customSw[i].getFunctionFamily() == LS_FAMILY_TIMER) { if (model.customSw[i].getFunctionFamily() == LS_FAMILY_TIMER) {
@ -203,6 +210,10 @@ void LogicalSwitchesPanel::edited()
model.customSw[i].andsw = 0; model.customSw[i].andsw = 0;
setSwitchWidgetVisibility(i); setSwitchWidgetVisibility(i);
} }
if (chDelta) {
model.customSw[i].val2 = 0;
setSwitchWidgetVisibility(i);
}
RawSource source; RawSource source;
switch (model.customSw[i].getFunctionFamily()) switch (model.customSw[i].getFunctionFamily())
@ -211,14 +222,18 @@ void LogicalSwitchesPanel::edited()
{ {
source = RawSource(model.customSw[i].val1, &model); source = RawSource(model.customSw[i].val1, &model);
RawSourceRange range = source.getRange(); RawSourceRange range = source.getRange();
if (model.customSw[i].func == LS_FN_DPOS || model.customSw[i].func == LS_FN_DAPOS) { int value = source.isTimeBased() ? QTimeS(cswitchTOffset[i]->time()).seconds() : cswitchOffset[i]->value();
model.customSw[i].val2 = (cswitchOffset[i]->value() / range.step); if (model.customSw[i].isDeltaFunction()) {
cswitchOffset[i]->setValue(model.customSw[i].val2*range.step); /*TODO: is this delta function value set correctly*/
model.customSw[i].val2 = (value/range.step);
value=model.customSw[i].val2*range.step;
} }
else { else {
model.customSw[i].val2 = round((cswitchOffset[i]->value()-range.offset)/range.step); model.customSw[i].val2 = round((value-range.offset)/range.step);;
cswitchOffset[i]->setValue(model.customSw[i].val2*range.step + range.offset); value= model.customSw[i].val2*range.step + range.offset;
} }
if (source.isTimeBased()) cswitchTOffset[i]->setTime(QTimeS(value));
else cswitchOffset[i]->setValue(value);
break; break;
} }
case LS_FAMILY_TIMER: case LS_FAMILY_TIMER:
@ -266,6 +281,7 @@ void LogicalSwitchesPanel::updateTimerParam(QDoubleSpinBox *sb, int timer, bool
#define VALUE1_VISIBLE 0x4 #define VALUE1_VISIBLE 0x4
#define VALUE2_VISIBLE 0x8 #define VALUE2_VISIBLE 0x8
#define VALUE3_VISIBLE 0x10 #define VALUE3_VISIBLE 0x10
#define VALUE_TO_VISIBLE 0x20
void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i) void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
{ {
@ -278,11 +294,30 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
switch (model.customSw[i].getFunctionFamily()) switch (model.customSw[i].getFunctionFamily())
{ {
case LS_FAMILY_VOFS: case LS_FAMILY_VOFS:
mask |= SOURCE1_VISIBLE | VALUE2_VISIBLE; mask |= SOURCE1_VISIBLE;
populateSourceCB(cswitchSource1[i], source, model, POPULATE_SOURCES | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | POPULATE_TELEMETRY | (firmware->getCapability(GvarsInCS) ? POPULATE_GVARS : 0)); populateSourceCB(cswitchSource1[i], source, model, POPULATE_SOURCES | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | POPULATE_TELEMETRY | (firmware->getCapability(GvarsInCS) ? POPULATE_GVARS : 0));
cswitchOffset[i]->setDecimals(range.decimals); cswitchOffset[i]->setDecimals(range.decimals);
cswitchOffset[i]->setSingleStep(range.step); cswitchOffset[i]->setSingleStep(range.step);
if (model.customSw[i].func == LS_FN_DPOS || model.customSw[i].func == LS_FN_DAPOS) { if (source.isTimeBased()) {
mask |= VALUE_TO_VISIBLE;
int maxTime;
int value;
if (model.customSw[i].isDeltaFunction()) {
/*TODO: is this delta function value set correctly*/
maxTime = range.step*127;
value = range.step*model.customSw[i].val2;
} else {
maxTime = range.max;
value = range.step*(model.customSw[i].val2/* TODO+source.getRawOffset(model)*/)+range.offset;
}
cswitchTOffset[i]->setMaximumTime(QTimeS(maxTime));
cswitchTOffset[i]->setDisplayFormat((maxTime>=3600)?"hh:mm:ss":"mm:ss");
cswitchTOffset[i]->setTime(QTimeS(value));
}
else {
mask |= VALUE2_VISIBLE;
if (model.customSw[i].isDeltaFunction()) {
/*TODO: is this delta function value set correctly*/
cswitchOffset[i]->setMinimum(range.step*-127); cswitchOffset[i]->setMinimum(range.step*-127);
cswitchOffset[i]->setMaximum(range.step*127); cswitchOffset[i]->setMaximum(range.step*127);
cswitchOffset[i]->setValue(range.step*model.customSw[i].val2); cswitchOffset[i]->setValue(range.step*model.customSw[i].val2);
@ -292,6 +327,7 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
cswitchOffset[i]->setMaximum(range.max); cswitchOffset[i]->setMaximum(range.max);
cswitchOffset[i]->setValue(range.step*(model.customSw[i].val2/* TODO+source.getRawOffset(model)*/)+range.offset); cswitchOffset[i]->setValue(range.step*(model.customSw[i].val2/* TODO+source.getRawOffset(model)*/)+range.offset);
} }
}
break; break;
case LS_FAMILY_VBOOL: case LS_FAMILY_VBOOL:
case LS_FAMILY_STICKY: case LS_FAMILY_STICKY:
@ -322,7 +358,7 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
cswitchValue[i]->setVisible(mask & VALUE1_VISIBLE); cswitchValue[i]->setVisible(mask & VALUE1_VISIBLE);
cswitchOffset[i]->setVisible(mask & VALUE2_VISIBLE); cswitchOffset[i]->setVisible(mask & VALUE2_VISIBLE);
cswitchOffset2[i]->setVisible(mask & VALUE3_VISIBLE); cswitchOffset2[i]->setVisible(mask & VALUE3_VISIBLE);
cswitchTOffset[i]->setVisible(mask & VALUE_TO_VISIBLE);
lock = false; lock = false;
} }

View file

@ -4,6 +4,7 @@
#include "modelpanel.h" #include "modelpanel.h"
#include <QComboBox> #include <QComboBox>
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
#include <QTimeEdit>
class LogicalSwitchesPanel : public ModelPanel class LogicalSwitchesPanel : public ModelPanel
{ {
@ -33,6 +34,7 @@ class LogicalSwitchesPanel : public ModelPanel
QDoubleSpinBox * cswitchValue[C9X_NUM_CSW]; QDoubleSpinBox * cswitchValue[C9X_NUM_CSW];
QDoubleSpinBox * cswitchOffset[C9X_NUM_CSW]; QDoubleSpinBox * cswitchOffset[C9X_NUM_CSW];
QDoubleSpinBox * cswitchOffset2[C9X_NUM_CSW]; QDoubleSpinBox * cswitchOffset2[C9X_NUM_CSW];
QTimeEdit * cswitchTOffset[C9X_NUM_CSW];
QComboBox * cswitchAnd[C9X_NUM_CSW]; QComboBox * cswitchAnd[C9X_NUM_CSW];
QDoubleSpinBox * cswitchDuration[C9X_NUM_CSW]; QDoubleSpinBox * cswitchDuration[C9X_NUM_CSW];
QDoubleSpinBox * cswitchDelay[C9X_NUM_CSW]; QDoubleSpinBox * cswitchDelay[C9X_NUM_CSW];