Subversion Repositories Projects

Rev

Rev 159 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

/***************************************************************************
 *   Copyright (C) 2008 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 <QtGui>

#include <QLineEdit>
#include <QString>
#include <QTimer>
#include <QIcon>
#include <QToolButton>
#include <QSpinBox>

#include "mktool.h"
#include "dlg_Config.h"
#include "dlg_Motortest.h"
#include "dlg_Preferences.h"
#include "../global.h"
#include "../ToolBox.h"

#include <stdlib.h>

MKTool::MKTool()
{
    setupUi(this);

    Settings = new cSettings;
//    Settings->read_Settings();
//    Settings->read_Settings_FC();

    init_Arrays();
    init_Icons();
    init_GUI();

    init_Objects();
    init_Connections();

    init_Plot();

    Ticker->start(2000);
}

void MKTool::init_GUI()
{
    setWindowTitle(QA_NAME + " v" + QA_VERSION);

#ifdef _EEEPC_
    toolBar->hide();
#endif

    resize(Settings->GUI.Size);
    move(Settings->GUI.Point);

    if (Settings->GUI.isMax)
    {
        showMaximized();
    }

    for (int a = 0; a < MaxAnalog; a++)
    {
        lb_Analog[a]->setText(Settings->Analog1.Label[a]);
    }

    for (int b = 0; b < 6; b++)
    {
        TabWidgets[b] = tab_Main->widget(b);
    }

    for (int c = 0; c < 6; c++)
    {
        if (Settings->GUI.TabViews[c] == false)
        {
            QString TabName = QString("Tab_%1").arg(c);

            for (int d = 0; d < tab_Main->count(); d++)
            {
                if (tab_Main->widget(d)->objectName() == TabName)
                {
                    tab_Main->removeTab(d);
                }
            }
        }
    }

    ac_View0->setChecked(Settings->GUI.TabViews[0]);
    ac_View1->setChecked(Settings->GUI.TabViews[1]);
    ac_View2->setChecked(Settings->GUI.TabViews[2]);
    ac_View3->setChecked(Settings->GUI.TabViews[3]);
    ac_View4->setChecked(Settings->GUI.TabViews[4]);
    ac_View5->setChecked(Settings->GUI.TabViews[5]);

    le_Port->setText(Settings->TTY.Port);

    cb_ShowMSG->setChecked(Settings->GUI.Term_Info);
    cb_ShowData->setChecked(Settings->GUI.Term_Data);
    cb_ShowAlways->setChecked(Settings->GUI.Term_Always);
}

void MKTool::init_Objects()
{
    // QTimer-Instanzen
    Ticker  = new QTimer(this);

    // Seriell-Port
    serialPort = new ManageSerialPort;

    // QFile-Instanz (Log-Datei)
    CSVFile = new QFile("");

    AllowSend = true;
}

void MKTool::init_Connections()
{
    // Seriel-Port Empfang
    connect(serialPort, SIGNAL(newDataReceived(const QByteArray &)), this, SLOT(slot_newDataReceived(const QByteArray &)));

    // Buttons und Menüpunkte / Toolbar
    connect(pb_Load,   SIGNAL(clicked()), this, SLOT(slot_LoadParameter()));
    connect(pb_Save,   SIGNAL(clicked()), this, SLOT(slot_SaveParameter()));
    connect(pb_Read,   SIGNAL(clicked()), this, SLOT(slot_GetParameter()));
    connect(pb_Write,  SIGNAL(clicked()), this, SLOT(slot_SetParameter()));

    connect(pb_LCDup,   SIGNAL(clicked()), this, SLOT(slot_LCD_UP()));
    connect(pb_LCDdown, SIGNAL(clicked()), this, SLOT(slot_LCD_DOWN()));

    // Actions
    connect(ac_Config,       SIGNAL(triggered()), this, SLOT(slot_ac_Config()));
    connect(ac_Preferences,  SIGNAL(triggered()), this, SLOT(slot_ac_Preferences()));

    connect(ac_Motortest,    SIGNAL(triggered()), this, SLOT(slot_ac_Motortest()));
    connect(ac_StartPlotter, SIGNAL(triggered()), this, SLOT(slot_ac_StartPlotter()));
    connect(ac_MehrDaten,    SIGNAL(triggered()), this, SLOT(slot_ac_MehrDaten()));
    connect(ac_About,        SIGNAL(triggered()), this, SLOT(slot_ac_About()));
    connect(ac_GetLabels,    SIGNAL(triggered()), this, SLOT(slot_ac_GetLabels()));

    // Tabs ein & ausblenden
    connect(ac_View0,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
    connect(ac_View1,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
    connect(ac_View2,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
    connect(ac_View3,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
    connect(ac_View4,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
    connect(ac_View5,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));

//    connect(pb_Update,  SIGNAL(clicked()), this, SLOT(slot_pb_Update()));

    connect(ac_ConnectTTY, SIGNAL(triggered()), this, SLOT(slot_OpenPort()));
    connect(ac_RecordCSV,  SIGNAL(triggered()), this, SLOT(slot_RecordCSV()));

    connect(ac_LogDir,       SIGNAL(triggered()), this, SLOT(slot_SetLogDir()));
    connect(ac_ParameterDir, SIGNAL(triggered()), this, SLOT(slot_SetParDir()));

    // Timer-Events
    connect(Ticker,   SIGNAL(timeout()),       SLOT(slot_Ticker()));

    // Seitenwechsel :)
    connect(tab_Main, SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int)));
    connect(tab_Par,  SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int)));

    // Parameterevents
    connect(tb_9_6,  SIGNAL(clicked()), this, SLOT(slot_tbUp()));
    connect(tb_9_7,  SIGNAL(clicked()), this, SLOT(slot_tbDown()));
    connect(tb_9_8,  SIGNAL(clicked()), this, SLOT(slot_tbLeft()));
    connect(tb_9_9,  SIGNAL(clicked()), this, SLOT(slot_tbRight()));

    connect(J16_0,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J16_1,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J16_2,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J16_3,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J16_4,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J16_5,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J16_6,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J16_7,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));

    connect(J17_0,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J17_1,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J17_2,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J17_3,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J17_4,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J17_5,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J17_6,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));
    connect(J17_7,  SIGNAL(clicked()), this, SLOT(slot_LEDtoValue()));

    connect(sb_11_1, SIGNAL(valueChanged(int)), this, SLOT(slot_ValuetoLED16(int)));
    connect(sb_11_3, SIGNAL(valueChanged(int)), this, SLOT(slot_ValuetoLED17(int)));

    // Plotter
    connect(scroll_plot, SIGNAL(valueChanged(int)), this, SLOT(slot_ScrollPlot(int)));

    // About-QT Dialog einfügen
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
}

void MKTool::init_Arrays()
{
    lb_Analog[0]  = lb_A_0;
    lb_Analog[1]  = lb_A_1;
    lb_Analog[2]  = lb_A_2;
    lb_Analog[3]  = lb_A_3;
    lb_Analog[4]  = lb_A_4;
    lb_Analog[5]  = lb_A_5;
    lb_Analog[6]  = lb_A_6;
    lb_Analog[7]  = lb_A_7;
    lb_Analog[8]  = lb_A_8;
    lb_Analog[9]  = lb_A_9;
    lb_Analog[10] = lb_A_10;
    lb_Analog[11] = lb_A_11;
    lb_Analog[12] = lb_A_12;
    lb_Analog[13] = lb_A_13;
    lb_Analog[14] = lb_A_14;
    lb_Analog[15] = lb_A_15;
    lb_Analog[16] = lb_A_16;
    lb_Analog[17] = lb_A_17;
    lb_Analog[18] = lb_A_18;
    lb_Analog[19] = lb_A_19;
    lb_Analog[20] = lb_A_20;
    lb_Analog[21] = lb_A_21;
    lb_Analog[22] = lb_A_22;
    lb_Analog[23] = lb_A_23;
    lb_Analog[24] = lb_A_24;
    lb_Analog[25] = lb_A_25;
    lb_Analog[26] = lb_A_26;
    lb_Analog[27] = lb_A_27;
    lb_Analog[28] = lb_A_28;
    lb_Analog[29] = lb_A_29;
    lb_Analog[30] = lb_A_30;
    lb_Analog[31] = lb_A_31;
}

void MKTool::init_Plot()
{
    NextPlot = 0;

    qwtPlot->setCanvasBackground(QColor(QRgb(0x00000000)));

    qwtPlot->insertLegend(new QwtLegend(), QwtPlot::RightLegend);

    QwtPlotGrid *Grid = new QwtPlotGrid();
    Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));


    Grid->attach(qwtPlot);

    qwtPlot->setAxisScale(QwtPlot::xBottom,0,PlotWide,0);

    for (int a = 0; a < MaxAnalog; a++)
    {
        Plot[a] = new QwtPlotCurve(Settings->Analog1.Label[a]);
        Plot[a]->setPen(QPen(QColor(Def_Colors[a])));
//        Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased);

        if (Settings->Analog1.PlotView[a])
            Plot[a]->attach(qwtPlot);
    }
    qwtPlot->replot();
}

void MKTool::init_Icons()
{
    Icons[0].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledred.png")), QIcon::Normal, QIcon::Off);
    Icons[1].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledyellow.png")), QIcon::Normal, QIcon::Off);
    Icons[3].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledyellow.png")), QIcon::Normal, QIcon::Off);
    Icons[4].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledoff.png")), QIcon::Normal, QIcon::Off);

    Icons[5].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/application-exit.png")), QIcon::Normal, QIcon::Off);
    Icons[6].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/media-playback-stop.png")), QIcon::Normal, QIcon::Off);
    Icons[7].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/media-record.png")), QIcon::Normal, QIcon::Off);
    Icons[8].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/network-connect.png")), QIcon::Normal, QIcon::Off);
    Icons[9].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/network-disconnect.png")), QIcon::Normal, QIcon::Off);
    Icons[10].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/utilities-system-monitor.png")), QIcon::Normal, QIcon::Off);

    Icons[20].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-up-double.png")), QIcon::Normal, QIcon::Off);
    Icons[21].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-up.png")), QIcon::Normal, QIcon::Off);
    Icons[22].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-down-double.png")), QIcon::Normal, QIcon::Off);
    Icons[23].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-down.png")), QIcon::Normal, QIcon::Off);
    Icons[24].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-left-double.png")), QIcon::Normal, QIcon::Off);
    Icons[25].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-left.png")), QIcon::Normal, QIcon::Off);
    Icons[26].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-right-double.png")), QIcon::Normal, QIcon::Off);
    Icons[27].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-right.png")), QIcon::Normal, QIcon::Off);
}


// Ticker-Event
///////////////
void MKTool::slot_Ticker()
{
    if (TickerDiv)
        TickerDiv = false;
    else
        TickerDiv = true;

    for (int a = 0; a < MaxTickerEvents; a++)
    {
        if (TickerEvent[a] == true)
        {
            switch(a)
            {
                case 0 :
                    if (TickerDiv)
                    {
                        QByteArray Temp(LastSend.toUtf8());
                        serialPort->sendData(Temp);
                    }
                break;
                case 1 :
                    TX_Data[0] = 0;
                    send_Data('p', ADDRESS_FC, TX_Data, 0, false);
                break;
                case 2 :
                    TX_Data[0] = LCD_Page;
                    TX_Data[1] = 0;
                    send_Data('l', ADDRESS_ALL, TX_Data, 1, true);
                break;
            }
        }
    }
}


// Slots der Actions (Menüpunkte, Buttons)
//////////////////////////////////////////
void MKTool::slot_ac_Motortest()
{
    dlg_Motortest *f_Motortest = new dlg_Motortest(this);

    connect(f_Motortest, SIGNAL(updateMotor(int, int, int, int)), this, SLOT(slot_Motortest(int, int, int, int)));

    if (f_Motortest->exec()==QDialog::Accepted)
    {
    }

    disconnect(f_Motortest, 0,0,0);
    slot_Motortest(0,0,0,0);
}

void MKTool::slot_Motortest(int Motor1, int Motor2, int Motor3, int Motor4)
{
    TX_Data[0] = Motor1;
    TX_Data[1] = Motor2;
    TX_Data[2] = Motor3;
    TX_Data[3] = Motor4;
    send_Data('t', ADDRESS_FC, TX_Data, 4, false);
}

void MKTool::slot_ac_Config()
{
    set_Analog Old_Analog1;

    Old_Analog1 = Settings->Analog1;

    dlg_Config *f_Config = new dlg_Config(this);
    f_Config->set_Settings(Settings, Mode.ID);

    if (f_Config->exec()==QDialog::Accepted)
    {
        Settings = f_Config->get_Settings();
        Settings->write_Settings_Analog(Mode.ID);

        for (int a = 0; a < MaxAnalog; a++)
        {
            if (Old_Analog1.PlotView[a] == Settings->Analog1.PlotView[a])
                continue;
            else
            {
                config_Plot();
                break;
            }
        }

        if (CSVFile->isOpen())
        {
            for (int a = 0; a < MaxAnalog; a++)
            {
                if (Old_Analog1.LogView[a] == Settings->Analog1.LogView[a])
                    continue;
                else
                {
                    slot_RecordCSV();
                    slot_RecordCSV();
                    break;
                }
            }
        }

    }
}

void MKTool::slot_ac_Preferences()
{
    dlg_Preferences *f_Preferences = new dlg_Preferences(this);

    if (f_Preferences->exec()==QDialog::Accepted)
    {

    }
}

void MKTool::slot_ac_StartPlotter()
{
    if (ac_StartPlotter->isChecked())
    {
        ac_StartPlotter->setText("Stop Plotter");
        pb_StartPlotter->setText("Stop Plotter");
    }
    else
    {
        ac_StartPlotter->setText("Start Plotter");
        pb_StartPlotter->setText("Start Plotter");
    }
}

void MKTool::slot_ac_View()
{
    int Aktive;

    QAction *Action = (QAction*)sender();

    if (Action->objectName() == QString("ac_View0"))
        Aktive = 0;
    if (Action->objectName() == QString("ac_View1"))
        Aktive = 1;
    if (Action->objectName() == QString("ac_View2"))
        Aktive = 2;
    if (Action->objectName() == QString("ac_View3"))
        Aktive = 3;
    if (Action->objectName() == QString("ac_View4"))
        Aktive = 4;
    if (Action->objectName() == QString("ac_View5"))
        Aktive = 5;

    QString TabName = QString("Tab_%1").arg(Aktive);

    if (!Action->isChecked())
    {
        for (int a = 0; a < tab_Main->count(); a++)
        {
            if (tab_Main->widget(a)->objectName() == TabName)
            {
                tab_Main->removeTab(a);
            }
        }

//        Action->setChecked(false);
    }
    else
    {
//        Action->setChecked(true);
        tab_Main->insertTab(Aktive, TabWidgets[Aktive], Action->text());
    }
}

void MKTool::slot_ac_MehrDaten() // DONE 0.71g
{
    if (ac_MehrDaten->isChecked())
    {
        TX_Data[0] = 10;
        send_Data('d', ADDRESS_ALL, TX_Data, 1, false);    }
    else
    {
        TX_Data[0] = 50;
        send_Data('d', ADDRESS_ALL, TX_Data, 1, false);    }
}

void MKTool::slot_ac_About()
{
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
}

void MKTool::slot_ac_GetLabels() // DONE 0.71g
{
    TX_Data[0] = 0;
    send_Data('a', ADDRESS_ALL, TX_Data, 1, false);
}


//  Daten-Plotter
/////////////////
void MKTool::update_Plot()
{
    for (int a = 0; a < MaxAnalog; a++)
    {
        Plot[a]->setData(aID,aData[a],NextPlot - 1);
    }

    if ((NextPlot > PlotWide))
    {
        scroll_plot->setMaximum(NextPlot - PlotWide);
    }

    if ((scroll_plot->value() == NextPlot - (PlotWide + 1)))
    {
        qwtPlot->setAxisScale(QwtPlot::xBottom,NextPlot - PlotWide,NextPlot,0);
        scroll_plot->setValue(NextPlot - PlotWide);
    }

    qwtPlot->replot();
}

void MKTool::config_Plot()
{
    for (int a = 0; a < MaxAnalog; a++)
    {
        Plot[a]->detach();
        Plot[a]->setPen(QPen(QColor(Def_Colors[a])));

        if (Settings->Analog1.PlotView[a])
        {
            Plot[a]->setTitle(Settings->Analog1.Label[a]);
            Plot[a]->attach(qwtPlot);
        }
    }
}

void MKTool::slot_ScrollPlot(int Pos)
{
    qwtPlot->setAxisScale(QwtPlot::xBottom,Pos,Pos + PlotWide,0);
    qwtPlot->replot();
}


// Firmeware-Update
///////////////////
void MKTool::slot_pb_Update()
{
    qDebug("Update");

    if (serialPort->isOpen())
    {
        slot_OpenPort();
    }

    Update = new QProcess();

    const QString Programm = "avrdude -p m644 -P /dev/ttyS0 -c butterfly -b 57600 -U flash:w:Flight-Ctrl_MEGA644_V0_71f.hex";
    const QStringList Argumente = (QStringList() << "-?");

    te_Shell->setText(""); // Ausgabefenster säubern
    Update->start(Programm); // Programmaufruf
//   Update.waitForFinished(); // auf Rückmeldung warten
//   Update.close(); // Kanal schließen
     connect(Update, SIGNAL(readyReadStandardOutput()), this, SLOT(slot_UpdateShell()) );
}

void MKTool::slot_UpdateShell()
{
    QByteArray Output;
//   te_Shell->setText(""); // Ausgabefenster säubern
    Output = Update->readAllStandardOutput(); // Shellausgabe an Variable

    te_Shell->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
    te_Shell->insertPlainText(QString::fromUtf8(Output));

    te_Shell->setText(QString::fromUtf8(Output)); // ...und endlich: Ausgabe im QLabel
    qDebug("Shell");
}

// Configuration -> Verzeichnisse
/////////////////////////////////
void MKTool::slot_SetLogDir()
{
    QString directory = QFileDialog::getExistingDirectory(this, "Verzeichniss für CSV-Logdateien", Settings->DIR.Logging, QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly);

    if ((!directory.isEmpty()) && (Settings->DIR.Logging != directory))
    {
        Settings->DIR.Logging = directory;
        Settings->write_Settings();
    }
}

void MKTool::slot_SetParDir()
{
    QString directory = QFileDialog::getExistingDirectory(this, "Verzeichniss für Parameter-Dateien", Settings->DIR.Parameter, QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly);

    if ((!directory.isEmpty()) && (Settings->DIR.Parameter != directory))
    {
        Settings->DIR.Parameter = directory;
        Settings->write_Settings();
    }

}


// Settings-Bereich
///////////////////

void MKTool::slot_LEDtoValue()
{
    QToolButton *ToolButton = (QToolButton*)sender();
    if (ToolButton->text() == QString("0"))
    {
        set_LED(ToolButton, true);
        sb_11_1->setValue(sb_11_1->value() + ToolButton->toolTip().toInt());
    }
    else if (ToolButton->text() == QString("1"))
    {
        set_LED(ToolButton);
        sb_11_1->setValue(sb_11_1->value() - ToolButton->toolTip().toInt());
    }
    else if (ToolButton->text() == QString("00"))
    {
        set_LED(ToolButton, true);
        sb_11_3->setValue(sb_11_3->value() + ToolButton->toolTip().toInt());
    }
    else if (ToolButton->text() == QString("11"))
    {
        set_LED(ToolButton);
        sb_11_3->setValue(sb_11_3->value() - ToolButton->toolTip().toInt());
    }
}

void MKTool::slot_ValuetoLED16(int Wert)
{
//    QSpinBox *SpinBox = (QSpinBox*)sender();

//    int Wert = SpinBox->value();

    set_LED(J16_0);
    set_LED(J16_1);
    set_LED(J16_2);
    set_LED(J16_3);
    set_LED(J16_4);
    set_LED(J16_5);
    set_LED(J16_6);
    set_LED(J16_7);

    for (int a = 0; a < 8; a++)
    {
        if (Wert > 127)
        {
            set_LED(J16_0, true);
            Wert = Wert - 128;
        }
        if (Wert > 63)
        {
            set_LED(J16_1, true);
            Wert = Wert - 64;
        }
        if (Wert > 31)
        {
            set_LED(J16_2, true);
            Wert = Wert - 32;
        }
        if (Wert > 15)
        {
            set_LED(J16_3, true);
            Wert = Wert - 16;
        }
        if (Wert > 7)
        {
            set_LED(J16_4, true);
            Wert = Wert - 8;
        }
        if (Wert > 3)
        {
            set_LED(J16_5, true);
            Wert = Wert - 4;
        }
        if (Wert > 1)
        {
            set_LED(J16_6, true);
            Wert = Wert - 2;
        }
        if (Wert > 0)
        {
            set_LED(J16_7, true);
            Wert = Wert - 1;
        }
    }
}

void MKTool::slot_ValuetoLED17(int Wert)
{
//    QSpinBox *SpinBox = (QSpinBox*)sender();

//    int Wert = SpinBox->value();

    set_LED(J17_0);
    set_LED(J17_1);
    set_LED(J17_2);
    set_LED(J17_3);
    set_LED(J17_4);
    set_LED(J17_5);
    set_LED(J17_6);
    set_LED(J17_7);

    for (int a = 0; a < 8; a++)
    {
        if (Wert > 127)
        {
            set_LED(J17_0, true);
            Wert = Wert - 128;
        }
        if (Wert > 63)
        {
            set_LED(J17_1, true);
            Wert = Wert - 64;
        }
        if (Wert > 31)
        {
            set_LED(J17_2, true);
            Wert = Wert - 32;
        }
        if (Wert > 15)
        {
            set_LED(J17_3, true);
            Wert = Wert - 16;
        }
        if (Wert > 7)
        {
            set_LED(J17_4, true);
            Wert = Wert - 8;
        }
        if (Wert > 3)
        {
            set_LED(J17_5, true);
            Wert = Wert - 4;
        }
        if (Wert > 1)
        {
            set_LED(J17_6, true);
            Wert = Wert - 2;
        }
        if (Wert > 0)
        {
            set_LED(J17_7, true);
            Wert = Wert - 1;
        }
    }
}

void MKTool::set_LED(QToolButton *ToolButton, bool On)
{
    if (ToolButton->text() == QString("0") && On)
    {
        ToolButton->setIcon(Icons[0]);
        ToolButton->setText("1");
    }
    else if (ToolButton->text() == QString("1") && !On)
    {
        ToolButton->setIcon(Icons[4]);
        ToolButton->setText("0");
    }
    else if (ToolButton->text() == QString("00") && On)
    {
        ToolButton->setIcon(Icons[0]);
        ToolButton->setText("11");
    }
    else if (ToolButton->text() == QString("11") && !On)
    {
        ToolButton->setIcon(Icons[4]);
        ToolButton->setText("00");
    }
}

void MKTool::slot_tbUp()
{
    if (tb_9_6->text() == QString("0"))
    {
        tb_9_6->setIcon(Icons[20]);
        tb_9_6->setText("1");
    }
    else
    {
        tb_9_6->setIcon(Icons[21]);
        tb_9_6->setText("0");
    }
}

void MKTool::slot_tbDown()
{
    if (tb_9_7->text() == QString("0"))
    {
        tb_9_7->setIcon(Icons[22]);
        tb_9_7->setText("1");
    }
    else
    {
        tb_9_7->setIcon(Icons[23]);
        tb_9_7->setText("0");
    }
}

void MKTool::slot_tbLeft()
{
    if (tb_9_8->text() == QString("0"))
    {
        tb_9_8->setIcon(Icons[24]);
        tb_9_8->setText("1");
    }
    else
    {
        tb_9_8->setIcon(Icons[25]);
        tb_9_8->setText("0");
    }
}

void MKTool::slot_tbRight()
{
    if (tb_9_9->text() == QString("0"))
    {
        tb_9_9->setIcon(Icons[26]);
        tb_9_9->setText("1");
    }
    else
    {
        tb_9_9->setIcon(Icons[27]);
        tb_9_9->setText("0");
    }
}

QComboBox *MKTool::setCombo(QComboBox *Combo, int Set, int Wert)
{
    if (ParameterSet[Set][Wert] <= 250)
    {
        Combo->setItemText(4, QString("%1").arg(ParameterSet[Set][Wert]));
        Combo->setCurrentIndex(4);
    }
    else
    {
        Combo->setCurrentIndex(ParameterSet[Set][Wert] - 251);
    }
    return Combo;
}

int MKTool::get_Value(QComboBox *Combo)
{
    if (Combo->currentText() == QString("Poti 1"))
        return 251;
    if (Combo->currentText() == QString("Poti 2"))
        return 252;
    if (Combo->currentText() == QString("Poti 3"))
        return 253;
    if (Combo->currentText() == QString("Poti 4"))
        return 254;
    return Combo->currentText().toInt();
}

void MKTool::store_ParameterSet(int Set) // DONE 0.71g
{
    char *Name = le_SetName->text().toLatin1().data();

    int a;

    for (a = 0; a < le_SetName->text().length(); a++)
    {
        ParameterSet[Set][P_NAME+a] = Name[a];
    }

    while(a < 12)
    {
        ParameterSet[Set][P_NAME+a] = 0;
        a++;
    }

    // Seite 1
    ParameterSet[Set][P_GLOBAL_CONF] = 0;

    if (cb_1_1->isChecked())
        ParameterSet[Set][P_GLOBAL_CONF] = ParameterSet[Set][P_GLOBAL_CONF] | 0x01;
    if (cb_1_2->isChecked())
        ParameterSet[Set][P_GLOBAL_CONF] = ParameterSet[Set][P_GLOBAL_CONF] | 0x02;
    if (cb_1_3->isChecked())
        ParameterSet[Set][P_GLOBAL_CONF] = ParameterSet[Set][P_GLOBAL_CONF] | 0x04;
    if (cb_1_4->isChecked())
        ParameterSet[Set][P_GLOBAL_CONF] = ParameterSet[Set][P_GLOBAL_CONF] | 0x08;
    if (cb_1_5->isChecked())
        ParameterSet[Set][P_GLOBAL_CONF] = ParameterSet[Set][P_GLOBAL_CONF] | 0x10;
    if (cb_1_6->isChecked())
        ParameterSet[Set][P_GLOBAL_CONF] = ParameterSet[Set][P_GLOBAL_CONF] | 0x20;
    if (cb_1_7->isChecked())
        ParameterSet[Set][P_GLOBAL_CONF] = ParameterSet[Set][P_GLOBAL_CONF] | 0x40;
    if (cb_1_8->isChecked())
        ParameterSet[Set][P_GLOBAL_CONF] = ParameterSet[Set][P_GLOBAL_CONF] | 0x80;

    // Seite 2
    ParameterSet[Set][P_KANAL_NICK]  = sb_2_1->value();
    ParameterSet[Set][P_KANAL_ROLL]  = sb_2_2->value();
    ParameterSet[Set][P_KANAL_GAS]   = sb_2_3->value();
    ParameterSet[Set][P_KANAL_GIER]  = sb_2_4->value();
    ParameterSet[Set][P_KANAL_POTI1] = sb_2_5->value();
    ParameterSet[Set][P_KANAL_POTI2] = sb_2_6->value();
    ParameterSet[Set][P_KANAL_POTI3] = sb_2_7->value();
    ParameterSet[Set][P_KANAL_POTI4] = sb_2_8->value();

    // Seite 3
    ParameterSet[Set][P_STICK_P]  = sb_3_1->value();
    ParameterSet[Set][P_STICK_D]  = sb_3_2->value();
    ParameterSet[Set][P_GIER_P]   = get_Value(cb_3_3);
    ParameterSet[Set][P_EXTERNAL] = get_Value(cb_3_4);

    // Seite 4
    ParameterSet[Set][P_MAXHOEHE]   = get_Value(cb_4_1);
    ParameterSet[Set][P_MIN_GAS]    = sb_4_2->value();
    ParameterSet[Set][P_HOEHE_P]    = get_Value(cb_4_3);
    ParameterSet[Set][P_DRUCK_D]    = get_Value(cb_4_4);
    ParameterSet[Set][P_HOEHE_ACC]  = get_Value(cb_4_5);
    ParameterSet[Set][P_HOEHE_GAIN] = sb_4_6->value();

    // Seite 5
    ParameterSet[Set][P_GYRO_P]          = get_Value(cb_5_1);
    ParameterSet[Set][P_GYRO_I]          = get_Value(cb_5_2);
    ParameterSet[Set][P_DYNAMIC_STAB]    = get_Value(cb_5_3);
    ParameterSet[Set][P_GYRO_ACC_FAKTOR] = sb_5_4->value();
    ParameterSet[Set][P_GYRO_ACC_ABGL]   = sb_5_5->value();
    ParameterSet[Set][P_FAKTOR_I]        = get_Value(cb_5_6);
    ParameterSet[Set][P_DRIFT_KOMP]      = sb_5_7->value();

    // Seite 6
    ParameterSet[Set][P_SERVO_NICK_CONT]  = get_Value(cb_6_1);
    ParameterSet[Set][P_SERVO_NICK_COMP]  = sb_6_2->value();
    ParameterSet[Set][P_SERVO_NICK_MIN]   = sb_6_3->value();
    ParameterSet[Set][P_SERVO_NICK_MAX]   = sb_6_4->value();
    ParameterSet[Set][P_SERVO_NICK_REFR]  = sb_6_5->value();
    ParameterSet[Set][P_SERVO_NICK_COMPI] = cb_6_6->isChecked();

    // Seite 7
    ParameterSet[Set][P_GAS_MIN]         = sb_7_1->value();
    ParameterSet[Set][P_GAS_MAX]         = sb_7_2->value();
    ParameterSet[Set][P_KOMPASS_WIRKUNG] = get_Value(cb_7_3);
    ParameterSet[Set][P_UNTERSPANNUNG]   = sb_7_4->value();
    ParameterSet[Set][P_NOTGASZEIT]      = sb_7_5->value();
    ParameterSet[Set][P_NOTGAS]          = sb_7_6->value();

    // Seite 8
    ParameterSet[Set][P_ACHS_KOPPLUNG]  = get_Value(cb_8_1);
    ParameterSet[Set][P_ACHS_GKOPPLUNG] = get_Value(cb_8_2);

    // Seite 9
    ParameterSet[Set][P_LOOP_CONFIG] = 0;
    if (tb_9_6->text() == QString("1"))
        ParameterSet[Set][P_LOOP_CONFIG] = ParameterSet[Set][P_LOOP_CONFIG] | 0x01;
    if (tb_9_7->text() == QString("1"))
        ParameterSet[Set][P_LOOP_CONFIG] = ParameterSet[Set][P_LOOP_CONFIG] | 0x02;
    if (tb_9_8->text() == QString("1"))
        ParameterSet[Set][P_LOOP_CONFIG] = ParameterSet[Set][P_LOOP_CONFIG] | 0x04;
    if (tb_9_9->text() == QString("1"))
        ParameterSet[Set][P_LOOP_CONFIG] = ParameterSet[Set][P_LOOP_CONFIG] | 0x08;
    if (cb_4_7->isChecked())
        ParameterSet[Set][P_LOOP_CONFIG] = ParameterSet[Set][P_LOOP_CONFIG] | 0x10;

    ParameterSet[Set][P_LOOP_GAS_LIMIT] = get_Value(cb_9_1);
    ParameterSet[Set][P_LOOP_THRESHOLD] = sb_9_2->value();
    ParameterSet[Set][P_WINKEL_NICK]    = sb_9_3->value();
    ParameterSet[Set][P_LOOP_HYSTERESE] = sb_9_4->value();
    ParameterSet[Set][P_WINKEL_ROLL]    = sb_9_5->value();

    // Seite 10
    ParameterSet[Set][P_USER_1] = get_Value(cb_10_1);
    ParameterSet[Set][P_USER_2] = get_Value(cb_10_2);
    ParameterSet[Set][P_USER_3] = get_Value(cb_10_3);
    ParameterSet[Set][P_USER_4] = get_Value(cb_10_4);
    ParameterSet[Set][P_USER_5] = get_Value(cb_10_5);
    ParameterSet[Set][P_USER_6] = get_Value(cb_10_6);
    ParameterSet[Set][P_USER_7] = get_Value(cb_10_7);
    ParameterSet[Set][P_USER_8] = get_Value(cb_10_8);

    // Seite 11
    ParameterSet[Set][P_J16_BITMASK] = sb_11_1->value();
    ParameterSet[Set][P_J16_TIMING]  = get_Value(cb_11_2);
    ParameterSet[Set][P_J17_BITMASK] = sb_11_3->value();
    ParameterSet[Set][P_J17_TIMING]  = get_Value(cb_11_4);

    // Seite 12
    ParameterSet[Set][P_NAV_GPS_MODE]   = get_Value(cb_12_1);
    ParameterSet[Set][P_NAV_GPS_GAIN]   = get_Value(cb_12_2);
    ParameterSet[Set][P_NAV_STICK_THRE] = sb_12_3->value();
    ParameterSet[Set][P_NAV_GPS_MIN]    = sb_12_4->value();
    ParameterSet[Set][P_NAV_GPS_P]      = get_Value(cb_12_5);
    ParameterSet[Set][P_NAV_GPS_I]      = get_Value(cb_12_6);
    ParameterSet[Set][P_NAV_GPS_D]      = get_Value(cb_12_7);
    ParameterSet[Set][P_NAV_GPS_ACC]    = get_Value(cb_12_8);

    //Seite 13
    ParameterSet[Set][P_NAV_WIND_CORR]  = get_Value(cb_13_1);
    ParameterSet[Set][P_NAV_SPEED_COMP] = get_Value(cb_13_2);
    ParameterSet[Set][P_NAV_RADIUS]     = get_Value(cb_13_3);
}

void MKTool::slot_SaveParameter() // DONE 0.71g
{
    int Set = sb_Set->value() + 5;

    QString Filename = QFileDialog::getSaveFileName(this, "Mikrokopter Parameter speichern", Settings->DIR.Parameter + le_SetName->text(), "Mikrokopter Parameter(*.mkp);;Alle Dateien (*)");

    if (!Filename.isEmpty())
    {
        if (!(Filename.endsWith(".mkp", Qt::CaseInsensitive)))
        {
            Filename = Filename + QString(".mkp");
        }
        store_ParameterSet(Set);
        QSettings Setting(Filename, QSettings::IniFormat);

        Setting.beginGroup("Setup");
            Setting.setValue("Name",         le_SetName->text());
            Setting.setValue("GlobalConfig", ParameterSet[Set][P_GLOBAL_CONF]);
        Setting.endGroup();

        Setting.beginGroup("Channels");
            Setting.setValue("Nick",   ParameterSet[Set][P_KANAL_NICK]);
            Setting.setValue("Roll",   ParameterSet[Set][P_KANAL_ROLL]);
            Setting.setValue("Gas",    ParameterSet[Set][P_KANAL_GAS]);
            Setting.setValue("Gier",   ParameterSet[Set][P_KANAL_GIER]);
            Setting.setValue("Poti_1", ParameterSet[Set][P_KANAL_POTI1]);
            Setting.setValue("Poti_2", ParameterSet[Set][P_KANAL_POTI2]);
            Setting.setValue("Poti_3", ParameterSet[Set][P_KANAL_POTI3]);
            Setting.setValue("Poti_4", ParameterSet[Set][P_KANAL_POTI4]);
        Setting.endGroup();

        Setting.beginGroup("Stick");
            Setting.setValue("Nick_Roll-P",     ParameterSet[Set][P_STICK_P]);
            Setting.setValue("Nick_Roll-D",     ParameterSet[Set][P_STICK_D]);
            Setting.setValue("Gier-P",          ParameterSet[Set][P_GIER_P]);
            Setting.setValue("ExternalControl", ParameterSet[Set][P_EXTERNAL]);
        Setting.endGroup();

        Setting.beginGroup("Altitude");
            Setting.setValue("Setpoint",     ParameterSet[Set][P_MAXHOEHE]);
            Setting.setValue("MinGas",       ParameterSet[Set][P_MIN_GAS]);
            Setting.setValue("P",            ParameterSet[Set][P_HOEHE_P]);
            Setting.setValue("Barometric-D", ParameterSet[Set][P_DRUCK_D]);
            Setting.setValue("Z-ACC-Effect", ParameterSet[Set][P_HOEHE_ACC]);
            Setting.setValue("Gain",         ParameterSet[Set][P_HOEHE_GAIN]);
        Setting.endGroup();

        Setting.beginGroup("Gyro");
            Setting.setValue("P",                     ParameterSet[Set][P_GYRO_P]);
            Setting.setValue("I",                     ParameterSet[Set][P_GYRO_I]);
            Setting.setValue("DynamicStability",      ParameterSet[Set][P_DYNAMIC_STAB]);
            Setting.setValue("ACC_Gyro-Factor",       ParameterSet[Set][P_GYRO_ACC_FAKTOR]);
            Setting.setValue("ACC_Gyro-Compensation", ParameterSet[Set][P_GYRO_ACC_ABGL]);
            Setting.setValue("DriftCompensation",     ParameterSet[Set][P_DRIFT_KOMP]);
            Setting.setValue("Main-I",                ParameterSet[Set][P_FAKTOR_I]);
        Setting.endGroup();

        Setting.beginGroup("Camera");
            Setting.setValue("ServoNickControl",      ParameterSet[Set][P_SERVO_NICK_CONT]);
            Setting.setValue("ServoNickCompensation", ParameterSet[Set][P_SERVO_NICK_COMP]);
            Setting.setValue("ServoNickInvert",       ParameterSet[Set][P_SERVO_NICK_COMPI]);
            Setting.setValue("ServoNickMin",          ParameterSet[Set][P_SERVO_NICK_MIN]);
            Setting.setValue("ServoNickMax",          ParameterSet[Set][P_SERVO_NICK_MAX]);
            Setting.setValue("ServoNickRefreshRate",  ParameterSet[Set][P_SERVO_NICK_REFR]);
        Setting.endGroup();

        Setting.beginGroup("Others");
            Setting.setValue("MinGas",         ParameterSet[Set][P_GAS_MIN]);
            Setting.setValue("MaxGas",         ParameterSet[Set][P_GAS_MAX]);
            Setting.setValue("Compass-Effect", ParameterSet[Set][P_KOMPASS_WIRKUNG]);
            Setting.setValue("UnderVoltage",   ParameterSet[Set][P_UNTERSPANNUNG]);
            Setting.setValue("NotGas",         ParameterSet[Set][P_NOTGAS]);
            Setting.setValue("NotGasTime",     ParameterSet[Set][P_NOTGASZEIT]);
        Setting.endGroup();

        Setting.beginGroup("Coupling");
            Setting.setValue("YawPosFeedback", ParameterSet[Set][P_ACHS_KOPPLUNG]);
            Setting.setValue("YawNegFeedback", ParameterSet[Set][P_ACHS_GKOPPLUNG]);
        Setting.endGroup();

        Setting.beginGroup("Loop");
            Setting.setValue("Config", ParameterSet[Set][P_LOOP_CONFIG]);
            Setting.setValue("GasLimit", ParameterSet[Set][P_LOOP_GAS_LIMIT]);
            Setting.setValue("StickThreshold", ParameterSet[Set][P_LOOP_THRESHOLD]);
            Setting.setValue("LoopHysteresis", ParameterSet[Set][P_LOOP_HYSTERESE]);
            Setting.setValue("TurnOverNick", ParameterSet[Set][P_WINKEL_NICK]);
            Setting.setValue("TurnOverRoll", ParameterSet[Set][P_WINKEL_ROLL]);
        Setting.endGroup();

        Setting.beginGroup("User");
             Setting.setValue("Parameter_1", ParameterSet[Set][P_USER_1]);
             Setting.setValue("Parameter_2", ParameterSet[Set][P_USER_2]);
             Setting.setValue("Parameter_3", ParameterSet[Set][P_USER_3]);
             Setting.setValue("Parameter_4", ParameterSet[Set][P_USER_4]);
             Setting.setValue("Parameter_5", ParameterSet[Set][P_USER_5]);
             Setting.setValue("Parameter_6", ParameterSet[Set][P_USER_6]);
             Setting.setValue("Parameter_7", ParameterSet[Set][P_USER_7]);
             Setting.setValue("Parameter_8", ParameterSet[Set][P_USER_8]);
        Setting.endGroup();

        Setting.beginGroup("Output");
            Setting.setValue("J16_Bitmask", ParameterSet[Set][P_J16_BITMASK]);
            Setting.setValue("J16_Timing",  ParameterSet[Set][P_J16_TIMING]);
            Setting.setValue("J17_Bitmask", ParameterSet[Set][P_J17_BITMASK]);
            Setting.setValue("J17_Timing",  ParameterSet[Set][P_J17_TIMING]);
        Setting.endGroup();

        Setting.beginGroup("NaviCtrl");
            Setting.setValue("GPS_ModeControl",       ParameterSet[Set][P_NAV_GPS_MODE]);
            Setting.setValue("GPS_Gain",              ParameterSet[Set][P_NAV_GPS_GAIN]);
            Setting.setValue("GPS_P",                 ParameterSet[Set][P_NAV_GPS_P]);
            Setting.setValue("GPS_I",                 ParameterSet[Set][P_NAV_GPS_I]);
            Setting.setValue("GPS_D",                 ParameterSet[Set][P_NAV_GPS_D]);
            Setting.setValue("GPS_Acc",               ParameterSet[Set][P_NAV_GPS_ACC]);
            Setting.setValue("GPS_MinSat",            ParameterSet[Set][P_NAV_GPS_MIN]);
            Setting.setValue("GPS_StickThreshold",    ParameterSet[Set][P_NAV_STICK_THRE]);
            Setting.setValue("GPS_WindCorrection",    ParameterSet[Set][P_NAV_WIND_CORR]);
            Setting.setValue("GPS_SpeedCompensation", ParameterSet[Set][P_NAV_SPEED_COMP]);
            Setting.setValue("GPS_MaxRadius",         ParameterSet[Set][P_NAV_RADIUS]);
        Setting.endGroup();
    }
}

void MKTool::slot_LoadParameter() // DONE 0.71g
{
    QString Filename = QFileDialog::getOpenFileName(this, "Mikrokopter Parameter laden", Settings->DIR.Parameter, "Mikrokopter Parameter(*.mkp);;Alle Dateien (*)");

    if (!Filename.isEmpty())
    {
        int Set = sb_Set->value();
        QSettings Setting(Filename, QSettings::IniFormat);

        Setting.beginGroup("Setup");
            QString Name = Setting.value("Name", QString("--noname--")).toString();
            char *CName = Name.toLatin1().data();
            int a;

            for (a=0; a < Name.length(); a++)
            {
                ParameterSet[Set][P_NAME+a] = CName[a];
            }
            while (a < 12)
            {
                ParameterSet[Set][P_NAME+a] = 0;
                a++;
            }

            ParameterSet[Set][P_GLOBAL_CONF] = Setting.value("GlobalConfig", 0).toInt();
        Setting.endGroup();

        Setting.beginGroup("Channels");
            ParameterSet[Set][P_KANAL_NICK]  = Setting.value("Nick", 1).toInt();
            ParameterSet[Set][P_KANAL_ROLL]  = Setting.value("Roll", 2).toInt();
            ParameterSet[Set][P_KANAL_GAS]   = Setting.value("Gas", 3).toInt();
            ParameterSet[Set][P_KANAL_GIER]  = Setting.value("Gier", 4).toInt();
            ParameterSet[Set][P_KANAL_POTI1] = Setting.value("Poti_1", 5).toInt();
            ParameterSet[Set][P_KANAL_POTI2] = Setting.value("Poti_2", 6).toInt();
            ParameterSet[Set][P_KANAL_POTI3] = Setting.value("Poti_3", 7).toInt();
            ParameterSet[Set][P_KANAL_POTI4] = Setting.value("Poti_4", 8).toInt();
        Setting.endGroup();

        Setting.beginGroup("Stick");
            ParameterSet[Set][P_STICK_P]  = Setting.value("Nick_Roll-P", 4).toInt();
            ParameterSet[Set][P_STICK_D]  = Setting.value("Nick_Roll-D", 8).toInt();
            ParameterSet[Set][P_GIER_P]   = Setting.value("Gier-P", 1).toInt();
            ParameterSet[Set][P_EXTERNAL] = Setting.value("ExternalControl", 1).toInt();
        Setting.endGroup();

        Setting.beginGroup("Altitude");
            ParameterSet[Set][P_MAXHOEHE]   = Setting.value("Setpoint", 251).toInt();
            ParameterSet[Set][P_MIN_GAS]    = Setting.value("MinGas", 30).toInt();
            ParameterSet[Set][P_HOEHE_P]    = Setting.value("P", 10).toInt();
            ParameterSet[Set][P_DRUCK_D]    = Setting.value("Barometric-D", 30).toInt();
            ParameterSet[Set][P_HOEHE_ACC]  = Setting.value("Z-ACC-Effect", 30).toInt();
            ParameterSet[Set][P_HOEHE_GAIN] = Setting.value("Gain", 3).toInt();
        Setting.endGroup();

        Setting.beginGroup("Gyro");
            ParameterSet[Set][P_GYRO_P]          = Setting.value("P", 80).toInt();
            ParameterSet[Set][P_GYRO_I]          = Setting.value("I", 120).toInt();
            ParameterSet[Set][P_DYNAMIC_STAB]    = Setting.value("DynamicStability", 75).toInt();
            ParameterSet[Set][P_GYRO_ACC_FAKTOR] = Setting.value("ACC_Gyro-Factor", 30).toInt();
            ParameterSet[Set][P_GYRO_ACC_ABGL]   = Setting.value("ACC_Gyro-Compensation", 32).toInt();
            ParameterSet[Set][P_DRIFT_KOMP]      = Setting.value("DriftCompensation", 4).toInt();
            ParameterSet[Set][P_FAKTOR_I]        = Setting.value("Main-I", 32).toInt();
        Setting.endGroup();

        Setting.beginGroup("Camera");
            ParameterSet[Set][P_SERVO_NICK_CONT]  = Setting.value("ServoNickControl", 100).toInt();
            ParameterSet[Set][P_SERVO_NICK_COMP]  = Setting.value("ServoNickCompensation", 40).toInt();
            ParameterSet[Set][P_SERVO_NICK_COMPI] = Setting.value("ServoNickInvert", 0).toInt();
            ParameterSet[Set][P_SERVO_NICK_MIN]   = Setting.value("ServoNickMin", 50).toInt();
            ParameterSet[Set][P_SERVO_NICK_MAX]   = Setting.value("ServoNickMax", 150).toInt();
            ParameterSet[Set][P_SERVO_NICK_REFR]  = Setting.value("ServoNickRefreshRate", 5).toInt();
        Setting.endGroup();

        Setting.beginGroup("Others");
            ParameterSet[Set][P_GAS_MIN]         = Setting.value("MinGas", 8).toInt();
            ParameterSet[Set][P_GAS_MAX]         = Setting.value("MaxGas", 230).toInt();
            ParameterSet[Set][P_KOMPASS_WIRKUNG] = Setting.value("Compass-Effect", 128).toInt();
            ParameterSet[Set][P_UNTERSPANNUNG]   = Setting.value("UnderVoltage", 94).toInt();
            ParameterSet[Set][P_NOTGAS]          = Setting.value("NotGas", 35).toInt();
            ParameterSet[Set][P_NOTGASZEIT]      = Setting.value("NotGasTime", 30).toInt();
        Setting.endGroup();

        Setting.beginGroup("Coupling");
            ParameterSet[Set][P_ACHS_KOPPLUNG]  = Setting.value("YawPosFeedback", 90).toInt();
            ParameterSet[Set][P_ACHS_GKOPPLUNG] = Setting.value("YawNegFeedback", 5).toInt();
        Setting.endGroup();

        Setting.beginGroup("Loop");
            ParameterSet[Set][P_LOOP_CONFIG]    = Setting.value("Config", 0).toInt();
            ParameterSet[Set][P_LOOP_GAS_LIMIT] = Setting.value("GasLimit", 50).toInt();
            ParameterSet[Set][P_LOOP_THRESHOLD] = Setting.value("StickThreshold", 90).toInt();
            ParameterSet[Set][P_LOOP_HYSTERESE] = Setting.value("LoopHysteresis", 50).toInt();
            ParameterSet[Set][P_WINKEL_NICK]    = Setting.value("TurnOverNick", 85).toInt();
            ParameterSet[Set][P_WINKEL_ROLL]    = Setting.value("TurnOverRoll", 85).toInt();
        Setting.endGroup();

        Setting.beginGroup("User");
            ParameterSet[Set][P_USER_1] = Setting.value("Parameter_1", 0).toInt();
            ParameterSet[Set][P_USER_2] = Setting.value("Parameter_2", 0).toInt();
            ParameterSet[Set][P_USER_3] = Setting.value("Parameter_3", 0).toInt();
            ParameterSet[Set][P_USER_4] = Setting.value("Parameter_4", 0).toInt();
            ParameterSet[Set][P_USER_5] = Setting.value("Parameter_5", 0).toInt();
            ParameterSet[Set][P_USER_6] = Setting.value("Parameter_6", 0).toInt();
            ParameterSet[Set][P_USER_7] = Setting.value("Parameter_7", 0).toInt();
            ParameterSet[Set][P_USER_8] = Setting.value("Parameter_8", 0).toInt();
        Setting.endGroup();

        Setting.beginGroup("Output");
            ParameterSet[Set][P_J16_BITMASK] = Setting.value("J16_Bitmask", 255).toInt();
            ParameterSet[Set][P_J16_TIMING]  = Setting.value("J16_Timing", 251).toInt();
            ParameterSet[Set][P_J17_BITMASK] = Setting.value("J17_Bitmask", 255).toInt();
            ParameterSet[Set][P_J17_TIMING]  = Setting.value("J17_Timing", 251).toInt();
        Setting.endGroup();

        Setting.beginGroup("NaviCtrl");
            ParameterSet[Set][P_NAV_GPS_MODE]   = Setting.value("GPS_ModeControl", 253).toInt();
            ParameterSet[Set][P_NAV_GPS_GAIN]   = Setting.value("GPS_Gain", 100).toInt();
            ParameterSet[Set][P_NAV_GPS_P]      = Setting.value("GPS_P", 90).toInt();
            ParameterSet[Set][P_NAV_GPS_I]      = Setting.value("GPS_I", 90).toInt();
            ParameterSet[Set][P_NAV_GPS_D]      = Setting.value("GPS_D", 90).toInt();
            ParameterSet[Set][P_NAV_GPS_ACC]    = Setting.value("GPS_Acc", 0).toInt();
            ParameterSet[Set][P_NAV_GPS_MIN]    = Setting.value("GPS_MinSat", 6).toInt();
            ParameterSet[Set][P_NAV_STICK_THRE] = Setting.value("GPS_StickThreshold", 8).toInt();
            ParameterSet[Set][P_NAV_WIND_CORR]  = Setting.value("GPS_WindCorrection", 90).toInt();
            ParameterSet[Set][P_NAV_SPEED_COMP] = Setting.value("GPS_SpeedCompensation", 30).toInt();
            ParameterSet[Set][P_NAV_RADIUS]     = Setting.value("GPS_MaxRadius", 100).toInt();
        Setting.endGroup();

        show_ParameterSet(Set);
    }
}

void MKTool::show_ParameterSet(int Set) // DONE 0.71g
{
    char Name[12];
    for (int a = 0; a < 12; a++)
    {
        Name[a] = ParameterSet[Set][P_NAME+a];
    }
    le_SetName->setText(QString(Name));

    // Seite 1
{
    cb_1_1->setChecked(ParameterSet[Set][P_GLOBAL_CONF] & 0x01);
    cb_1_2->setChecked(ParameterSet[Set][P_GLOBAL_CONF] & 0x02);
    cb_1_3->setChecked(ParameterSet[Set][P_GLOBAL_CONF] & 0x04);
    cb_1_4->setChecked(ParameterSet[Set][P_GLOBAL_CONF] & 0x08);
    cb_1_5->setChecked(ParameterSet[Set][P_GLOBAL_CONF] & 0x10);
    cb_1_6->setChecked(ParameterSet[Set][P_GLOBAL_CONF] & 0x20);
    cb_1_7->setChecked(ParameterSet[Set][P_GLOBAL_CONF] & 0x40);
    cb_1_8->setChecked(ParameterSet[Set][P_GLOBAL_CONF] & 0x80);
}
    // Seite 2
{
    sb_2_1->setValue(ParameterSet[Set][P_KANAL_NICK]);
    sb_2_2->setValue(ParameterSet[Set][P_KANAL_ROLL]);
    sb_2_3->setValue(ParameterSet[Set][P_KANAL_GAS]);
    sb_2_4->setValue(ParameterSet[Set][P_KANAL_GIER]);
    sb_2_5->setValue(ParameterSet[Set][P_KANAL_POTI1]);
    sb_2_6->setValue(ParameterSet[Set][P_KANAL_POTI2]);
    sb_2_7->setValue(ParameterSet[Set][P_KANAL_POTI3]);
    sb_2_8->setValue(ParameterSet[Set][P_KANAL_POTI4]);
}
    // Seite 3
{
    sb_3_1->setValue(ParameterSet[Set][P_STICK_P]);
    sb_3_2->setValue(ParameterSet[Set][P_STICK_D]);
    cb_3_3 = setCombo(cb_3_3, Set, P_GIER_P);
    cb_3_4 = setCombo(cb_3_4, Set, P_EXTERNAL);
}
    // Seite 4
{
    cb_4_1 = setCombo(cb_4_1, Set, P_MAXHOEHE);
    sb_4_2->setValue(ParameterSet[Set][P_MIN_GAS]);
    cb_4_3 = setCombo(cb_4_3, Set, P_HOEHE_P);
    cb_4_4 = setCombo(cb_4_4, Set, P_DRUCK_D);
    cb_4_5 = setCombo(cb_4_5, Set, P_HOEHE_ACC);
    sb_4_6->setValue(ParameterSet[Set][P_HOEHE_GAIN]);
    cb_4_7->setChecked(ParameterSet[Set][P_LOOP_CONFIG] & 0x10);
}
    // Seite 5
{
    cb_5_1 = setCombo(cb_5_1, Set, P_GYRO_P);
    cb_5_2 = setCombo(cb_5_2, Set, P_GYRO_I);
    cb_5_3 = setCombo(cb_5_3, Set, P_DYNAMIC_STAB);
    sb_5_4->setValue(ParameterSet[Set][P_GYRO_ACC_FAKTOR]);
    sb_5_5->setValue(ParameterSet[Set][P_GYRO_ACC_ABGL]);
    cb_5_6 = setCombo(cb_5_6, Set, P_FAKTOR_I);
    sb_5_7->setValue(ParameterSet[Set][P_DRIFT_KOMP]);
}
    // Seite 6
{
    cb_6_1 = setCombo(cb_6_1, Set, P_SERVO_NICK_CONT);
    sb_6_2->setValue(ParameterSet[Set][P_SERVO_NICK_COMP]);
    sb_6_3->setValue(ParameterSet[Set][P_SERVO_NICK_MIN]);
    sb_6_4->setValue(ParameterSet[Set][P_SERVO_NICK_MAX]);
    sb_6_5->setValue(ParameterSet[Set][P_SERVO_NICK_REFR]);
    cb_6_6->setChecked(ParameterSet[Set][P_SERVO_NICK_COMPI]);
}
    // Seite 7
{
    sb_7_1->setValue(ParameterSet[Set][P_GAS_MIN]);
    sb_7_2->setValue(ParameterSet[Set][P_GAS_MAX]);
    cb_7_3 = setCombo(cb_7_3, Set, P_KOMPASS_WIRKUNG);
    sb_7_4->setValue(ParameterSet[Set][P_UNTERSPANNUNG]);
    sb_7_5->setValue(ParameterSet[Set][P_NOTGASZEIT]);
    sb_7_6->setValue(ParameterSet[Set][P_NOTGAS]);
}
    // Seite 8
{
    cb_8_1 = setCombo(cb_8_1, Set, P_ACHS_KOPPLUNG);
    cb_8_2 = setCombo(cb_8_2, Set, P_ACHS_GKOPPLUNG);
}
    // Seite 9
{
    if (ParameterSet[Set][P_LOOP_CONFIG] & 0x01)
    {
        tb_9_6->setIcon(Icons[20]);
        tb_9_6->setText("1");
    }
    else
    {
        tb_9_6->setIcon(Icons[21]);
        tb_9_6->setText("0");
    }

    if (ParameterSet[Set][P_LOOP_CONFIG] & 0x02)
    {
        tb_9_7->setIcon(Icons[22]);
        tb_9_7->setText("1");
    }
    else
    {
        tb_9_7->setIcon(Icons[23]);
        tb_9_7->setText("0");
    }

    if (ParameterSet[Set][P_LOOP_CONFIG] & 0x04)
    {
        tb_9_8->setIcon(Icons[24]);
        tb_9_8->setText("1");
    }
    else
    {
        tb_9_8->setIcon(Icons[25]);
        tb_9_8->setText("0");
    }

    if (ParameterSet[Set][P_LOOP_CONFIG] & 0x08)
    {
        tb_9_9->setIcon(Icons[26]);
        tb_9_9->setText("1");
    }
    else
    {
        tb_9_9->setIcon(Icons[27]);
        tb_9_9->setText("0");
    }

    cb_9_1 = setCombo(cb_9_1, Set, P_LOOP_GAS_LIMIT);
    sb_9_2->setValue(ParameterSet[Set][P_LOOP_THRESHOLD]);
    sb_9_3->setValue(ParameterSet[Set][P_WINKEL_NICK]);
    sb_9_4->setValue(ParameterSet[Set][P_LOOP_HYSTERESE]);
    sb_9_5->setValue(ParameterSet[Set][P_WINKEL_ROLL]);
}
    // Seite 10
{
    cb_10_1 = setCombo(cb_10_1, Set, P_USER_1);
    cb_10_2 = setCombo(cb_10_2, Set, P_USER_2);
    cb_10_3 = setCombo(cb_10_3, Set, P_USER_3);
    cb_10_4 = setCombo(cb_10_4, Set, P_USER_4);
    cb_10_5 = setCombo(cb_10_5, Set, P_USER_5);
    cb_10_6 = setCombo(cb_10_6, Set, P_USER_6);
    cb_10_7 = setCombo(cb_10_7, Set, P_USER_7);
    cb_10_8 = setCombo(cb_10_8, Set, P_USER_8);
}
    // Seite 11
{
    sb_11_1->setValue(ParameterSet[Set][P_J16_BITMASK]);
    cb_11_2 = setCombo(cb_11_2, Set, P_J16_TIMING);
    sb_11_3->setValue(ParameterSet[Set][P_J17_BITMASK]);
    cb_11_4 = setCombo(cb_11_4, Set, P_J17_TIMING);
}
    // Seite 12
{
    cb_12_1 = setCombo(cb_12_1, Set, P_NAV_GPS_MODE);
    cb_12_2 = setCombo(cb_12_2, Set, P_NAV_GPS_GAIN);
    sb_12_3->setValue(ParameterSet[Set][P_NAV_STICK_THRE]);
    sb_12_4->setValue(ParameterSet[Set][P_NAV_GPS_MIN]);
    cb_12_5 = setCombo(cb_12_5, Set, P_NAV_GPS_P);
    cb_12_6 = setCombo(cb_12_6, Set, P_NAV_GPS_I);
    cb_12_7 = setCombo(cb_12_7, Set, P_NAV_GPS_D);
    cb_12_8 = setCombo(cb_12_8, Set, P_NAV_GPS_ACC);
}

    // Seite 13
{
    cb_13_1 = setCombo(cb_13_1, Set, P_NAV_WIND_CORR);
    cb_13_2 = setCombo(cb_13_2, Set, P_NAV_SPEED_COMP);
    cb_13_3 = setCombo(cb_13_3, Set, P_NAV_RADIUS);
}


}

void MKTool::slot_TabChanged(int Tab) // DONE 0.71g
{
    Tab = Tab;
    if (tab_Main->count() != 0)
    {
        if ((tab_Main->currentWidget()->objectName() == QString("Tab_2")) && (tab_Par->currentIndex() == 1))
        {
            TX_Data[0] = 0;
            send_Data('p', ADDRESS_FC, TX_Data, 0, true);

            Ticker->setInterval(500);
            TickerEvent[1] = true;
        }
        else
        {
            Ticker->setInterval(2000);
            TickerEvent[1] = false;
        }

        if ((tab_Main->currentWidget()->objectName() == QString("Tab_4")))
        {
            TX_Data[0] = 0;
            TX_Data[1] = 0;
            send_Data('l', ADDRESS_ALL, TX_Data, 1, true);

            Ticker->setInterval(500);
            TickerEvent[2] = true;
        }
        else
        {
            Ticker->setInterval(2000);
            TickerEvent[2] = false;
        }
    }
}

void MKTool::slot_LCD_UP() // DONE 0.71g
{
    if (LCD_Page == LCD_MAX_Page)
        TX_Data[0] = 0;
    else
        TX_Data[0] = LCD_Page + 1;

    TX_Data[1] = 0;
    send_Data('l', ADDRESS_ALL, TX_Data, 1, true);
}

void MKTool::slot_LCD_DOWN() // DONE 0.71g
{
    if (LCD_Page == 0)
        TX_Data[0] = LCD_MAX_Page;
    else
        TX_Data[0] = LCD_Page - 1;

    TX_Data[1] = 0;
    send_Data('l', ADDRESS_ALL, TX_Data, 1, true);
}

void MKTool::slot_GetParameter() // DONE 0.71g
{
    TX_Data[0] = sb_Set->value();
    TX_Data[1] = 0;
    send_Data('q', ADDRESS_FC, TX_Data, 1);
}

void MKTool::slot_SetParameter() // DONE 0.71g
{
    store_ParameterSet(sb_Set->value());

    TX_Data[0] = sb_Set->value();
    TX_Data[1] = VERSION_SETTINGS;

    for (int a = 0; a < MaxParameter; a++)
    {
        TX_Data[a + 2] = ParameterSet[sb_Set->value()][a];
    }

    store_ParameterSet(sb_Set->value());

    send_Data('s', ADDRESS_FC, TX_Data, MaxParameter + 2, false);
}


// Save GUI-Settings
////////////////////
void MKTool::write_Settings()
{
    QBitArray TabViews(6);
    TabViews.setBit(0, ac_View0->isChecked());
    TabViews.setBit(1, ac_View1->isChecked());
    TabViews.setBit(2, ac_View2->isChecked());
    TabViews.setBit(3, ac_View3->isChecked());
    TabViews.setBit(4, ac_View4->isChecked());
    TabViews.setBit(5, ac_View5->isChecked());

    Settings->GUI.Term_Info   = cb_ShowMSG->isChecked();
    Settings->GUI.Term_Data   = cb_ShowData->isChecked();
    Settings->GUI.Term_Always = cb_ShowAlways->isChecked();

    QSettings Setting("KeyOz-Net", "QMK-Groundstation");

    Setting.beginGroup("Port");
        Setting.setValue("TTY", le_Port->text());
    Setting.endGroup();

    Setting.beginGroup("GUI");
        Setting.setValue("IsMax", isMaximized());
        Setting.setValue("Size",  size());
        Setting.setValue("Point", pos());
        Setting.setValue("TabViews", QBitArray(TabViews));
    Setting.endGroup();
}


// Debug-Daten anzeigen und Aufzeichnen
///////////////////////////////////////
void MKTool::write_CSV()
{
    QTextStream Out(CSVFile);
    for (int a=0; a<MaxAnalog; a++)
    {
        if (Settings->Analog1.LogView[a])
        {
            Out << AnalogData[a];
            if (a < MaxAnalog - 1)
                Out << ';';
        }
    }
    Out << "\n";
}

void MKTool::slot_RecordCSV() // DONE 0.71g
{
    if (!CSVFile->isOpen())
    {
        QString Filename = Settings->DIR.Logging + Mode.Hardware + " - " + QDate::currentDate().toString(("yyyy-MM-dd")) + " -- " + QTime::currentTime().toString("hh-mm") + ".csv";

        CSVFile = new QFile(Filename);
        if (!CSVFile->exists())
        {
            CSVFile->open(QIODevice::Append | QIODevice::Text);

            QTextStream Out(CSVFile);

            for (int a = 0; a < MaxAnalog; a++)
            {
                if (Settings->Analog1.LogView[a])
                {
                    Out << Settings->Analog1.Label[a];

                    if (a < MaxAnalog - 1)
                        Out << ';';
                }
            }
            Out << "\n";
        }
        else
        {
            CSVFile->open(QIODevice::Append | QIODevice::Text);
        }

        pb_Record->setIcon(Icons[6]);
        pb_Record->setText("CSV Stop");
        ac_RecordCSV->setIcon(Icons[6]);
        ac_RecordCSV->setText("CSV Stop");
    }
    else
    {
        CSVFile->close();
        pb_Record->setIcon(Icons[7]);
        pb_Record->setText("CSV Aufzeichnen");
        ac_RecordCSV->setIcon(Icons[7]);
        ac_RecordCSV->setText("CSV  Aufzeichnen");
    }
}

void MKTool::show_DebugData()
{
    if (CSVFile->isOpen())
    {
        write_CSV();
    }

    if (ac_StartPlotter->isChecked())
    {
        aID[NextPlot] = NextPlot;

        for (int a = 0; a < MaxAnalog; a++)
        {
            aData[a][NextPlot] = AnalogData[a];
        }
        NextPlot++;

        if ((tab_Main->currentWidget()->objectName() == QString("Tab_1")))
            update_Plot();
    }

    le_A_0->setText(QString("%1").arg(AnalogData[0]));
    le_A_1->setText(QString("%1").arg(AnalogData[1]));
    le_A_2->setText(QString("%1").arg(AnalogData[2]));
    le_A_3->setText(QString("%1").arg(AnalogData[3]));
    le_A_4->setText(QString("%1").arg(AnalogData[4]));
    le_A_5->setText(QString("%1").arg(AnalogData[5]));
    le_A_6->setText(QString("%1").arg(AnalogData[6]));
    le_A_7->setText(QString("%1").arg(AnalogData[7]));
    le_A_8->setText(QString("%1").arg(AnalogData[8]));
    le_A_9->setText(QString("%1").arg(AnalogData[9]));
    le_A_10->setText(QString("%1").arg(AnalogData[10]));
    le_A_11->setText(QString("%1").arg(AnalogData[11]));
    le_A_12->setText(QString("%1").arg(AnalogData[12]));
    le_A_13->setText(QString("%1").arg(AnalogData[13]));
    le_A_14->setText(QString("%1").arg(AnalogData[14]));
    le_A_15->setText(QString("%1").arg(AnalogData[15]));
    le_A_16->setText(QString("%1").arg(AnalogData[16]));
    le_A_17->setText(QString("%1").arg(AnalogData[17]));
    le_A_18->setText(QString("%1").arg(AnalogData[18]));
    le_A_19->setText(QString("%1").arg(AnalogData[19]));
    le_A_20->setText(QString("%1").arg(AnalogData[20]));
    le_A_21->setText(QString("%1").arg(AnalogData[21]));
    le_A_22->setText(QString("%1").arg(AnalogData[22]));
    le_A_23->setText(QString("%1").arg(AnalogData[23]));
    le_A_24->setText(QString("%1").arg(AnalogData[24]));
    le_A_25->setText(QString("%1").arg(AnalogData[25]));
    le_A_26->setText(QString("%1").arg(AnalogData[26]));
    le_A_27->setText(QString("%1").arg(AnalogData[27]));
    le_A_28->setText(QString("%1").arg(AnalogData[28]));
    le_A_29->setText(QString("%1").arg(AnalogData[29]));
    le_A_30->setText(QString("%1").arg(AnalogData[30]));
    le_A_31->setText(QString("%1").arg(AnalogData[31]));
}


// Seriel-Port Bereich, Befehle senden und Daten empfangen
//////////////////////////////////////////////////////////

// Neues Datenpacket empfangen -> Verarbeiten
void MKTool::new_RXData(sRxData RX) // DONE 0.71g
{

    if (LastSend.length() > 2)
    {
    }

    int HardwareID = RX.Input[1] - 'a';

    switch(RX.Input[2])
    {
        case 'L' : // DONE 0.71g
                    if (ToolBox::Decode64(RX, true))
                    {
                        int LCD[150];
                        memcpy(LCD,RX.Decode, sizeof(RX.Decode));

                        LCD_Page     = RX.Decode[0];
                        LCD_MAX_Page = RX.Decode[1];

                        le_LCD0->setText(ToolBox::Data2QString(LCD,2,22));
                        le_LCD1->setText(ToolBox::Data2QString(LCD,22,42));
                        le_LCD2->setText(ToolBox::Data2QString(LCD,42,62));
                        le_LCD3->setText(ToolBox::Data2QString(LCD,62,82));

                        TickerEvent[0] = false;
                    }
                break;
        case 'P' : // DONE 0.71g
                    if (ToolBox::Decode64(RX, true))
                    {
                        pb_K1->setValue(ToolBox::Data2Int(RX.Decode,  0,true));
                        pb_K2->setValue(ToolBox::Data2Int(RX.Decode,  2,true));
                        pb_K3->setValue(ToolBox::Data2Int(RX.Decode,  4,true));
                        pb_K4->setValue(ToolBox::Data2Int(RX.Decode,  6,true));
                        pb_K5->setValue(ToolBox::Data2Int(RX.Decode,  8,true));
                        pb_K6->setValue(ToolBox::Data2Int(RX.Decode, 10,true));
                        pb_K7->setValue(ToolBox::Data2Int(RX.Decode, 12,true));
                        pb_K8->setValue(ToolBox::Data2Int(RX.Decode, 14,true));
                    }
                break;
        case 'A' : // DONE 0.71g
                    if (ToolBox::Decode64(RX, true))
                    {
                        int Position = RX.Decode[0];
                        if (Position < 32)
                        {
                            Settings->Analog1.Label[Position] = ToolBox::Data2QString(RX.Decode,1,17).trimmed();
                            Position ++;
                            TX_Data[0] = Position;
                            send_Data('a', ADDRESS_ALL, TX_Data, 1, false);
                        }
                        if (Position == 32)
                        {
                            for (int a = 0; a < MaxAnalog; a++)
                            {
                                lb_Analog[a]->setText(Settings->Analog1.Label[a]);
                            }
                            Settings->write_Settings_AnalogLabels(HardwareID);
                            config_Plot();
                        }
                    }
                break;
        case 'D' : // DONE 0.71g
                    if (ToolBox::Decode64(RX, true))
                    {
                        for (int i = 0; i < MaxAnalog; i++)
                        {
                            AnalogData[i] = ToolBox::Data2Int(RX.Decode, (i * 2) + 2);
                        }
                        show_DebugData();
                    }
                break;
        case 'Q' : // DONE 0.71g
                    TickerEvent[0] = false;

                    ToolBox::Decode64(RX, true);

                    if (RX.Decode[1] == VERSION_SETTINGS)
                    {
                        int Settings_ID = RX.Decode[0];
                        for (int a = 0; a < MaxParameter; a++)
                        {
                            ParameterSet[Settings_ID][a] = RX.Decode[a + 2];
                        }
//                        memcpy(ParameterSet[Settings_ID],RX.Decode, sizeof(RX.Decode));
                        show_ParameterSet(Settings_ID);
                    }
                    else
                    {
                        pb_Read->setDisabled(true);
                        pb_Write->setDisabled(true);

                        QMessageBox::warning(this, QA_NAME,
                               "Versionen inkompatibel. \nParameterbearbeitung nicht moeglich.", QMessageBox::Ok);
                    }

                break;
        case 'S' : // DONE 0.71g
                    TickerEvent[0] = false;
                    qDebug("Settings set...!!!");
                break;
        case 'V' : // DONE 0.71g
                    TickerEvent[0] = false;

                    ToolBox::Decode64(RX, true);

                    Mode.ID            = RX.Input[1] - 'a';
                    Mode.VERSION_MAJOR = RX.Decode[0];
                    Mode.VERSION_MINOR = RX.Decode[1];
                    Mode.VERSION_PATCH = RX.Decode[4];
                    Mode.VERSION_SERIAL_MAJOR = RX.Decode[2];
                    Mode.VERSION_SERIAL_MINOR = RX.Decode[3];

                    Mode.Hardware   = HardwareType[Mode.ID];
                    Mode.Version    = QString("%1").arg(RX.Decode[0]) + "." + QString("%1").arg(RX.Decode[1]) + QString(RX.Decode[4] + 'a');

                    setWindowTitle(QA_NAME + " v" + QA_VERSION + " - " + Mode.Hardware + " " + Mode.Version);

                    if (Mode.VERSION_SERIAL_MAJOR != VERSION_SERIAL_MAJOR)
                    {
                            AllowSend = false;
                            QMessageBox::warning(this, QA_NAME,
                               "Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,", QMessageBox::Ok);
                    }

                    TX_Data[0] = 50;
                    send_Data('d', ADDRESS_ALL, TX_Data, 1, false);

                    if (Mode.ID == ADDRESS_FC)
                    {
                        {
                            TX_Data[0] = 0xff;
                            TX_Data[1] = 0;
                            send_Data('q', ADDRESS_FC, TX_Data, 1);
                        }
                    }
                    else
                    {
                            pb_Read->setDisabled(true);
                            pb_Write->setDisabled(true);

//                            QMessageBox::warning(this, QA_NAME,
//                               "Keine Verbindung zur FlightCtrl. \nParameterbearbeitung nicht moeglich.", QMessageBox::Ok);
                    }

                    Settings->read_Settings_AnalogLabels(HardwareID);
                    Settings->read_Settings_Analog(HardwareID);
                    for (int a = 0; a < MaxAnalog; a++)
                    {
                        lb_Analog[a]->setText(Settings->Analog1.Label[a]);
                    }
                    config_Plot();

                break;
    }
}

// Neue Daten an der Schnittstelle
void MKTool::slot_newDataReceived(const QByteArray &dataReceived) // DONE 0.71g
{
    const char *RXt;
    RXt = dataReceived.data();
    int a = 0;

    while (RXt[a] != '\0')
    {
        if (RXt[a] == '\r')
        {
            while ((RxData.String.length() > 1) && (RxData.String.at(1) == '#'))
            {
                RxData.String.remove(0,1);
            }

            if (ToolBox::check_CRC(RxData.String))
            {
                RxData.Input = RxData.String.toLatin1().data();
                new_RXData(RxData);

                if ((cb_ShowData->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked())))
                {
                    te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
                    te_RX->insertPlainText(RxData.String + '\r');
                }
            }
            else
            {
                if ((cb_ShowMSG->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked())))
                {
                    te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
                    te_RX->insertPlainText(RxData.String + '\r');
                }
            }
            RxData.String = QString("");
        }
        else
        {
            {
                RxData.String = RxData.String + QString(RXt[a]);
            }
        }
        a++;
    }
}

// Seriellen Port öffnen
void MKTool::slot_OpenPort()
{
    if (serialPort->isOpen())
    {
        TX_Data[0] = 0;
        TX_Data[1] = 0;
        TX_Data[2] = 0;
        TX_Data[3] = 0;
        send_Data('t', ADDRESS_FC, TX_Data, 4, false);

        serialPort->close();
        pb_Open->setText("Verbinden");
        ac_ConnectTTY->setText("Verbinden");
        pb_Open->setIcon(Icons[9]);
        ac_ConnectTTY->setIcon(Icons[9]);
    }
    else
    {
        serialPort->setPort(le_Port->text()); //Port

        serialPort->setBaudRate(BAUD57600); //BaudRate
        serialPort->setDataBits(DATA_8); //DataBits
        serialPort->setParity(PAR_NONE); //Parity
        serialPort->setStopBits(STOP_1); //StopBits
        serialPort->setFlowControl(FLOW_OFF); //FlowControl

        serialPort->setTimeout(0, 10);
        serialPort->enableSending();
        serialPort->enableReceiving();

        serialPort->open();
        if (serialPort->isOpen())
        {
            serialPort->receiveData();

            send_Data('v', ADDRESS_ALL, TX_Data, 0, true);

            pb_Open->setText("Trennen");
            ac_ConnectTTY->setText("Trennen");
            pb_Open->setIcon(Icons[8]);
            ac_ConnectTTY->setIcon(Icons[8]);
        }
    }
}

// Daten senden
void MKTool::send_Data(char CMD, int Address, char Data[150],unsigned int Length, bool Resend) // DONE 0.71g
{
    if (serialPort->isOpen() && AllowSend)
    {
        QString TX_Data = ToolBox::Encode64(Data, Length);

        TX_Data = QString("#") + (QString('a' + Address)) + QString(CMD) + TX_Data;

//    qDebug(TX_Data.toLatin1().data());

        TX_Data = ToolBox::add_CRC(TX_Data) + '\r';

//    qDebug(TX_Data.toLatin1().data());

        if (Resend)
        {
            LastSend = TX_Data;
            TickerEvent[0] = true;
        }

        QByteArray Temp(TX_Data.toUtf8());
        serialPort->sendData(Temp);
    }
}


// Programm beenden
///////////////////

MKTool::~MKTool()
{
    qDebug(" Programm Ende ..!! ");
    if (serialPort->isOpen())
    {
        serialPort->close();
    }

    write_Settings();
    Settings->write_Settings();

    if (CSVFile->isOpen())
    {
        CSVFile->close();
    }

//    close();
}