Example #1
0
void ExpoDialog::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 (!GetEepromInterface()->getCapability(ExpoIsCurve)) {
          if (ui->expoGV->isChecked()) {
            ui->expoCB->show();
            ui->expoSB->hide();
          } else {
            ui->expoCB->hide();
            ui->expoSB->show();
          }
        } else {
          if (ui->expoCurveGV->isChecked()) {
            ui->expoCurveCB->show();
            ui->expoCurveSB->hide();
          } else {
            ui->expoCurveCB->hide();
            ui->expoCurveSB->show();
          }
        }
        if (ui->weightGV->isChecked()) {
          ui->weightCB->show();
          ui->weightSB->hide();
        } else {
          ui->weightCB->hide();
          ui->weightSB->show();
        }
      }
      valuesChanged();
      QTimer::singleShot(0, this, SLOT(shrink()));      
    }
}
Example #2
0
ExpoDialog::ExpoDialog(QWidget *parent, ExpoData *expoData, int stickMode) :
    QDialog(parent),
    ui(new Ui::ExpoDialog),
    ed(expoData)
{
    ui->setupUi(this);
    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 };

    setWindowTitle(tr("DEST -> %1").arg(getStickStr(ed->chn)));
    QRegExp rx(CHAR_FOR_NAMES_REGEX);
    
    if (GetEepromInterface()->getCapability(GvarsAsWeight)) {
      int gvars=0;
      if (GetEepromInterface()->getCapability(HasVariants)) {
        if ((GetCurrentFirmwareVariant() & GVARS_VARIANT)) {
          gvars=1;
        }
      } else {
        gvars=1;
      }
      if (gvars==0) {
        ui->expoGV->setDisabled(true);
        ui->weightGV->setDisabled(true);
        ui->expoCurveGV->setDisabled(true);
        if (ed->expo>100) {
          ed->expo=0;
        }
        if (ed->weight>100 || ed->weight<-100) {
          ed->weight=100;
        }
        if (ed->curveParam>100 || ed->curveParam<-100) {
          ed->curveParam=0;
        }
      }
      populateGVCB(ui->expoCB,ed->expo);
      populateGVCB(ui->weightCB,ed->weight);
      populateGVCB(ui->expoCurveCB,ed->curveParam);

      ui->weightSB->setMinimum(0);
      ui->weightSB->setMaximum(100);
      if (ed->weight>100 || ed->weight<0) {
        ui->weightGV->setChecked(true);
        ui->weightSB->hide();
        ui->weightCB->show();
      } else {
        ui->weightGV->setChecked(false);
        ui->weightSB->setValue(ed->weight);
        ui->weightSB->show();
        ui->weightCB->hide();
      }

      ui->expoSB->setMinimum(-100);
      ui->expoSB->setMaximum(100);
      if (ed->expo>100 || ed->expo<-100) {
        ui->expoGV->setChecked(true);
        ui->expoSB->hide();
        ui->expoCB->show();
      } else {
        ui->expoGV->setChecked(false);
        ui->expoSB->setValue(ed->expo);
        ui->expoSB->show();
        ui->expoCB->hide();
      }

      ui->expoCurveSB->setMinimum(-100);
      ui->expoCurveSB->setMaximum(100);
      if (ed->curveParam>100 || ed->curveParam<-100) {
        ui->expoCurveGV->setChecked(true);
        ui->expoCurveSB->hide();
        ui->expoCurveCB->show();
      } else {
        ui->expoCurveGV->setChecked(false);
        ui->expoCurveSB->setValue(ed->curveParam);
        ui->expoCurveSB->show();
        ui->expoCurveCB->hide();
      }
    } else {
      ui->expoGV->hide();
      ui->weightGV->hide();
      ui->expoCurveGV->hide();
      ui->expoSB->setMinimum(-100);
      ui->expoSB->setMaximum(100);
      ui->expoSB->setValue(ed->expo);
      ui->expoCurveSB->setMinimum(-100);
      ui->expoCurveSB->setMaximum(100);
      ui->expoCurveSB->setValue(ed->curveParam);
      ui->weightSB->setMinimum(0);
      ui->weightSB->setMaximum(100);
      ui->weightSB->setValue(ed->weight);
    }
    populateSwitchCB(ui->switchesCB,ed->swtch);
    if (ed->curveMode==0) {
      populateExpoCurvesCB(ui->curvesCB,0); // TODO capacity for er9x
    } else {
      populateExpoCurvesCB(ui->curvesCB,ed->curveParam); // TODO capacity for er9x
    }
    ui->modeCB->setCurrentIndex(ed->mode-1);
    if (!GetEepromInterface()->getCapability(HasExpoCurves)) {
      ui->label_curves->hide();
      ui->curvesCB->hide();
      ed->curveMode=1;
    }
    if (!GetEepromInterface()->getCapability(ExpoIsCurve)) {
      ui->expoCurveCB->hide();
      ui->expoCurveSB->hide();
      ui->expoCurveGV->hide();
      ui->label_curves->setText(tr("Curve"));
    } else {
      ui->label_expo->hide();
      ui->expoCB->hide();
      ui->expoGV->hide();
      ui->expoSB->hide();
    }
    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 ((ed->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();
      }      
    }
    int expolength=GetEepromInterface()->getCapability(HasExpoNames);
    if (!expolength) {
      ui->label_name->hide();
      ui->expoName->hide();
    } else {
      ui->expoName->setMaxLength(expolength);
    }
    ui->expoName->setValidator(new QRegExpValidator(rx, this));
    ui->expoName->setText(ed->name);
    valuesChanged();
    connect(ui->expoName,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
    connect(ui->expoCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
    connect(ui->expoSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
    connect(ui->expoCurveCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
    connect(ui->expoCurveSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
    connect(ui->weightCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
    connect(ui->weightSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
    connect(ui->switchesCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
    connect(ui->curvesCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
    connect(ui->modeCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
    connect(ui->expoGV,SIGNAL(stateChanged(int)),this,SLOT(widgetChanged()));
    connect(ui->expoCurveGV,SIGNAL(stateChanged(int)),this,SLOT(widgetChanged()));
    connect(ui->weightGV,SIGNAL(stateChanged(int)),this,SLOT(widgetChanged()));
    for (int i=0; i<9; i++) {
      connect(cb_fp[i],SIGNAL(toggled(bool)),this,SLOT(valuesChanged()));
    }
    QTimer::singleShot(0, this, SLOT(shrink()));
}
Example #3
0
void burnDialog::on_BurnFlashButton_clicked()
{
  if (hexType==FLASH_FILE_TYPE) {
    QString fileName=ui->FWFileName->text();
    if (!fileName.isEmpty()) {
      g.flashDir( QFileInfo(fileName).dir().absolutePath() );
      if (!ui->useFwImageCB->isChecked()) {
        QImage image = ui->imageLabel->pixmap()->toImage().scaled(ui->imageLabel->width(), ui->imageLabel->height());
        if (!image.isNull()) {
          QString tempDir = QDir::tempPath();
          QString tempFile;
          if (getFileType(fileName) == FILE_TYPE_HEX)
            tempFile = tempDir + "/flash.hex";
          else
            tempFile = tempDir + "/flash.bin";
          FlashInterface flash(fileName);
          flash.setSplash(image);
          if (flash.saveFlash(tempFile) > 0) {
            hexfileName->clear();
            hexfileName->append(tempFile);
          } else {
            hexfileName->clear();
            QMessageBox::critical(this, tr("Warning"), tr("Cannot save customized firmware"));
          }
        }
        else {
          hexfileName->clear();
          QMessageBox::critical(this, tr("Warning"), tr("Custom image not found"));
        }
      }
      else {
        hexfileName->clear();
        hexfileName->append(fileName);
      }
    }
    else {
      QMessageBox::critical(this, tr("Warning"), tr("No firmware selected"));
      hexfileName->clear();     
    }
  }
  if (hexType==EEPROM_FILE_TYPE) {
    QString calib = g.profile[g.id()].stickPotCalib();
    QString trainercalib = g.profile[g.id()].trainerCalib();
    int potsnum=GetCurrentFirmware()->getCapability(Pots);
    int8_t vBatCalib=(int8_t) g.profile[g.id()].vBatCalib();
    int8_t currentCalib=(int8_t) g.profile[g.id()].currentCalib();
    int8_t PPM_Multiplier=(int8_t) g.profile[g.id()].ppmMultiplier();
    uint8_t GSStickMode=(uint8_t) g.profile[g.id()].gsStickMode();
    uint8_t vBatWarn=(uint8_t) g.profile[g.id()].vBatWarn();
    
    QString DisplaySet= g.profile[g.id()].display();
    QString BeeperSet= g.profile[g.id()].beeper();
    QString HapticSet= g.profile[g.id()].haptic();
    QString SpeakerSet= g.profile[g.id()].speaker();
    bool patch=false;
    if (ui->patchcalib_CB->isChecked()) {
      if ((calib.length()==(NUM_STICKS+potsnum)*12) && (trainercalib.length()==16)) {
        QString Byte;
        int16_t byte16;
        bool ok;
        for (int i=0; i<(NUM_STICKS+potsnum); i++) {
          Byte=calib.mid(i*12,4);
          byte16=(int16_t)Byte.toInt(&ok,16);
          if (ok)
            radioData.generalSettings.calibMid[i]=byte16;
          Byte=calib.mid(4+i*12,4);
          byte16=(int16_t)Byte.toInt(&ok,16);
          if (ok)
            radioData.generalSettings.calibSpanNeg[i]=byte16;
          Byte=calib.mid(8+i*12,4);
          byte16=(int16_t)Byte.toInt(&ok,16);
          if (ok)
            radioData.generalSettings.calibSpanPos[i]=byte16;
        }
        for (int i=0; i<4; i++) {
          Byte=trainercalib.mid(i*4,4);
          byte16=(int16_t)Byte.toInt(&ok,16);
          if (ok)
            radioData.generalSettings.trainer.calib[i]=byte16;
        }
        radioData.generalSettings.currentCalib=currentCalib;
        radioData.generalSettings.vBatCalib=vBatCalib;
        radioData.generalSettings.PPM_Multiplier=PPM_Multiplier;
        patch=true;
      } else {
        QMessageBox::critical(this, tr("Warning"), tr("Wrong radio calibration data in profile, Settings not patched"));
      }
    }
    if (ui->patchhw_CB->isChecked()) {
      if ((DisplaySet.length()==6) && (BeeperSet.length()==4) && (HapticSet.length()==6) && (SpeakerSet.length()==6)) {
        radioData.generalSettings.vBatWarn=vBatWarn;
        radioData.generalSettings.stickMode=GSStickMode;
        uint8_t byte8u;
        int8_t byte8;
        bool ok;
        byte8=(int8_t)DisplaySet.mid(0,2).toInt(&ok,16);
        if (ok)
          radioData.generalSettings.optrexDisplay=(byte8==1 ? true : false);
        byte8u=(uint8_t)DisplaySet.mid(2,2).toUInt(&ok,16);
        if (ok)
          radioData.generalSettings.contrast=byte8u;

        byte8u=(uint8_t)DisplaySet.mid(4,2).toUInt(&ok,16);
        if (ok)
          radioData.generalSettings.backlightBright=byte8u;

        byte8u=(uint8_t)BeeperSet.mid(0,2).toUInt(&ok,16);
        if (ok)
          radioData.generalSettings.beeperMode=(BeeperMode)byte8u;

        byte8=(int8_t)BeeperSet.mid(2,2).toInt(&ok,16);
        if (ok)
          radioData.generalSettings.beeperLength=byte8;

        byte8u=(uint8_t)HapticSet.mid(0,2).toUInt(&ok,16);
        if (ok)
          radioData.generalSettings.hapticMode=(BeeperMode)byte8u;

        byte8u=(uint8_t)HapticSet.mid(2,2).toUInt(&ok,16);
        if (ok)
          radioData.generalSettings.hapticStrength=byte8u;

        byte8=(int8_t)HapticSet.mid(4,2).toInt(&ok,16);
        if (ok)
          radioData.generalSettings.hapticLength=byte8;

        byte8u=(uint8_t)SpeakerSet.mid(0,2).toUInt(&ok,16);
        if (ok)
          radioData.generalSettings.speakerMode=byte8u;

        byte8u=(uint8_t)SpeakerSet.mid(2,2).toUInt(&ok,16);
        if (ok)
          radioData.generalSettings.speakerPitch=byte8u;

        byte8u=(uint8_t)SpeakerSet.mid(4,2).toUInt(&ok,16);
        if (ok)
          radioData.generalSettings.speakerVolume=byte8u;
        patch=true;
      } else {
        QMessageBox::critical(this, tr("Warning"), tr("Wrong radio setting data in profile, Settings not patched"));
      }
    
      QString fileName;
      if (patch) {
        QString tempDir    = QDir::tempPath();
        fileName = tempDir + "/temp.bin";
        QFile file(fileName);

        uint8_t *eeprom = (uint8_t*)malloc(GetEepromInterface()->getEEpromSize());
        int eeprom_size = 0;

        eeprom_size = GetEepromInterface()->save(eeprom, radioData, GetCurrentFirmwareVariant());
        if (!eeprom_size) {
          QMessageBox::warning(this, tr("Error"),tr("Cannot write file %1:\n%2.").arg(fileName).arg(file.errorString()));
          hexfileName->clear();
        }

        if (!file.open(QIODevice::WriteOnly)) {
          QMessageBox::warning(this, tr("Error"),tr("Cannot write file %1:\n%2.").arg(fileName).arg(file.errorString()));
          hexfileName->clear();
        }

        QTextStream outputStream(&file);

        long result = file.write((char*)eeprom, eeprom_size);
        if(result!=eeprom_size) {
          QMessageBox::warning(this, tr("Error"),tr("Error writing file %1:\n%2.").arg(fileName).arg(file.errorString()));
          hexfileName->clear();
        }
        hexfileName->clear();
        hexfileName->append(fileName);
      } else {
        hexfileName->clear();
        hexfileName->append(ui->FWFileName->text());        
      }
    } else {
      hexfileName->clear();
      hexfileName->append(ui->FWFileName->text());        
    }
  }
  this->close();
}