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

New plce holder function in eeprominterface for importing wizard data. Need help from Bertrand since the format of the real mixes is mysterious.

This commit is contained in:
Kjell Kernen 2014-03-04 13:36:01 +01:00
parent 11565e05e9
commit b133a990f1
7 changed files with 121 additions and 87 deletions

View file

@ -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<WIZ_MAX_CHANNELS; i++ ){
Channel ch = mix.channel[i];
if (ch.sourceDlg > 0){
//**** INSERT MIXER HERE ****
}
}
}
void ModelData::setDefaultMixes(GeneralSettings & settings)
{
if (IS_TARANIS(GetEepromInterface()->getBoard())) {

View file

@ -24,6 +24,7 @@
#include <QList>
#include <QtXml>
#include <iostream>
#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);

View file

@ -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();
}
}

View file

@ -11,32 +11,9 @@
* GNU General Public License for more details.
*
*/
#include <string.h>
#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<MAX_CHANNELS; i++){
if (!channel[i].isEmpty()){
str += QString(tr("Channel %1: ").arg(i+1));
str += channel[i].toString();
str += QString("\n");
}
}
return str;
}

View file

@ -14,15 +14,13 @@
#ifndef WIZARDDATA_H
#define WIZARDDATA_H
#include <QObject>
#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

View file

@ -14,6 +14,7 @@
#include <QtGui>
#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; j<MAX_CHANNELS; j++)
for (int j=0; j<WIZ_MAX_CHANNELS; j++)
CB->removeItem(0);
for (int i=0; i<MAX_CHANNELS; i++)
for (int i=0; i<WIZ_MAX_CHANNELS; i++)
{
if (wizDlg->mix.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; i<MAX_CHANNELS; i++)
for (int i=0; i<WIZ_MAX_CHANNELS; i++)
{
if (wizDlg->mix.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; i<WIZ_MAX_CHANNELS; i++){
if (!(mix->channel[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;
}

View file

@ -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