Rev 440 |
Rev 449 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/***************************************************************************
* Copyright (C) 2009 by Manuel Schrape *
* manuel.schrape@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "dlg_MotorMixer.h"
dlg_MotorMixer::dlg_MotorMixer(QWidget *parent) : QDialog(parent)
{
setupUi(this);
connect(pb_READ, SIGNAL(clicked()), this, SLOT(slot_pb_READ()));
connect(pb_LOAD, SIGNAL(clicked()), this, SLOT(slot_pb_LOAD()));
connect(pb_SAVE, SIGNAL(clicked()), this, SLOT(slot_pb_SAVE()));
connect(pb_WRITE, SIGNAL(clicked()), this, SLOT(slot_pb_WRITE()));
connect(sb_NICK_1, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_2, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_3, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_4, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_5, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_6, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_7, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_8, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_9, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_10, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_11, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_NICK_12, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_1, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_2, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_3, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_4, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_5, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_6, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_7, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_8, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_9, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_10, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_11, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_ROLL_12, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_1, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_2, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_3, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_4, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_5, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_6, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_7, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_8, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_9, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_10, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_11, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
connect(sb_GIER_12, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int)));
}
// Connection-Object übergeben.
void dlg_MotorMixer::set_Objects(Handler *handler, cSettings *t_Settings)
{
this->handler = handler;
this->data = handler->data;
o_Settings = t_Settings;
}
// Motordaten übernehmen.
void dlg_MotorMixer::set_MotorConfig(sRxData RX)
{
//FIXME: put this in libMK/Handler.cpp and fill motor values in KopterData
/*
int Pos = 0;
MixerName = ToolBox::dataToQString(RX.decode, 1, 12);
Pos = 13;
for (int z = 0; z < 16; z++)
{
for (int y = 0; y < 4; y++)
{
Motor[z][y] = Parser::dataToChar(RX.decode,Pos);
Pos++;
}
}
set_MotorData();
*/
}
// Motordaten aus GUI übernehmen
void dlg_MotorMixer::get_MotorData()
{
sMotorData motorData;
char * mixerName = le_NAME->text().toAscii().data();
motorData.mixer_name = string(mixerName);
int gas[MAX_MOTORS] = {
sb_GAS_1->value(), sb_GAS_2->value(), sb_GAS_3->value(), sb_GAS_4->value(),
sb_GAS_5->value(), sb_GAS_6->value(), sb_GAS_7->value(), sb_GAS_8->value(),
sb_GAS_9->value(), sb_GAS_10->value(), sb_GAS_11->value(), sb_GAS_12->value()
};
int nick[MAX_MOTORS] = {
sb_NICK_1->value(), sb_NICK_2->value(), sb_NICK_3->value(), sb_NICK_4->value(),
sb_NICK_5->value(), sb_NICK_6->value(), sb_NICK_7->value(), sb_NICK_8->value(),
sb_NICK_9->value(), sb_NICK_10->value(), sb_NICK_11->value(), sb_NICK_12->value()
};
int roll[MAX_MOTORS] = {
sb_ROLL_1->value(), sb_ROLL_2->value(), sb_ROLL_3->value(), sb_ROLL_4->value(),
sb_ROLL_5->value(), sb_ROLL_6->value(), sb_ROLL_7->value(), sb_ROLL_8->value(),
sb_ROLL_9->value(), sb_ROLL_10->value(), sb_ROLL_11->value(), sb_ROLL_12->value()
};
int yaw[MAX_MOTORS] = {
sb_GIER_1->value(), sb_GIER_2->value(), sb_GIER_3->value(), sb_GIER_4->value(),
sb_GIER_5->value(), sb_GIER_6->value(), sb_GIER_7->value(), sb_GIER_8->value(),
sb_GIER_9->value(), sb_GIER_10->value(), sb_GIER_11->value(), sb_GIER_12->value()
};
for (int i = 0; i < MAX_MOTORS; i++) {
motorData.mixer_gas[i] = gas[i];
motorData.mixer_nick[i] = nick[i];
motorData.mixer_roll[i] = roll[i];
motorData.mixer_yaw[i] = yaw[i];
}
//FIXME: add Function in handler to send data
}
// Motordaten anzeigen
void dlg_MotorMixer::set_MotorData()
{
sMotorData motorData = handler->data->motor;
le_NAME->setText(motorData.mixer_name.c_str());
sb_GAS_1->setValue(motorData.mixer_gas[0]);
sb_GAS_2->setValue(motorData.mixer_gas[1]);
sb_GAS_3->setValue(motorData.mixer_gas[2]);
sb_GAS_4->setValue(motorData.mixer_gas[3]);
sb_GAS_5->setValue(motorData.mixer_gas[4]);
sb_GAS_6->setValue(motorData.mixer_gas[5]);
sb_GAS_7->setValue(motorData.mixer_gas[6]);
sb_GAS_8->setValue(motorData.mixer_gas[7]);
sb_GAS_9->setValue(motorData.mixer_gas[8]);
sb_GAS_10->setValue(motorData.mixer_gas[9]);
sb_GAS_11->setValue(motorData.mixer_gas[10]);
sb_GAS_12->setValue(motorData.mixer_gas[11]);
sb_NICK_1->setValue(motorData.mixer_nick[0]);
sb_NICK_2->setValue(motorData.mixer_nick[1]);
sb_NICK_3->setValue(motorData.mixer_nick[2]);
sb_NICK_4->setValue(motorData.mixer_nick[3]);
sb_NICK_5->setValue(motorData.mixer_nick[4]);
sb_NICK_6->setValue(motorData.mixer_nick[5]);
sb_NICK_7->setValue(motorData.mixer_nick[6]);
sb_NICK_8->setValue(motorData.mixer_nick[7]);
sb_NICK_9->setValue(motorData.mixer_nick[8]);
sb_NICK_10->setValue(motorData.mixer_nick[9]);
sb_NICK_11->setValue(motorData.mixer_nick[10]);
sb_NICK_12->setValue(motorData.mixer_nick[11]);
sb_ROLL_1->setValue(motorData.mixer_roll[0]);
sb_ROLL_2->setValue(motorData.mixer_roll[1]);
sb_ROLL_3->setValue(motorData.mixer_roll[2]);
sb_ROLL_4->setValue(motorData.mixer_roll[3]);
sb_ROLL_5->setValue(motorData.mixer_roll[4]);
sb_ROLL_6->setValue(motorData.mixer_roll[5]);
sb_ROLL_7->setValue(motorData.mixer_roll[6]);
sb_ROLL_8->setValue(motorData.mixer_roll[7]);
sb_ROLL_9->setValue(motorData.mixer_roll[8]);
sb_ROLL_10->setValue(motorData.mixer_roll[9]);
sb_ROLL_11->setValue(motorData.mixer_roll[10]);
sb_ROLL_12->setValue(motorData.mixer_roll[11]);
sb_GIER_1->setValue(motorData.mixer_yaw[0]);
sb_GIER_2->setValue(motorData.mixer_yaw[1]);
sb_GIER_3->setValue(motorData.mixer_yaw[2]);
sb_GIER_4->setValue(motorData.mixer_yaw[3]);
sb_GIER_5->setValue(motorData.mixer_yaw[4]);
sb_GIER_6->setValue(motorData.mixer_yaw[5]);
sb_GIER_7->setValue(motorData.mixer_yaw[6]);
sb_GIER_8->setValue(motorData.mixer_yaw[7]);
sb_GIER_9->setValue(motorData.mixer_yaw[8]);
sb_GIER_10->setValue(motorData.mixer_yaw[9]);
sb_GIER_11->setValue(motorData.mixer_yaw[10]);
sb_GIER_12->setValue(motorData.mixer_yaw[11]);
}
// Prüfen auf vollstaändigkeit
void dlg_MotorMixer::slot_CheckValue(int Wert)
{
Wert = Wert;
int NICK = sb_NICK_1->value() + sb_NICK_2->value() + sb_NICK_3->value() +
sb_NICK_4->value() + sb_NICK_5->value() + sb_NICK_6->value() +
sb_NICK_7->value() + sb_NICK_8->value() + sb_NICK_9->value() +
sb_NICK_10->value() + sb_NICK_11->value() + sb_NICK_12->value();
int ROLL = sb_ROLL_1->value() + sb_ROLL_2->value() + sb_ROLL_3->value() +
sb_ROLL_4->value() + sb_ROLL_5->value() + sb_ROLL_6->value() +
sb_ROLL_7->value() + sb_ROLL_8->value() + sb_ROLL_9->value() +
sb_ROLL_10->value() + sb_ROLL_11->value() + sb_ROLL_12->value();
int GIER = sb_GIER_1->value() + sb_GIER_2->value() + sb_GIER_3->value() +
sb_GIER_4->value() + sb_GIER_5->value() + sb_GIER_6->value() +
sb_GIER_7->value() + sb_GIER_8->value() + sb_GIER_9->value() +
sb_GIER_10->value() + sb_GIER_11->value() + sb_GIER_12->value();
if (NICK == 0)
{
lb_NICK->setEnabled(true);
}
else
{
lb_NICK->setEnabled(false);
}
if (ROLL == 0)
{
lb_ROLL->setEnabled(true);
}
else
{
lb_ROLL->setEnabled(false);
}
if (GIER == 0)
{
lb_GIER->setEnabled(true);
}
else
{
lb_GIER->setEnabled(false);
}
}
//FIXME: put this in libMK/Handler.cpp
/*
int dlg_MotorMixer::get_MotorConfig()
{
get_MotorData();
TX_Data[0] = VERSION_MIXER;
char *Name = MixerName.toLatin1().data();
int a;
for (a = 0; a < MixerName.length(); a++)
{
TX_Data[1+a] = Name[a];
}
while(a < 12)
{
TX_Data[1+a] = 0;
a++;
}
int Pos = 13;
for (int z = 0; z < 16; z++)
{
for (int y = 0; y < 4; y++)
{
TX_Data[Pos] = Parser::charToData(Motor[z][y]);
Pos++;
}
}
return Pos - 1;
}
*/
// read motor values
void dlg_MotorMixer::slot_pb_READ()
{
//send command to get mixer values
handler->read_motor_mixer();
}
//write motor values
//FIXME: put this in libMK/Handler.cpp
void dlg_MotorMixer::slot_pb_WRITE()
{
char tx_data[150];
int length = handler->get_motor_config(tx_data);
handler->write_motor_mixer(tx_data, length);
}
void dlg_MotorMixer::slot_pb_LOAD()
{
QString Filename = QFileDialog::getOpenFileName(this, tr("Mikrokopter MotorMixer laden"), o_Settings->DIR.Parameter + "", tr("MK MotorMixer(*.mkm);;Alle Dateien (*)"));
if (!Filename.isEmpty())
{
QSettings Setting(Filename, QSettings::IniFormat);
Setting.beginGroup("Info");
data->motor.mixer_name = Setting.value("Name", QString("--noname--")).toString().toAscii().data();
data->motor.mixer_version = Setting.value("Version", 0).toInt();
Setting.endGroup();
Setting.beginGroup("Gas");
for (int z = 0; z < MAXMOTOR; z++)
{
data->motor.mixer_gas[z] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt();
}
Setting.endGroup();
Setting.beginGroup("Nick");
for (int z = 0; z < MAXMOTOR; z++)
{
data->motor.mixer_nick[z] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt();
}
Setting.endGroup();
Setting.beginGroup("Roll");
for (int z = 0; z < MAXMOTOR; z++)
{
data->motor.mixer_roll[z] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt();
}
Setting.endGroup();
Setting.beginGroup("Yaw");
for (int z = 0; z < MAXMOTOR; z++)
{
data->motor.mixer_yaw[z] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt();
}
Setting.endGroup();
if (data->motor.mixer_version == VERSION_MIXER)
{
set_MotorData();
}
}
}
void dlg_MotorMixer::slot_pb_SAVE()
{
QString Filename = QFileDialog::getSaveFileName(this, tr("Mikrokopter MotorMixer speichern"), o_Settings->DIR.Parameter + "/" + le_NAME->text(), tr("MK MotorMixer(*.mkm);;Alle Dateien (*)"));
if (!Filename.isEmpty())
{
if (!(Filename.endsWith(".mkm", Qt::CaseInsensitive)))
{
Filename = Filename + QString(".mkm");
}
get_MotorData();
QSettings Setting(Filename, QSettings::IniFormat);
Setting.beginGroup("Info");
Setting.setValue("Name", data->motor.mixer_name.c_str());
Setting.setValue("Version", data->motor.mixer_version);
Setting.endGroup();
Setting.beginGroup("Gas");
for (int z = 0; z < MAXMOTOR; z++)
{
Setting.setValue(QString("Motor%1").arg(z+1), data->motor.mixer_gas[z]);
}
Setting.endGroup();
Setting.beginGroup("Nick");
for (int z = 0; z < MAXMOTOR; z++)
{
Setting.setValue(QString("Motor%1").arg(z+1), data->motor.mixer_nick[z]);
}
Setting.endGroup();
Setting.beginGroup("Roll");
for (int z = 0; z < MAXMOTOR; z++)
{
Setting.setValue(QString("Motor%1").arg(z+1), data->motor.mixer_roll[z]);
}
Setting.endGroup();
Setting.beginGroup("Yaw");
for (int z = 0; z < MAXMOTOR; z++)
{
Setting.setValue(QString("Motor%1").arg(z+1), data->motor.mixer_yaw[z]);
}
Setting.endGroup();
}
}