294 lines
11 KiB
C++
294 lines
11 KiB
C++
#include "mixerdialog.h"
|
|
#include "ui_mixerdialog.h"
|
|
#include "eeprominterface.h"
|
|
#include "helpers.h"
|
|
|
|
MixerDialog::MixerDialog(QWidget *parent, MixData *mixdata, int stickMode) :
|
|
QDialog(parent),
|
|
ui(new Ui::MixerDialog),
|
|
md(mixdata)
|
|
{
|
|
ui->setupUi(this);
|
|
QRegExp rx(CHAR_FOR_NAMES_REGEX);
|
|
QLabel * lb_fp[] = {ui->lb_FP0,ui->lb_FP1,ui->lb_FP2,ui->lb_FP3,ui->lb_FP4,ui->lb_FP5,ui->lb_FP6,ui->lb_FP7,ui->lb_FP8 };
|
|
QCheckBox * cb_fp[] = {ui->cb_FP0,ui->cb_FP1,ui->cb_FP2,ui->cb_FP3,ui->cb_FP4,ui->cb_FP5,ui->cb_FP6,ui->cb_FP7,ui->cb_FP8 };
|
|
|
|
if (md->destCh > (unsigned int)GetEepromInterface()->getCapability(Outputs))
|
|
this->setWindowTitle(tr("DEST -> X%1").arg(md->destCh-GetEepromInterface()->getCapability(Outputs)));
|
|
else
|
|
this->setWindowTitle(tr("DEST -> CH%1%2").arg(md->destCh/10).arg(md->destCh%10));
|
|
|
|
populateSourceCB(ui->sourceCB, md->srcRaw, POPULATE_SOURCES | POPULATE_SWITCHES | (GetEepromInterface()->getCapability(ExtraTrims) ? POPULATE_TRIMS : 0) | (GetEepromInterface()->getCapability(GvarsAsSources) ? POPULATE_GVARS : 0));
|
|
|
|
ui->sourceCB->removeItem(0);
|
|
int limit=GetEepromInterface()->getCapability(OffsetWeight);
|
|
if (GetEepromInterface()->getCapability(GvarsAsWeight)) {
|
|
int gvars=0;
|
|
if (GetEepromInterface()->getCapability(HasVariants)) {
|
|
if ((GetCurrentFirmwareVariant() & GVARS_VARIANT)) {
|
|
gvars=1;
|
|
}
|
|
} else {
|
|
gvars=1;
|
|
}
|
|
if (gvars==0) {
|
|
ui->offsetGV->setDisabled(true);
|
|
ui->weightGV->setDisabled(true);
|
|
if (md->weight>limit || md->weight<-limit) {
|
|
md->weight=100;
|
|
}
|
|
if (md->sOffset>limit || md->sOffset<-limit) {
|
|
md->sOffset=0;
|
|
}
|
|
}
|
|
populateGVCB(ui->offsetCB,md->sOffset);
|
|
populateGVCB(ui->weightCB,md->weight);
|
|
ui->weightSB->setMinimum(-limit);
|
|
ui->weightSB->setMaximum(limit);
|
|
if (md->weight>limit || md->weight<-limit) {
|
|
ui->weightGV->setChecked(true);
|
|
ui->weightSB->hide();
|
|
ui->weightCB->show();
|
|
} else {
|
|
ui->weightGV->setChecked(false);
|
|
ui->weightSB->setValue(md->weight);
|
|
ui->weightSB->show();
|
|
ui->weightCB->hide();
|
|
}
|
|
|
|
ui->offsetSB->setMinimum(-limit);
|
|
ui->offsetSB->setMaximum(limit);
|
|
if (md->sOffset>limit || md->sOffset<-limit) {
|
|
ui->offsetGV->setChecked(true);
|
|
ui->offsetSB->hide();
|
|
ui->offsetCB->show();
|
|
}
|
|
else {
|
|
ui->offsetGV->setChecked(false);
|
|
ui->offsetSB->setValue(md->sOffset);
|
|
ui->offsetSB->show();
|
|
ui->offsetCB->hide();
|
|
}
|
|
}
|
|
else {
|
|
ui->offsetGV->hide();
|
|
ui->weightGV->hide();
|
|
ui->offsetSB->setMinimum(-limit);
|
|
ui->offsetSB->setMaximum(limit);
|
|
ui->offsetSB->setValue(md->sOffset);
|
|
ui->weightSB->setMinimum(-limit);
|
|
ui->weightSB->setMaximum(limit);
|
|
ui->weightSB->setValue(md->weight);
|
|
}
|
|
|
|
populateCurveReference(ui->curveTypeCB, ui->curveGVarCB, ui->curveValueCB, ui->curveValueSB, md->curve, 0);
|
|
|
|
ui->MixDR_CB->setChecked(md->noExpo==0);
|
|
if (!GetEepromInterface()->getCapability(MixesWithoutExpo)) {
|
|
ui->MixDR_CB->hide();
|
|
ui->label_MixDR->hide();
|
|
}
|
|
if (GetEepromInterface()->getCapability(ExtraTrims)) {
|
|
ui->trimCB->addItem(tr("Rud"),1);
|
|
ui->trimCB->addItem(tr("Ele"),2);
|
|
ui->trimCB->addItem(tr("Thr"),3);
|
|
ui->trimCB->addItem(tr("Ail"),4);
|
|
}
|
|
ui->trimCB->setCurrentIndex((-md->carryTrim)+1);
|
|
int namelength=GetEepromInterface()->getCapability(HasMixerNames);
|
|
if (!namelength) {
|
|
ui->label_name->hide();
|
|
ui->mixerName->hide();
|
|
} else {
|
|
ui->mixerName->setMaxLength(namelength);
|
|
}
|
|
if (!GetEepromInterface()->getCapability(FlightPhases)) {
|
|
ui->label_phases->hide();
|
|
for (int i=0; i<9; i++) {
|
|
lb_fp[i]->hide();
|
|
cb_fp[i]->hide();
|
|
}
|
|
}
|
|
else {
|
|
int mask=1;
|
|
for (int i=0; i<9 ; i++) {
|
|
if ((md->phases & mask)==0) {
|
|
cb_fp[i]->setChecked(true);
|
|
}
|
|
mask <<= 1;
|
|
}
|
|
for (int i=GetEepromInterface()->getCapability(FlightPhases); i<9;i++) {
|
|
lb_fp[i]->hide();
|
|
cb_fp[i]->hide();
|
|
}
|
|
}
|
|
|
|
ui->mixerName->setValidator(new QRegExpValidator(rx, this));
|
|
ui->mixerName->setText(md->name);
|
|
|
|
populateSwitchCB(ui->switchesCB,md->swtch);
|
|
ui->warningCB->setCurrentIndex(md->mixWarn);
|
|
ui->mltpxCB->setCurrentIndex(md->mltpx);
|
|
int scale=GetEepromInterface()->getCapability(SlowScale);
|
|
float range=GetEepromInterface()->getCapability(SlowRange);
|
|
ui->slowDownSB->setMaximum(range/scale);
|
|
ui->slowDownSB->setSingleStep(1.0/scale);
|
|
ui->slowDownSB->setDecimals((scale==1 ? 0 :1));
|
|
ui->slowDownSB->setValue((float)md->speedDown/scale);
|
|
ui->slowUpSB->setMaximum(range/scale);
|
|
ui->slowUpSB->setSingleStep(1.0/scale);
|
|
ui->slowUpSB->setDecimals((scale==1 ? 0 :1));
|
|
ui->slowUpSB->setValue((float)md->speedUp/scale);
|
|
ui->delayDownSB->setMaximum(range/scale);
|
|
ui->delayDownSB->setSingleStep(1.0/scale);
|
|
ui->delayDownSB->setDecimals((scale==1 ? 0 :1));
|
|
ui->delayDownSB->setValue((float)md->delayDown/scale);
|
|
ui->delayUpSB->setMaximum(range/scale);
|
|
ui->delayUpSB->setSingleStep(1.0/scale);
|
|
ui->delayUpSB->setDecimals((scale==1 ? 0 :1));
|
|
ui->delayUpSB->setValue((float)md->delayUp/scale);
|
|
QTimer::singleShot(0, this, SLOT(shrink()));
|
|
|
|
valuesChanged();
|
|
connect(ui->mixerName,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
|
|
connect(ui->sourceCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
|
|
connect(ui->weightCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
|
|
connect(ui->offsetCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
|
|
|
|
connect(ui->curveTypeCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
|
|
connect(ui->curveGVarCB,SIGNAL(stateChanged(int)),this,SLOT(valuesChanged()));
|
|
connect(ui->curveValueCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
|
|
connect(ui->curveValueSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
|
|
|
|
connect(ui->weightSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
|
|
connect(ui->offsetSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
|
|
connect(ui->weightGV,SIGNAL(stateChanged(int)),this,SLOT(widgetChanged())); // TODO why the same slot?
|
|
connect(ui->offsetGV,SIGNAL(stateChanged(int)),this,SLOT(widgetChanged()));
|
|
connect(ui->trimCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
|
|
connect(ui->MixDR_CB,SIGNAL(toggled(bool)),this,SLOT(valuesChanged()));
|
|
connect(ui->switchesCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
|
|
connect(ui->warningCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
|
|
connect(ui->mltpxCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
|
|
connect(ui->delayDownSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
|
|
connect(ui->delayUpSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
|
|
connect(ui->slowDownSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
|
|
connect(ui->slowUpSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
|
|
for (int i=0; i<9; i++) {
|
|
connect(cb_fp[i],SIGNAL(toggled(bool)),this,SLOT(valuesChanged()));
|
|
}
|
|
}
|
|
|
|
MixerDialog::~MixerDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MixerDialog::changeEvent(QEvent *e)
|
|
{
|
|
QDialog::changeEvent(e);
|
|
switch (e->type()) {
|
|
case QEvent::LanguageChange:
|
|
ui->retranslateUi(this);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void MixerDialog::widgetChanged()
|
|
{
|
|
if (GetEepromInterface()->getCapability(GvarsAsWeight)) {
|
|
int gvars=0;
|
|
if (GetEepromInterface()->getCapability(HasVariants)) {
|
|
if ((GetCurrentFirmwareVariant() & GVARS_VARIANT)) {
|
|
gvars=1;
|
|
}
|
|
} else {
|
|
gvars=1;
|
|
}
|
|
if (gvars==1) {
|
|
if (ui->weightGV->isChecked()) {
|
|
ui->weightCB->show();
|
|
ui->weightSB->hide();
|
|
} else {
|
|
ui->weightCB->hide();
|
|
ui->weightSB->show();
|
|
}
|
|
if (ui->offsetGV->isChecked()) {
|
|
ui->offsetCB->show();
|
|
ui->offsetSB->hide();
|
|
} else {
|
|
ui->offsetCB->hide();
|
|
ui->offsetSB->show();
|
|
}
|
|
}
|
|
valuesChanged();
|
|
QTimer::singleShot(0, this, SLOT(shrink()));
|
|
}
|
|
}
|
|
|
|
void MixerDialog::valuesChanged()
|
|
{
|
|
QCheckBox * cb_fp[] = {ui->cb_FP0,ui->cb_FP1,ui->cb_FP2,ui->cb_FP3,ui->cb_FP4,ui->cb_FP5,ui->cb_FP6,ui->cb_FP7,ui->cb_FP8 };
|
|
md->srcRaw = RawSource(ui->sourceCB->itemData(ui->sourceCB->currentIndex()).toInt());
|
|
if ((ui->sourceCB->itemData(ui->sourceCB->currentIndex()).toInt()-65536)<4) {
|
|
if (!GetEepromInterface()->getCapability(MixesWithoutExpo)) {
|
|
ui->MixDR_CB->hide();
|
|
ui->label_MixDR->hide();
|
|
} else {
|
|
ui->MixDR_CB->setVisible(true);
|
|
ui->label_MixDR->setVisible(true);
|
|
}
|
|
} else {
|
|
ui->MixDR_CB->setHidden(true);
|
|
ui->label_MixDR->setHidden(true);
|
|
}
|
|
if (ui->weightGV->isChecked()) {
|
|
md->weight = ui->weightCB->itemData(ui->weightCB->currentIndex()).toInt();
|
|
} else {
|
|
md->weight = ui->weightSB->value();
|
|
}
|
|
if (ui->offsetGV->isChecked()) {
|
|
md->sOffset = ui->offsetCB->itemData(ui->offsetCB->currentIndex()).toInt();
|
|
} else {
|
|
md->sOffset = ui->offsetSB->value();
|
|
}
|
|
md->carryTrim = -(ui->trimCB->currentIndex()-1);
|
|
md->noExpo = ui->MixDR_CB->checkState() ? 0 : 1;
|
|
|
|
// TODO md->curve = ui->curvesCB->currentIndex()-(numcurves)*GetEepromInterface()->getCapability(HasNegCurves);
|
|
// TODO if (ui->differentialGV->isChecked()) {
|
|
// TODO md->differential = ui->differentialCB->itemData(ui->differentialCB->currentIndex()).toInt();
|
|
// TODO } else {
|
|
// TODO md->differential = ui->differentialSB->value();
|
|
// TODO }
|
|
// populateCurveReference(QComboBox *curveTypeCB, QCheckBox *curveGVarCB, QComboBox *curveValueCB, QSpinBox *curveValueCB, CurveReference & curve, unsigned int flags)
|
|
|
|
md->swtch = RawSwitch(ui->switchesCB->itemData(ui->switchesCB->currentIndex()).toInt());
|
|
md->mixWarn = ui->warningCB->currentIndex();
|
|
md->mltpx = (MltpxValue)ui->mltpxCB->currentIndex();
|
|
int scale=GetEepromInterface()->getCapability(SlowScale);
|
|
md->delayDown = round(ui->delayDownSB->value()*scale);
|
|
md->delayUp = round(ui->delayUpSB->value()*scale);
|
|
md->speedDown = round(ui->slowDownSB->value()*scale);
|
|
md->speedUp = round(ui->slowUpSB->value()*scale);
|
|
|
|
int i=0;
|
|
for (i=0; i<ui->mixerName->text().toAscii().length(); i++) {
|
|
md->name[i]=ui->mixerName->text().toAscii().at(i);
|
|
}
|
|
md->name[i]=0;
|
|
md->phases=0;
|
|
for (int i=8; i>=0 ; i--) {
|
|
if (!cb_fp[i]->checkState()) {
|
|
md->phases+=1;
|
|
}
|
|
md->phases<<=1;
|
|
}
|
|
md->phases>>=1;
|
|
}
|
|
|
|
void MixerDialog::shrink() {
|
|
resize(0,0);
|
|
}
|