diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 711b68764..6c63bb6f9 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -8,6 +8,7 @@ #include "firmwares/ersky9x/ersky9xinterface.h" #include "appdata.h" #include "helpers.h" +#include "wizarddata.h" QString EEPROMWarnings; @@ -971,6 +972,25 @@ bool ModelData::isempty() return !used; } +void ModelData::importWizardData( unsigned int id, const WizMix mix ) +{ + clear(); + used = true; + modelId = id+1; + + // Safe copy model name + strncpy ( name, mix.name, WIZ_MODEL_NAME_LENGTH); + name[WIZ_MODEL_NAME_LENGTH] = 0; + + for (int i=0; i 0){ + + //**** INSERT MIXER HERE **** + } + } +} + void ModelData::setDefaultMixes(GeneralSettings & settings) { if (IS_TARANIS(GetEepromInterface()->getBoard())) { diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index f4a2bc7dc..1af0de25f 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -24,6 +24,7 @@ #include #include #include +#include "wizarddata.h" #if __GNUC__ #define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__)) @@ -950,6 +951,7 @@ class ModelData { void clear(); bool isempty(); + void importWizardData(unsigned int, const WizMix); void setDefaultMixes(GeneralSettings & settings); void setDefaultValues(unsigned int id, GeneralSettings & settings); diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index bf1c23989..5101fa6eb 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -189,15 +189,7 @@ void MdiChild::wizardEdit() wizard->exec(); if (wizard->mix.complete){ ModelData &model = radioData.models[row - 1]; - - // Remove dicritics and filter off anything but chars from the new model name - QString newName(wizard->mix.name.normalized(QString::NormalizationForm_D)); - newName = newName.replace(QRegExp("[^a-zA-Z\\s]"), ""); - strncpy(model.name, newName.toAscii(), sizeof(model.name)); - model.name[sizeof(model.name)-1]=0; - - //TODO Save the rest of the wizard->mix data to model. - + model.importWizardData(row - 1, wizard->mix); setModified(); } } diff --git a/companion/src/wizarddata.cpp b/companion/src/wizarddata.cpp index 3b0d063df..427651c47 100644 --- a/companion/src/wizarddata.cpp +++ b/companion/src/wizarddata.cpp @@ -11,32 +11,9 @@ * GNU General Public License for more details. * */ - +#include #include "wizarddata.h" -QString inputName(Input input) -{ - switch (input){ - case THROTTLE: return "THR"; - case RUDDER: return "RUD"; - case ELEVATOR: return "ELE"; - case AILERON: return "AIL"; - case FLAP: return "FLP"; - case AIRBREAK: return "AIR"; - default: return "---"; - } -} - -QString vehicleName(Vehicle vehicle) -{ - switch (vehicle){ - case PLANE: return "Plane"; - case MULTICOPTER: return "Multicopter"; - case HELICOPTER: return "Helicopter"; - default: return "---"; - } -} - Channel::Channel() { clear(); @@ -51,38 +28,11 @@ void Channel::clear() weight2 = 0; } -bool Channel::isEmpty() -{ - return sourceDlg < 0; -} - -QString Channel::toString() -{ - QString str; - str = QString("[%1, %2]").arg(inputName(input1)).arg(weight1); - if ( input2 != NOINPUT ) - str += QString("[%1, %2]").arg(inputName(input2)).arg(weight2); - return str; -} - -Mix::Mix() +WizMix::WizMix() { complete = false; - name = ""; + strcpy(name, " "); vehicle = NOVEHICLE; } -QString Mix::toString() -{ - QString str; - str = QString(tr("Model Name: ")) + name + "\n"; - str += QString(tr("Model Type: ")) + vehicleName(vehicle) + "\n"; - for (int i=0; i -#define MAX_CHANNELS 8 +#define WIZ_MAX_CHANNELS 8 +#define WIZ_MODEL_NAME_LENGTH 12 + enum Input {NOINPUT, THROTTLE, RUDDER, ELEVATOR, AILERON, FLAP, AIRBREAK}; enum Vehicle {NOVEHICLE, PLANE, MULTICOPTER, HELICOPTER }; -QString inputName(Input); -QString vehicleName(Input); - class Channel { public: @@ -33,23 +31,18 @@ public: int weight2; Channel(); - bool isEmpty(); void clear(); - - QString toString(); }; -class Mix:QObject +class WizMix { - Q_OBJECT public: bool complete; - QString name; + char name[WIZ_MODEL_NAME_LENGTH + 1]; Vehicle vehicle; - Channel channel[MAX_CHANNELS]; + Channel channel[WIZ_MAX_CHANNELS]; - Mix(); - QString toString(); + WizMix(); }; #endif // WIZARDDATA_H diff --git a/companion/src/wizarddialog.cpp b/companion/src/wizarddialog.cpp index ad39ecde2..0eaf56d3e 100644 --- a/companion/src/wizarddialog.cpp +++ b/companion/src/wizarddialog.cpp @@ -14,6 +14,7 @@ #include #include "wizarddialog.h" +#include "wizarddata.h" WizardDialog::WizardDialog(QWidget *parent) : QWizard(parent) @@ -139,12 +140,12 @@ StandardPage::StandardPage(int currentPage, WizardDialog *dlg, QString image, QS void StandardPage::populateCB( QComboBox *CB ) { - for (int j=0; jremoveItem(0); - for (int i=0; imix.channel[i].isEmpty()){ + if (wizDlg->mix.channel[i].sourceDlg < 0){ CB->addItem(tr("Channel ") + QString("%1").arg(i+1), i); } } @@ -154,9 +155,9 @@ bool StandardPage::bookChannel(QString label, Input input1, int weight1, Input i { int index = label.right(1).toInt() - 1; - if (index<0 || index >= MAX_CHANNELS) + if (index<0 || index >= WIZ_MAX_CHANNELS) return false; - if (!wizDlg->mix.channel[index].isEmpty()) + if (!(wizDlg->mix.channel[index].sourceDlg < 0)) return false; wizDlg->mix.channel[index].sourceDlg = pageCurrent; @@ -170,7 +171,7 @@ bool StandardPage::bookChannel(QString label, Input input1, int weight1, Input i void StandardPage::releaseChannels() { - for (int i=0; imix.channel[i].sourceDlg == pageCurrent){ wizDlg->mix.channel[i].clear(); @@ -211,7 +212,13 @@ ModelSelectionPage::ModelSelectionPage(WizardDialog *dlg, QString image, QString bool ModelSelectionPage::validatePage() { - wizDlg->mix.name = nameLineEdit->text(); + //Filter and insert model name in mix data + QString newName(nameLineEdit->text()); + newName = (newName.normalized(QString::NormalizationForm_D)); + newName = newName.replace(QRegExp("[^ A-Za-z0-9_.-,\\s]"), ""); + strncpy( wizDlg->mix.name, newName.toAscii(), WIZ_MODEL_NAME_LENGTH); + wizDlg->mix.name[WIZ_MODEL_NAME_LENGTH]=0; + if (multirotorRB->isChecked()) wizDlg->mix.vehicle = MULTICOPTER; else if (helicopterRB->isChecked()) @@ -719,8 +726,8 @@ ConclusionPage::ConclusionPage(WizardDialog *dlg, QString image, QString title, } void ConclusionPage::initializePage(){ - - textLabel->setText(wizDlg->mix.toString()); + WizardPrinter p(&wizDlg->mix); + textLabel->setText(p.print()); } bool ConclusionPage::validatePage() { @@ -729,3 +736,58 @@ bool ConclusionPage::validatePage() { } +QString WizardPrinter::inputName(Input input) +{ + switch (input){ + case THROTTLE: return "THR"; + case RUDDER: return "RUD"; + case ELEVATOR: return "ELE"; + case AILERON: return "AIL"; + case FLAP: return "FLP"; + case AIRBREAK: return "AIR"; + default: return "---"; + } +} + +QString WizardPrinter::vehicleName(Vehicle vehicle) +{ + switch (vehicle){ + case PLANE: return "Plane"; + case MULTICOPTER: return "Multicopter"; + case HELICOPTER: return "Helicopter"; + default: return "---"; + } +} + +WizardPrinter::WizardPrinter(WizMix *wizMix) +{ + mix = wizMix; +} + + QString WizardPrinter::printChannel( Input input1, int weight1, Input input2, int weight2 ) +{ + QString str; + str = QString("[%1, %2]").arg(inputName(input1)).arg(weight1); + if ( input2 != NOINPUT ) + str += QString("[%1, %2]").arg(inputName(input2)).arg(weight2); + return str; +} + +QString WizardPrinter::print() +{ + QString str; + str = QString(tr("Model Name: ")) + mix->name + "\n"; + str += QString(tr("Model Type: ")) + vehicleName(mix->vehicle) + "\n"; + for (int i=0; ichannel[i].sourceDlg < 0 )){ + Channel ch = mix->channel[i]; + str += QString(tr("Channel %1: ").arg(i+1)); + str += printChannel(ch.input1, ch.weight1, ch.input2, ch.weight2 ); + str += QString("\n"); + } + } + return str; +} + + + diff --git a/companion/src/wizarddialog.h b/companion/src/wizarddialog.h index 57dedd019..35cc66793 100644 --- a/companion/src/wizarddialog.h +++ b/companion/src/wizarddialog.h @@ -35,7 +35,7 @@ public: Page_Fblheli, Page_Helictrl, Page_Multirotor, Page_Conclusion }; - Mix mix; + WizMix mix; WizardDialog(QWidget *parent = 0); private slots: @@ -308,4 +308,19 @@ private: QLabel *textLabel; }; +class WizardPrinter:QObject +{ + Q_OBJECT +public: + WizardPrinter( WizMix * ); + QString print(); +private: + WizMix *mix; + QString inputName( Input ); + QString vehicleName( Vehicle ); + QString printChannel( Input, int, Input, int ); +}; #endif // WIZARDDIALOG_H + + +