1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 16:55:20 +03:00

[Companion] Servos limits are displayed in us if ppmus option selected

This commit is contained in:
bsongis 2014-08-26 16:14:29 +02:00
parent 1721fd635e
commit 1f8b3725c4
6 changed files with 102 additions and 127 deletions

View file

@ -1135,6 +1135,7 @@ enum Capability {
HasSoundMixer, HasSoundMixer,
NumModules, NumModules,
PPMCenter, PPMCenter,
PPMUnitMicroseconds,
SYMLimits, SYMLimits,
HasCurrentCalibration, HasCurrentCalibration,
HasVolume, HasVolume,

View file

@ -665,7 +665,9 @@ int OpenTxFirmware::getCapability(const Capability capability)
case TelemetryMaxMultiplier: case TelemetryMaxMultiplier:
return (IS_ARM(board) ? 32 : 8); return (IS_ARM(board) ? 32 : 8);
case PPMCenter: case PPMCenter:
return (IS_TARANIS(board) ? 500 : 125); return (IS_TARANIS(board) ? 500 : (id.contains("ppmca") ? 125 : 0));
case PPMUnitMicroseconds:
return id.contains("ppmus") ? 1 : 0;
case SYMLimits: case SYMLimits:
return 1; return 1;
case OptrexDisplay: case OptrexDisplay:

View file

@ -147,7 +147,7 @@ void populatePhasesCB(QComboBox *b, int value)
b->setCurrentIndex(value + GetCurrentFirmware()->getCapability(FlightModes)); b->setCurrentIndex(value + GetCurrentFirmware()->getCapability(FlightModes));
} }
GVarGroup::GVarGroup(QCheckBox *weightGV, QAbstractSpinBox *weightSB, QComboBox *weightCB, int & weight, const int deflt, const int mini, const int maxi, const double step, const unsigned int flags): GVarGroup::GVarGroup(QCheckBox *weightGV, QAbstractSpinBox *weightSB, QComboBox *weightCB, int & weight, const int deflt, const int mini, const int maxi, const double step, bool allowGvars):
QObject(), QObject(),
weightGV(weightGV), weightGV(weightGV),
weightSB(weightSB), weightSB(weightSB),
@ -156,10 +156,9 @@ GVarGroup::GVarGroup(QCheckBox *weightGV, QAbstractSpinBox *weightSB, QComboBox
weightCB(weightCB), weightCB(weightCB),
weight(weight), weight(weight),
step(step), step(step),
flags(flags),
lock(true) lock(true)
{ {
if (GetCurrentFirmware()->getCapability(Gvars)) { if (allowGvars && GetCurrentFirmware()->getCapability(Gvars)) {
populateGVCB(weightCB, weight); populateGVCB(weightCB, weight);
connect(weightGV, SIGNAL(stateChanged(int)), this, SLOT(gvarCBChanged(int))); connect(weightGV, SIGNAL(stateChanged(int)), this, SLOT(gvarCBChanged(int)));
connect(weightCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged())); connect(weightCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged()));

View file

@ -42,7 +42,7 @@ class GVarGroup: public QObject {
Q_OBJECT Q_OBJECT
public: public:
GVarGroup(QCheckBox *weightGV, QAbstractSpinBox *weightSB, QComboBox *weightCB, int & weight, const int deflt, const int mini, const int maxi, const double step=1, const unsigned int flags=0); GVarGroup(QCheckBox *weightGV, QAbstractSpinBox *weightSB, QComboBox *weightCB, int & weight, const int deflt, const int mini, const int maxi, const double step=1, bool allowGVars=true);
protected slots: protected slots:
void gvarCBChanged(int); void gvarCBChanged(int);
@ -56,7 +56,6 @@ class GVarGroup: public QObject {
QComboBox *weightCB; QComboBox *weightCB;
int & weight; int & weight;
double step; double step;
unsigned int flags;
bool lock; bool lock;
}; };

View file

@ -7,6 +7,74 @@
#include <QCheckBox> #include <QCheckBox>
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
LimitsGroup::LimitsGroup(FirmwareInterface * firmware, QGridLayout *gridLayout, int row, int col, int & value, int min, int max, int deflt):
firmware(firmware),
spinbox(new QDoubleSpinBox()),
value(value),
step(1.0)
{
bool allowGVars = false;
spinbox->setProperty("index", row);
spinbox->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
spinbox->setAccelerated(true);
if (firmware->getCapability(PPMUnitMicroseconds)) {
step = 5.12;
spinbox->setDecimals(1);
spinbox->setSuffix("us");
}
else {
spinbox->setDecimals(0);
spinbox->setSuffix("%");
}
if (IS_TARANIS(firmware->getBoard()) || deflt == 0 /*it's the offset*/) {
min *= 10;
max *= 10;
deflt *= 10;
step /= 10;
spinbox->setDecimals(1);
allowGVars = true;
}
spinbox->setSingleStep(step);
QHBoxLayout * horizontalLayout = new QHBoxLayout();
QCheckBox * gv = new QCheckBox(QObject::tr("GV"));
horizontalLayout->addWidget(gv);
QComboBox * cb = new QComboBox();
horizontalLayout->addWidget(cb);
horizontalLayout->addWidget(spinbox);
gridLayout->addLayout(horizontalLayout, row, col, 1, 1);
gvarGroup = new GVarGroup(gv, spinbox, cb, value, deflt, min, max, step, allowGVars);
}
LimitsGroup::~LimitsGroup()
{
delete gvarGroup;
}
void LimitsGroup::updateMinMax(int max)
{
if (IS_TARANIS(firmware->getBoard())) {
max *= 10;
}
if (spinbox->maximum() == 0) {
spinbox->setMinimum(-step*max);
if (value < -max) {
value = -max;
}
}
if (spinbox->minimum() == 0) {
spinbox->setMaximum(step*max);
if (value > max) {
value = max;
}
}
}
Channels::Channels(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, FirmwareInterface * firmware): Channels::Channels(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, FirmwareInterface * firmware):
ModelPanel(parent, model, generalSettings, firmware) ModelPanel(parent, model, generalSettings, firmware)
{ {
@ -52,85 +120,13 @@ Channels::Channels(QWidget * parent, ModelData & model, GeneralSettings & genera
} }
// Channel offset // Channel offset
QDoubleSpinBox * offset = new QDoubleSpinBox(this); limitsGroups << new LimitsGroup(firmware, gridLayout, i+1, col++, model.limitData[i].offset, -100, 100, 0);
offset->setProperty("index", i);
offset->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
offset->setAccelerated(true);
offset->setDecimals(1);
offset->setSingleStep(0.1);
if (IS_TARANIS(firmware->getBoard())) {
QHBoxLayout * horizontalLayout = new QHBoxLayout();
QCheckBox * ofsGV = new QCheckBox(tr("GV"));
horizontalLayout->addWidget(ofsGV);
QComboBox * ofsCB = new QComboBox(this);
horizontalLayout->addWidget(ofsCB);
horizontalLayout->addWidget(offset);
gridLayout->addLayout(horizontalLayout, i+1, col++, 1, 1);
ofsGroup = new GVarGroup(ofsGV, offset, ofsCB, model.limitData[i].offset, 0, -10*model.getChannelsMax(), 10*model.getChannelsMax(), 0.1);
}
else {
offset->setMinimum(-100);
offset->setMaximum(100);
offset->setValue(float(model.limitData[i].offset) / 10);
connect(offset, SIGNAL(editingFinished()), this, SLOT(offsetEdited()));
gridLayout->addWidget(offset, i+1, col++, 1, 1);
}
// Channel min // Channel min
QDoubleSpinBox * minSB = new QDoubleSpinBox(this); limitsGroups << new LimitsGroup(firmware, gridLayout, i+1, col++, model.limitData[i].min, -model.getChannelsMax(), 0, -100);
minSB->setProperty("index", i);
minSB->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
minSB->setAccelerated(true);
if (IS_TARANIS(firmware->getBoard())) {
QHBoxLayout * horizontalLayout = new QHBoxLayout();
QCheckBox * minGV = new QCheckBox(tr("GV"));
horizontalLayout->addWidget(minGV);
QComboBox * minCB = new QComboBox(this);
horizontalLayout->addWidget(minCB);
minSB->setDecimals(1);
minSB->setSingleStep(0.1);
horizontalLayout->addWidget(minSB);
gridLayout->addLayout(horizontalLayout, i+1, col++, 1, 1);
minGroup = new GVarGroup(minGV, minSB, minCB, model.limitData[i].min, -1000, -10*model.getChannelsMax(), 0, 0.1);
}
else {
minSB->setDecimals(0);
minSB->setSingleStep(1);
minSB->setMinimum(-model.getChannelsMax());
minSB->setMaximum(0);
minSB->setValue(model.limitData[i].min / 10);
connect(minSB, SIGNAL(editingFinished()), this, SLOT(minEdited()));
gridLayout->addWidget(minSB, i+1, col++, 1, 1);
}
minSpins << minSB;
// Channel max // Channel max
QDoubleSpinBox * maxSB = new QDoubleSpinBox(this); limitsGroups << new LimitsGroup(firmware, gridLayout, i+1, col++, model.limitData[i].max, 0, model.getChannelsMax(), 100);
maxSB->setProperty("index", i);
maxSB->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
maxSB->setAccelerated(true);
if (IS_TARANIS(firmware->getBoard())) {
QHBoxLayout * horizontalLayout = new QHBoxLayout();
QCheckBox * maxGV = new QCheckBox(tr("GV"));
horizontalLayout->addWidget(maxGV);
QComboBox * maxCB = new QComboBox(this);
horizontalLayout->addWidget(maxCB);
maxSB->setDecimals(1);
maxSB->setSingleStep(0.1);
horizontalLayout->addWidget(maxSB);
gridLayout->addLayout(horizontalLayout, i+1, col++, 1, 1);
maxGroup = new GVarGroup(maxGV, maxSB, maxCB, model.limitData[i].max, 1000, 0, 10*model.getChannelsMax(), 0.1);
}
else {
maxSB->setDecimals(0);
maxSB->setSingleStep(1);
maxSB->setMinimum(0);
maxSB->setMaximum(model.getChannelsMax());
maxSB->setValue(model.limitData[i].max / 10);
connect(maxSB, SIGNAL(editingFinished()), this, SLOT(maxEdited()));
gridLayout->addWidget(maxSB, i+1, col++, 1, 1);
}
maxSpins << maxSB;
// Channel inversion // Channel inversion
QComboBox * invCB = new QComboBox(this); QComboBox * invCB = new QComboBox(this);
@ -159,6 +155,7 @@ Channels::Channels(QWidget * parent, ModelData & model, GeneralSettings & genera
QSpinBox * center = new QSpinBox(this); QSpinBox * center = new QSpinBox(this);
center->setProperty("index", i); center->setProperty("index", i);
center->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); center->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
center->setSuffix("us");
center->setMinimum(1500-ppmCenterMax); center->setMinimum(1500-ppmCenterMax);
center->setMaximum(1500+ppmCenterMax); center->setMaximum(1500+ppmCenterMax);
center->setValue(1500); center->setValue(1500);
@ -185,9 +182,9 @@ Channels::Channels(QWidget * parent, ModelData & model, GeneralSettings & genera
Channels::~Channels() Channels::~Channels()
{ {
delete ofsGroup; foreach(LimitsGroup *group, limitsGroups) {
delete minGroup; delete group;
delete maxGroup; }
} }
void Channels::symlimitsEdited() void Channels::symlimitsEdited()
@ -210,46 +207,14 @@ void Channels::nameEdited()
} }
} }
void Channels::offsetEdited()
{
QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox*>(sender());
int index = dsb->property("index").toInt();
model.limitData[index].offset = round(dsb->value() * 10);
emit modified();
}
void Channels::minEdited()
{
QDoubleSpinBox *sb = qobject_cast<QDoubleSpinBox*>(sender());
int index = sb->property("index").toInt();
model.limitData[index].min = round(sb->value() * 10);
emit modified();
}
void Channels::maxEdited()
{
QDoubleSpinBox *sb = qobject_cast<QDoubleSpinBox*>(sender());
int index = sb->property("index").toInt();
model.limitData[index].max = round(sb->value() * 10);
emit modified();
}
void Channels::refreshExtendedLimits() void Channels::refreshExtendedLimits()
{ {
int channelMax = model.getChannelsMax(); int channelMax = model.getChannelsMax();
int channelMaxValue = channelMax * 10;
for (int i=0; i<firmware->getCapability(Outputs); i++) { foreach(LimitsGroup *group, limitsGroups) {
QDoubleSpinBox * minDSB = minSpins[i]; group->updateMinMax(channelMax);
QDoubleSpinBox * maxDSB = maxSpins[i];
minDSB->setMinimum(-channelMax);
maxDSB->setMaximum(+channelMax);
//reset any limit that is bigger than current maximum (dependent on extended limits setting)
if ( model.limitData[i].min < -channelMaxValue ) model.limitData[i].min = -channelMaxValue;
if ( model.limitData[i].max > +channelMaxValue ) model.limitData[i].max = +channelMaxValue;
} }
emit modified(); emit modified();
} }

View file

@ -6,6 +6,22 @@
class GVarGroup; class GVarGroup;
class LimitsGroup
{
public:
LimitsGroup(FirmwareInterface * firmware, QGridLayout *gridLayout, int row, int col, int & value, int min, int max, int deflt);
~LimitsGroup();
void updateMinMax(int max);
protected:
FirmwareInterface * firmware;
QDoubleSpinBox * spinbox;
GVarGroup * gvarGroup;
int & value;
double step;
};
class Channels : public ModelPanel class Channels : public ModelPanel
{ {
Q_OBJECT Q_OBJECT
@ -15,11 +31,7 @@ class Channels : public ModelPanel
~Channels(); ~Channels();
private: private:
QVector<QDoubleSpinBox *> minSpins; QVector<LimitsGroup *> limitsGroups;
QVector<QDoubleSpinBox *> maxSpins;
GVarGroup * ofsGroup;
GVarGroup * minGroup;
GVarGroup * maxGroup;
public slots: public slots:
void refreshExtendedLimits(); void refreshExtendedLimits();
@ -27,9 +39,6 @@ class Channels : public ModelPanel
private slots: private slots:
void symlimitsEdited(); void symlimitsEdited();
void nameEdited(); void nameEdited();
void offsetEdited();
void minEdited();
void maxEdited();
void invEdited(); void invEdited();
void curveEdited(); void curveEdited();
void ppmcenterEdited(); void ppmcenterEdited();