Subversion Repositories Projects

Rev

Rev 442 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
158 KeyOz 1
/***************************************************************************
2
 *   Copyright (C) 2008 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
250 KeyOz 20
// TODO: Wiederholungssenden wieder einbauen
21
 
158 KeyOz 22
#include <QtGui>
23
 
24
#include <QLineEdit>
25
#include <QString>
26
#include <QTimer>
27
#include <QIcon>
28
#include <QToolButton>
29
#include <QSpinBox>
199 KeyOz 30
#include <QAction>
227 KeyOz 31
#include <QPalette>
158 KeyOz 32
 
33
#include "mktool.h"
34
#include "dlg_Config.h"
35
#include "dlg_Motortest.h"
159 KeyOz 36
#include "dlg_Preferences.h"
158 KeyOz 37
#include "../global.h"
227 KeyOz 38
#include "../Classes/ToolBox.h"
158 KeyOz 39
 
40
#include <stdlib.h>
41
 
42
MKTool::MKTool()
43
{
44
    setupUi(this);
45
 
46
    Settings = new cSettings;
47
 
48
    init_Arrays();
49
    init_GUI();
306 KeyOz 50
    init_Cockpit();
158 KeyOz 51
 
52
    init_Objects();
53
    init_Connections();
54
 
55
    init_Plot();
56
}
57
 
58
void MKTool::init_GUI()
59
{
60
    setWindowTitle(QA_NAME + " v" + QA_VERSION);
61
 
167 KeyOz 62
    // Tab mit Debug-Elementen verbergen
314 KeyOz 63
    tab_Main->removeTab(6);
449 Brean 64
 
272 KeyOz 65
    // Develop - Nicht gebrauchte sachen abschalten.
66
    pb_SettingsReset->hide();
67
    pb_Flash->hide();
68
    rb_NC->hide();
167 KeyOz 69
 
279 KeyOz 70
    // Beta-Sachen einschalten.
71
#ifdef _BETA_
72
    ac_QMKServer->setEnabled(true);
73
#endif
337 KeyOz 74
 
167 KeyOz 75
    // Settings-Tab hinzufügen.
76
    f_Settings = new wdg_Settings( this );
227 KeyOz 77
    f_Settings->set_Config(Settings);
358 KeyOz 78
    tab_Main->insertTab ( 2, f_Settings, ac_View2->icon(), tr("FC-Settings"));
167 KeyOz 79
    tab_Main->widget(2)->setObjectName("Tab_2");
80
 
81
    // Zusätzliche Widgets in die Toolbar.
227 KeyOz 82
    tb_TTY->addWidget(lb_Port);
83
    tb_TTY->addWidget(le_Port);
166 KeyOz 84
 
227 KeyOz 85
    tb_Hardware->addWidget(rb_SelFC);
86
    tb_Hardware->addWidget(rb_SelNC);
87
    tb_Hardware->addWidget(rb_SelMag);
166 KeyOz 88
 
227 KeyOz 89
    tb_Allgemein->setVisible(Settings->GUI.ToolViews[0]);
90
    tb_Werkzeuge->setVisible(Settings->GUI.ToolViews[1]);
91
    tb_Debug->setVisible(Settings->GUI.ToolViews[2]);
92
    tb_TTY->setVisible(Settings->GUI.ToolViews[3]);
93
    tb_Hardware->setVisible(Settings->GUI.ToolViews[4]);
94
 
272 KeyOz 95
#ifdef _EEEPC_
96
    lb_Status->hide();
97
#endif
98
 
199 KeyOz 99
    lb_Status->setText(tr("Hallo bei QMK-Groundstation...!!!"));
100
 
158 KeyOz 101
    resize(Settings->GUI.Size);
102
    move(Settings->GUI.Point);
103
 
104
    if (Settings->GUI.isMax)
105
    {
106
        showMaximized();
107
    }
108
 
199 KeyOz 109
    // Analoglabels anzeigen
158 KeyOz 110
    for (int a = 0; a < MaxAnalog; a++)
111
    {
162 KeyOz 112
        lb_Analog[a]->setText(Settings->Analog1.Label[a]);
158 KeyOz 113
    }
114
 
199 KeyOz 115
    // Kopie der Tabs anlegen
272 KeyOz 116
    for (int b = 0; b < 7; b++)
158 KeyOz 117
    {
118
        TabWidgets[b] = tab_Main->widget(b);
119
    }
120
 
199 KeyOz 121
    // Ausgeblendete Tabs ausblenden
272 KeyOz 122
    for (int c = 0; c < 7; c++)
158 KeyOz 123
    {
124
        if (Settings->GUI.TabViews[c] == false)
125
        {
126
            QString TabName = QString("Tab_%1").arg(c);
127
 
128
            for (int d = 0; d < tab_Main->count(); d++)
129
            {
130
                if (tab_Main->widget(d)->objectName() == TabName)
131
                {
132
                    tab_Main->removeTab(d);
133
                }
134
            }
135
        }
136
    }
137
 
138
    ac_View0->setChecked(Settings->GUI.TabViews[0]);
139
    ac_View1->setChecked(Settings->GUI.TabViews[1]);
140
    ac_View2->setChecked(Settings->GUI.TabViews[2]);
141
    ac_View3->setChecked(Settings->GUI.TabViews[3]);
142
    ac_View4->setChecked(Settings->GUI.TabViews[4]);
143
    ac_View5->setChecked(Settings->GUI.TabViews[5]);
272 KeyOz 144
    ac_View6->setChecked(Settings->GUI.TabViews[6]);
158 KeyOz 145
 
146
    le_Port->setText(Settings->TTY.Port);
162 KeyOz 147
 
148
    cb_ShowMSG->setChecked(Settings->GUI.Term_Info);
149
    cb_ShowData->setChecked(Settings->GUI.Term_Data);
150
    cb_ShowAlways->setChecked(Settings->GUI.Term_Always);
158 KeyOz 151
}
152
 
306 KeyOz 153
void MKTool::init_Cockpit()
154
{
155
    // Cockpit-Elemente
156
    QPalette newPalette;
157
 
158
    newPalette.setColor(QPalette::Base, Qt::darkBlue);
159
    newPalette.setColor(QPalette::Foreground, QColor(Qt::darkBlue).dark(120));
160
    newPalette.setColor(QPalette::Text, Qt::white);
161
 
162
    Compass->setScaleOptions(QwtDial::ScaleTicks | QwtDial::ScaleLabel);
163
    Compass->setScaleTicks(0, 0, 3);
164
    Compass->setScale(36, 5, 0);
165
 
166
    Compass->setNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, true, Qt::red, QColor(Qt::gray).light(130)));
167
    Compass->setPalette(newPalette);
168
    Compass->setMaximumSize(QSize(MeterSize, MeterSize));
169
    Compass->setMinimumSize(QSize(MeterSize, MeterSize));
170
 
171
    QPalette newPalette1;
172
 
173
    newPalette1.setColor(QPalette::Base, Qt::darkBlue);
174
    newPalette1.setColor(QPalette::Foreground, QColor(255,128,0).dark(120));
175
    newPalette1.setColor(QPalette::Text, Qt::white);
176
 
177
    Attitude = new AttitudeIndicator(this);
178
    Attitude->setMaximumSize(QSize(MeterSize, MeterSize));
179
    Attitude->setMinimumSize(QSize(MeterSize, MeterSize));
180
    Attitude->setPalette(newPalette1);
181
 
182
    verticalLayout->addWidget(Attitude);
183
 
184
    qwt_Rate->setRange(-10.0, 10.0, 0.1, 0);
185
 
186
    newPalette1.setColor(QPalette::Foreground, QColor(Qt::darkBlue).dark(120));
187
 
188
    SpeedMeter = new cSpeedMeter(this);
189
    SpeedMeter->setMaximumSize(QSize(MeterSize, MeterSize));
190
    SpeedMeter->setMinimumSize(QSize(MeterSize, MeterSize));
191
    SpeedMeter->setPalette(newPalette1);
192
    SpeedMeter->setRange(0.0, 5.0);
193
    SpeedMeter->setScale(1, 2, 0.5);
194
    SpeedMeter->setProperty("END", 5);
195
 
196
    LayOut_Speed->addWidget(SpeedMeter);
197
}
198
 
158 KeyOz 199
void MKTool::init_Objects()
200
{
440 Brean 201
    //new KopterData object that contains all data from MK
202
    data = new KopterData();
203
 
396 Brean 204
    //new QT-Communication object
449 Brean 205
    com = new QTSerialCommunication();
396 Brean 206
 
207
    //create handler that handles incomming data
440 Brean 208
    handler = new Handler(com, data);
396 Brean 209
 
158 KeyOz 210
    // QTimer-Instanzen
441 Brean 211
    //FIXME: Move Ticker to libMK/QTCommunication.cpp
212
    //Ticker = new QTimer(this);
158 KeyOz 213
 
396 Brean 214
    // Logger
440 Brean 215
    logger = new Logger(Settings, data);
159 KeyOz 216
 
227 KeyOz 217
    // LCD-Dialog
218
    f_LCD = new dlg_LCD(this);
219
 
305 KeyOz 220
    // LCD-Dialog
307 KeyOz 221
    f_MotorMixer = new dlg_MotorMixer(this);
222
 
223
    // LCD-Dialog
305 KeyOz 224
    f_Map = new dlg_Map(this);
306 KeyOz 225
    f_Map->create_Map(Settings);
305 KeyOz 226
 
306 KeyOz 227
    KML_Server = new cKML_Server();
199 KeyOz 228
 
272 KeyOz 229
    QMK_Server = new cQMK_Server();
230
    QMK_Server->setProperty("Connect", false);
199 KeyOz 231
 
232
    if (Settings->Server.StartServer)
233
    {
234
        ac_StartServer->setChecked(true);
306 KeyOz 235
        KML_Server->start_Server(Settings->Server.Port.toInt(), Settings);
199 KeyOz 236
    }
158 KeyOz 237
}
238
 
239
void MKTool::init_Connections()
240
{
250 KeyOz 241
    connect(Dec, SIGNAL(clicked()), this, SLOT(slot_Test()));
199 KeyOz 242
 
306 KeyOz 243
    // Waypoints übergeben
244
    connect(f_Map, SIGNAL(set_Target(sWayPoint)), this , SLOT(slot_MAP_SetTarget(sWayPoint)));
358 KeyOz 245
    connect(f_Map, SIGNAL(set_WayPoints(QList<sWayPoint>)), this , SLOT(slot_MAP_SetWayPoints(QList<sWayPoint>)));
306 KeyOz 246
 
250 KeyOz 247
    // Daten Senden / Empfangen
396 Brean 248
//FIXME: put this in QTCommunication.cpp
249
//    connect(o_Connection, SIGNAL(newData(sRxData)), this, SLOT(slot_newData(sRxData)));
250
//    connect(o_Connection, SIGNAL(showTerminal(int, QString)), this, SLOT(slot_showTerminal(int, QString)));
158 KeyOz 251
 
199 KeyOz 252
    // Serielle Verbundung öffnen / schließen
253
    connect(ac_ConnectTTY, SIGNAL(triggered()), this, SLOT(slot_OpenPort()));
254
 
396 Brean 255
    // TCP-Connection for other QMK-Groundstations
227 KeyOz 256
    connect(ac_QMKServer, SIGNAL(triggered()), this, SLOT(slot_QMKS_Connect()));
257
 
167 KeyOz 258
    // Buttons Settings lesen / schreiben
199 KeyOz 259
    connect(f_Settings->pb_Read,   SIGNAL(clicked()), this, SLOT(slot_GetFCSettings()));
260
    connect(f_Settings->pb_Write,  SIGNAL(clicked()), this, SLOT(slot_SetFCSettings()));
158 KeyOz 261
 
262
    // Actions
263
    connect(ac_Config,       SIGNAL(triggered()), this, SLOT(slot_ac_Config()));
159 KeyOz 264
    connect(ac_Preferences,  SIGNAL(triggered()), this, SLOT(slot_ac_Preferences()));
158 KeyOz 265
    connect(ac_Motortest,    SIGNAL(triggered()), this, SLOT(slot_ac_Motortest()));
307 KeyOz 266
    connect(ac_MotorMixer,   SIGNAL(triggered()), this, SLOT(slot_ac_MotorMixer()));
227 KeyOz 267
    connect(ac_LCD,          SIGNAL(triggered()), this, SLOT(slot_ac_LCD()));
305 KeyOz 268
    connect(ac_Map,          SIGNAL(triggered()), this, SLOT(slot_ac_Map()));
199 KeyOz 269
    connect(ac_FastDebug,    SIGNAL(triggered()), this, SLOT(slot_ac_FastDebug()));
270
    connect(ac_NoDebug,      SIGNAL(triggered()), this, SLOT(slot_ac_NoDebug()));
271
    connect(ac_FastNavi,     SIGNAL(triggered()), this, SLOT(slot_ac_FastNavi()));
272
    connect(ac_NoNavi,       SIGNAL(triggered()), this, SLOT(slot_ac_NoNavi()));
158 KeyOz 273
    connect(ac_GetLabels,    SIGNAL(triggered()), this, SLOT(slot_ac_GetLabels()));
274
 
167 KeyOz 275
    // Plotter starten / scrollen
276
    connect(scroll_plot,     SIGNAL(valueChanged(int)), this, SLOT(slot_ScrollPlot(int)));
277
    connect(ac_StartPlotter, SIGNAL(triggered()), this, SLOT(slot_ac_StartPlotter()));
199 KeyOz 278
    connect(ac_StartServer,  SIGNAL(triggered()), this, SLOT(slot_ac_StartServer()));
167 KeyOz 279
 
158 KeyOz 280
    // Tabs ein & ausblenden
281
    connect(ac_View0,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
282
    connect(ac_View1,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
283
    connect(ac_View2,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
284
    connect(ac_View3,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
285
    connect(ac_View4,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
286
    connect(ac_View5,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
227 KeyOz 287
    connect(ac_View6,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
158 KeyOz 288
 
199 KeyOz 289
    connect(ac_SelNC,        SIGNAL(triggered()), this, SLOT(slot_ac_Hardware()));
290
    connect(ac_SelFC,        SIGNAL(triggered()), this, SLOT(slot_ac_Hardware()));
291
    connect(ac_SelMag,       SIGNAL(triggered()), this, SLOT(slot_ac_Hardware()));
292
 
293
    connect(rb_SelNC,        SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
294
    connect(rb_SelFC,        SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
295
    connect(rb_SelMag,       SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
296
 
167 KeyOz 297
    // firmeware Updateen / flashen
199 KeyOz 298
    connect(pb_Update,   SIGNAL(clicked()), this, SLOT(slot_pb_Update()));
166 KeyOz 299
    connect(pb_HexFile,  SIGNAL(clicked()), this, SLOT(slot_pb_HexFile()));
158 KeyOz 300
 
250 KeyOz 301
    // Wegpunkt-Befehl
358 KeyOz 302
    connect(pb_FlyTo,        SIGNAL(clicked()), this, SLOT(slot_pb_SendTarget()));
250 KeyOz 303
 
167 KeyOz 304
    // CVS-Record starten / stoppen
239 Brean 305
    connect(ac_RecordCSV,  SIGNAL(triggered()), this, SLOT(slot_RecordLog()));
158 KeyOz 306
 
307
    // Timer-Events
441 Brean 308
    //FIXME: Move Ticker to libMK/QTCommunication.cpp
309
    //connect(Ticker,   SIGNAL(timeout()),       SLOT(slot_Ticker()));
158 KeyOz 310
 
167 KeyOz 311
    // Seitenwechsel
199 KeyOz 312
    connect(tab_Main,             SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int)));
306 KeyOz 313
//    connect(f_Settings->tab_Par,  SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int)));
314
    connect(f_Settings->listWidget,  SIGNAL(currentRowChanged(int)), this, SLOT(slot_TabChanged(int)));
158 KeyOz 315
 
167 KeyOz 316
    // About QMK & About-QT Dialog einfügen
317
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
158 KeyOz 318
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
319
}
320
 
321
void MKTool::init_Arrays()
322
{
323
    lb_Analog[0]  = lb_A_0;
324
    lb_Analog[1]  = lb_A_1;
325
    lb_Analog[2]  = lb_A_2;
326
    lb_Analog[3]  = lb_A_3;
327
    lb_Analog[4]  = lb_A_4;
328
    lb_Analog[5]  = lb_A_5;
329
    lb_Analog[6]  = lb_A_6;
330
    lb_Analog[7]  = lb_A_7;
331
    lb_Analog[8]  = lb_A_8;
332
    lb_Analog[9]  = lb_A_9;
333
    lb_Analog[10] = lb_A_10;
334
    lb_Analog[11] = lb_A_11;
335
    lb_Analog[12] = lb_A_12;
336
    lb_Analog[13] = lb_A_13;
337
    lb_Analog[14] = lb_A_14;
338
    lb_Analog[15] = lb_A_15;
339
    lb_Analog[16] = lb_A_16;
340
    lb_Analog[17] = lb_A_17;
341
    lb_Analog[18] = lb_A_18;
342
    lb_Analog[19] = lb_A_19;
343
    lb_Analog[20] = lb_A_20;
344
    lb_Analog[21] = lb_A_21;
345
    lb_Analog[22] = lb_A_22;
346
    lb_Analog[23] = lb_A_23;
347
    lb_Analog[24] = lb_A_24;
348
    lb_Analog[25] = lb_A_25;
349
    lb_Analog[26] = lb_A_26;
350
    lb_Analog[27] = lb_A_27;
351
    lb_Analog[28] = lb_A_28;
352
    lb_Analog[29] = lb_A_29;
353
    lb_Analog[30] = lb_A_30;
354
    lb_Analog[31] = lb_A_31;
441 Brean 355
    le_Analog[0] = le_A_0;
356
    le_Analog[1] = le_A_1;
357
    le_Analog[2] = le_A_2;
358
    le_Analog[3] = le_A_3;
359
    le_Analog[4] = le_A_4;
360
    le_Analog[5] = le_A_5;
361
    le_Analog[6] = le_A_6;
362
    le_Analog[7] = le_A_7;
363
    le_Analog[8] = le_A_8;
364
    le_Analog[9] = le_A_9;
365
    le_Analog[10] = le_A_10;
366
    le_Analog[11] = le_A_11;
367
    le_Analog[12] = le_A_12;
368
    le_Analog[13] = le_A_13;
369
    le_Analog[14] = le_A_14;
370
    le_Analog[15] = le_A_15;
371
    le_Analog[16] = le_A_16;
372
    le_Analog[17] = le_A_17;
373
    le_Analog[18] = le_A_18;
374
    le_Analog[19] = le_A_19;
375
    le_Analog[20] = le_A_20;
376
    le_Analog[21] = le_A_21;
377
    le_Analog[22] = le_A_22;
378
    le_Analog[23] = le_A_23;
379
    le_Analog[24] = le_A_24;
380
    le_Analog[25] = le_A_25;
381
    le_Analog[26] = le_A_26;
382
    le_Analog[27] = le_A_27;
383
    le_Analog[28] = le_A_28;
384
    le_Analog[29] = le_A_29;
385
    le_Analog[30] = le_A_30;
386
    le_Analog[31] = le_A_31;
158 KeyOz 387
}
388
 
389
void MKTool::init_Plot()
390
{
391
    NextPlot = 0;
392
 
393
    qwtPlot->setCanvasBackground(QColor(QRgb(0x00000000)));
394
 
395
    qwtPlot->insertLegend(new QwtLegend(), QwtPlot::RightLegend);
396
 
397
    QwtPlotGrid *Grid = new QwtPlotGrid();
398
    Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
399
 
400
    Grid->attach(qwtPlot);
401
 
166 KeyOz 402
    qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0);
158 KeyOz 403
 
404
    for (int a = 0; a < MaxAnalog; a++)
405
    {
162 KeyOz 406
        Plot[a] = new QwtPlotCurve(Settings->Analog1.Label[a]);
407
        Plot[a]->setPen(QPen(QColor(Def_Colors[a])));
250 KeyOz 408
//        Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased);
158 KeyOz 409
 
162 KeyOz 410
        if (Settings->Analog1.PlotView[a])
158 KeyOz 411
            Plot[a]->attach(qwtPlot);
412
    }
413
    qwtPlot->replot();
414
}
415
 
306 KeyOz 416
void MKTool::slot_set_Settings(cSettings *t_Settings)
417
{
418
    Settings = t_Settings;
419
}
420
 
199 KeyOz 421
void MKTool::slot_Test()
158 KeyOz 422
{
449 Brean 423
//    sRxData RX;
272 KeyOz 424
 
449 Brean 425
//    RX.str = IN->text().toLatin1().data();
272 KeyOz 426
 
449 Brean 427
//    RX.input = (char *)RX.str.c_str();
272 KeyOz 428
 
449 Brean 429
//    slot_newData(RX);
250 KeyOz 430
}
158 KeyOz 431
 
272 KeyOz 432
// KML-Datei nach Wegpunkt parsen
433
// TODO: Richtigen KML-Parser bauen
250 KeyOz 434
void MKTool::parse_TargetKML()
435
{
436
    QString Tmp = te_KML->toPlainText().simplified();
397 Brean 437
    QStringList list;
158 KeyOz 438
 
250 KeyOz 439
    if ((Tmp.contains("<kml xmlns=\"http://earth.google.com/kml/2.2\">"))  && (Tmp.contains("<coordinates>")))
440
    {
397 Brean 441
        list = Tmp.split("<coordinates>");
442
        list = list[1].split(",");
250 KeyOz 443
 
397 Brean 444
        le_TarLong->setText( QString::number( list[0].toDouble() ) );
445
        le_TarLat->setText( QString::number( list[1].toDouble() ) );
442 Brean 446
        //le_TarLong->setText(ToolBox::get_Float((List[0] * 10000000), 7));
447
        //le_TarLat->setText(ToolBox::get_Float((List[1] * 10000000), 7));
250 KeyOz 448
    }
158 KeyOz 449
}
450
 
441 Brean 451
// send waypoint to NaviCtrl.
358 KeyOz 452
void MKTool::slot_pb_SendTarget()
250 KeyOz 453
{
440 Brean 454
    sNaviData navi = data->navi;
455
    if ((navi.Current.Longitude == 0) && (navi.Current.Latitude == 0))
250 KeyOz 456
    {
457
        QMessageBox msgB;
458
        QString msg;
358 KeyOz 459
        msgB.setText(tr("Fehler: Es konnten keine GPS-Daten vom Mikrokopter empfangen werden"));
250 KeyOz 460
        msgB.exec();
461
        return;
462
    }
272 KeyOz 463
 
441 Brean 464
    //create a waypoint that can be understood by NaviCtrl
250 KeyOz 465
    Waypoint_t desired_pos;
466
    bool ok_lat, ok_lon;
467
 
441 Brean 468
    //get data from QT-GUI
250 KeyOz 469
    double desired_long, desired_lat;
470
 
471
    desired_long = le_TarLong->text().toDouble(&ok_lon);
472
    desired_lat  = le_TarLat->text().toDouble(&ok_lat);
473
 
474
    if (ok_lon && desired_long < 100)
475
        desired_long *= 10000000+0.5;
476
 
477
    if (ok_lat && desired_lat < 100)
478
        desired_lat *= 10000000+0.5;
479
 
441 Brean 480
    //fill WayPoint struct
250 KeyOz 481
    desired_pos.Position.Altitude = 0;
482
    desired_pos.Position.Longitude = int32_t(desired_long);
483
    desired_pos.Position.Latitude =  int32_t(desired_lat);
484
    desired_pos.Position.Status = NEWDATA;
485
    desired_pos.Heading = -1;
334 KeyOz 486
    desired_pos.ToleranceRadius = 5;
358 KeyOz 487
    desired_pos.HoldTime = sb_TarTime->value();
250 KeyOz 488
    desired_pos.Event_Flag = 0;
489
    desired_pos.reserve[0] = 0; // reserve
490
    desired_pos.reserve[1] = 0; // reserve
491
    desired_pos.reserve[2] = 0; // reserve
492
    desired_pos.reserve[3] = 0; // reserve
493
 
441 Brean 494
    //...and send it to NaviCtrl
250 KeyOz 495
    int max_radius = 10000;
496
    if (ok_lat && ok_lon &&
440 Brean 497
        abs((double)(navi.Current.Longitude - desired_pos.Position.Longitude)) < max_radius &&
498
        abs((double)(navi.Current.Latitude  - desired_pos.Position.Latitude)) < max_radius)
250 KeyOz 499
    {
399 Brean 500
        handler->send_waypoint(desired_pos);
250 KeyOz 501
    }
502
    else
503
    {
504
        QMessageBox msgB;
505
        QString msg;
358 KeyOz 506
        msg += tr("Bitte die Eingabe ueberpruefen!\n");
507
        msg += tr("Die Werte muessen sich in der Naehe der aktuellen Koordinaten befinden\n");
250 KeyOz 508
        msg += "(Lon: ";
440 Brean 509
        msg += QString::number(navi.Current.Longitude);
250 KeyOz 510
        msg += ", ";
511
        msg += "Lat: ";
440 Brean 512
        msg += QString::number(navi.Current.Latitude);
250 KeyOz 513
        msg += ")";
514
        msgB.setText(msg);
515
        msgB.exec();
516
    }
517
}
518
 
337 KeyOz 519
// Hardware-Auswahl im Menp
199 KeyOz 520
void MKTool::slot_ac_Hardware()
521
{
522
    QAction *Action = (QAction*)sender();
158 KeyOz 523
 
199 KeyOz 524
    if (Action->isChecked() == false)
525
    {
526
        Action->setChecked(true);
527
    }
528
 
529
    slot_rb_Hardware();
530
}
531
 
337 KeyOz 532
// Hardware Auswahl und umschalten
199 KeyOz 533
void MKTool::slot_rb_Hardware()
534
{
442 Brean 535
    if ((rb_SelNC->isChecked() == false) && (data->mode.id != ADDRESS_NC))
199 KeyOz 536
    {
537
        lb_Status->setText(tr("Schalte um auf NaviCtrl."));
399 Brean 538
        handler->switch_navictrl();
539
        //FIXME: remove wait?
540
        ToolBox::wait(SLEEP);
199 KeyOz 541
    }
542
 
543
    if (rb_SelFC->isChecked())
544
    {
545
        lb_Status->setText(tr("Schalte um auf FlightCtrl."));
399 Brean 546
        handler->switch_flightctrl();
199 KeyOz 547
    }
548
    else
549
    if (rb_SelMag->isChecked())
550
    {
551
        lb_Status->setText(tr("Schalte um auf MK3MAG."));
399 Brean 552
        handler->switch_mk3mag();
199 KeyOz 553
    }
554
    else
555
    if (rb_SelNC->isChecked())
556
    {
557
        lb_Status->setText(tr("Schalte um auf NaviCtrl."));
399 Brean 558
        handler->switch_navictrl();
199 KeyOz 559
    }
391 Brean 560
    ToolBox::wait(SLEEP);
199 KeyOz 561
 
562
//    qDebug("Select RB Hardware");
399 Brean 563
    handler->get_version();
199 KeyOz 564
}
565
 
442 Brean 566
//FIXME: Put this somewhere in libMK/QTCommunication.cpp
158 KeyOz 567
// Ticker-Event
568
///////////////
442 Brean 569
/*void MKTool::slot_Ticker()
158 KeyOz 570
{
442 Brean 571
 
572
 
158 KeyOz 573
    if (TickerDiv)
574
        TickerDiv = false;
575
    else
576
        TickerDiv = true;
396 Brean 577
 
158 KeyOz 578
    for (int a = 0; a < MaxTickerEvents; a++)
579
    {
580
        if (TickerEvent[a] == true)
581
        {
582
            switch(a)
583
            {
584
                case 0 :
585
                    {
586
                    }
587
                break;
588
                case 1 :
159 KeyOz 589
                    TX_Data[0] = 0;
306 KeyOz 590
                    o_Connection->send_Cmd('p', ADDRESS_FC, TX_Data, 0, false);
158 KeyOz 591
                break;
159 KeyOz 592
                case 2 :
227 KeyOz 593
                    if (f_LCD->cb_LCD->isChecked())
167 KeyOz 594
                    {
227 KeyOz 595
                        if (!f_LCD->isVisible())
596
                        {
597
                            Ticker->setInterval(2000);
598
                            TickerEvent[2] = false;
599
                        }
167 KeyOz 600
                        TX_Data[0] = LCD_Page;
601
                        TX_Data[1] = 0;
306 KeyOz 602
                        o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
167 KeyOz 603
                    }
159 KeyOz 604
                break;
167 KeyOz 605
                case 3 :
199 KeyOz 606
                    if (ac_FastDebug->isChecked())
167 KeyOz 607
                    {
608
                        TX_Data[0] = Settings->Data.Debug_Fast / 10;
306 KeyOz 609
                        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
167 KeyOz 610
                    }
611
                    else
612
                    {
613
                        TX_Data[0] = Settings->Data.Debug_Slow / 10;
306 KeyOz 614
                        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
167 KeyOz 615
                    }
616
                break;
337 KeyOz 617
                case 4 :
618
                    {
619
                        for (int z = 0; z<12; z++)
620
                        {
621
                            TX_Data[z] = Motor.Speed[z];
622
                        }
623
                        o_Connection->send_Cmd('t', ADDRESS_FC, TX_Data, 12, false);
624
                    }
625
 
158 KeyOz 626
            }
627
        }
628
    }
442 Brean 629
}
396 Brean 630
*/
158 KeyOz 631
 
442 Brean 632
// connect to QMK dataserver
227 KeyOz 633
void MKTool::slot_QMKS_Connect()
634
{
635
    if (ac_QMKServer->isChecked())
636
    {
637
        lb_Status->setText(tr("Verbinde zum QMK-Datenserver."));
158 KeyOz 638
 
272 KeyOz 639
        QMK_Server->Connect(Settings->Server.QMKS_Host, Settings->Server.QMKS_Port.toInt(), Settings->Server.QMKS_Login, Settings->Server.QMKS_Password);
227 KeyOz 640
 
272 KeyOz 641
        connect(QMK_Server, SIGNAL(sig_Connected()), this, SLOT(slot_QMKS_Connected()));
642
        connect(QMK_Server, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_QMKS_Disconnected(int)));
227 KeyOz 643
    }
644
    else
645
    {
272 KeyOz 646
        if ((QMK_Server->property("Connect")) == true)
227 KeyOz 647
        {
272 KeyOz 648
            disconnect(QMK_Server, SIGNAL(sig_Disconnected(int)), 0, 0);
227 KeyOz 649
            lb_Status->setText(tr("Trenne vom QMK-Datenserver."));
650
 
272 KeyOz 651
            QMK_Server->Disconnect();
652
            QMK_Server->setProperty("Connect", false);
358 KeyOz 653
            ac_QMKServer->setText(tr("QMK-Server Verbinden"));
227 KeyOz 654
        }
655
    }
656
}
657
 
337 KeyOz 658
// Verbindung zum QMK-Server hergestellt.
227 KeyOz 659
void MKTool::slot_QMKS_Connected()
660
{
272 KeyOz 661
    QMK_Server->setProperty("Connect", true);
358 KeyOz 662
    ac_QMKServer->setText(tr("QMK-Server Trennnen"));
227 KeyOz 663
    lb_Status->setText(tr("Verbunden mit QMK-Datenserver."));
664
}
665
 
337 KeyOz 666
// QMK-Serververbindung getrennt
227 KeyOz 667
void MKTool::slot_QMKS_Disconnected(int Error)
668
{
272 KeyOz 669
    QMK_Server->setProperty("Connect", false);
358 KeyOz 670
    ac_QMKServer->setText(tr("QMK-Server Verbinden"));
227 KeyOz 671
    ac_QMKServer->setChecked(false);
672
 
272 KeyOz 673
    disconnect(QMK_Server, SIGNAL(sig_Disconnected(int)), 0, 0);
227 KeyOz 674
 
675
    switch (Error)
676
    {
677
        case 1 :
678
        {
679
            lb_Status->setText(tr("Verbindung vom Server beendet."));
358 KeyOz 680
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Verbindung wurde vom Server beendet."), QMessageBox::Ok);
227 KeyOz 681
        }
682
        break;
683
        case 2 :
684
        {
685
            lb_Status->setText(tr("Server nicht gefunden."));
358 KeyOz 686
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Kann nicht zum Server verbinden."), QMessageBox::Ok);
227 KeyOz 687
        }
688
        break;
689
        case 3 :
690
        {
691
            lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch."));
358 KeyOz 692
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Loginname oder Password falsch."), QMessageBox::Ok);
227 KeyOz 693
        }
694
        break;
695
        default :
696
        {
697
            lb_Status->setText(tr("Getrennt vom QMK-Datenserver."));
698
        }
699
        break;
700
    }
701
}
702
 
158 KeyOz 703
// Slots der Actions (Menüpunkte, Buttons)
704
//////////////////////////////////////////
705
void MKTool::slot_ac_Motortest()
706
{
707
    dlg_Motortest *f_Motortest = new dlg_Motortest(this);
708
 
337 KeyOz 709
//    connect(f_Motortest, SIGNAL(updateMotor(int, int, int, int)), this, SLOT(slot_Motortest(int, int, int, int)));
710
    connect(f_Motortest, SIGNAL(updateMotor(sMotor)), this, SLOT(slot_Motortest(sMotor)));
158 KeyOz 711
 
441 Brean 712
//FIXME: Move Ticker to libMK/QTCommunication.cpp
713
//    Ticker->setInterval(500);
714
//    TickerEvent[4] = true;
337 KeyOz 715
 
158 KeyOz 716
    if (f_Motortest->exec()==QDialog::Accepted)
717
    {
718
    }
719
 
720
    disconnect(f_Motortest, 0,0,0);
337 KeyOz 721
 
440 Brean 722
    handler->reset_motor();
441 Brean 723
//FIXME: Move Ticker to libMK/QTCommunication.cpp
724
//    Ticker->setInterval(2000);
725
//    TickerEvent[4] = false;
158 KeyOz 726
}
727
 
442 Brean 728
void MKTool::slot_Motortest(sMotorData p_Motor)
337 KeyOz 729
{
399 Brean 730
    handler->motor_test(p_Motor);
337 KeyOz 731
}
732
 
733
// Motormixer-Einstellungen anzeigen
307 KeyOz 734
void MKTool::slot_ac_MotorMixer()
735
{
396 Brean 736
    f_MotorMixer->set_Objects(handler, Settings);
440 Brean 737
    handler->read_motor_mixer();
307 KeyOz 738
 
739
    if (f_MotorMixer->exec()==QDialog::Accepted)
740
    {
741
    }
742
}
743
 
337 KeyOz 744
// LCD Anzeigen
227 KeyOz 745
void MKTool::slot_ac_LCD()
746
{
747
    if (!f_LCD->isVisible())
748
    {
306 KeyOz 749
        delete f_LCD;
227 KeyOz 750
        f_LCD = new dlg_LCD(this);
751
 
752
        // LCD auf / ab
753
        connect(f_LCD->pb_LCDup,   SIGNAL(clicked()), this, SLOT(slot_LCD_UP()));
754
        connect(f_LCD->pb_LCDdown, SIGNAL(clicked()), this, SLOT(slot_LCD_DOWN()));
755
        f_LCD->show();
399 Brean 756
        handler->show_lcd();
440 Brean 757
        //FIXME: replace ticker with something else???
441 Brean 758
        //Ticker->setInterval(500);
759
        //TickerEvent[2] = true;
227 KeyOz 760
    }
761
}
762
 
337 KeyOz 763
// Map-Fenster anzeigen
305 KeyOz 764
void MKTool::slot_ac_Map()
765
{
766
    if (!f_Map->isVisible())
767
    {
768
        f_Map->show();
769
    }
770
}
771
 
358 KeyOz 772
void MKTool::slot_MAP_SetWayPoints(QList<sWayPoint> l_WayPoints)
773
{
774
    double Longitude, Latitude;
775
 
399 Brean 776
    // delete waypoint-list
777
    handler->delete_waypoints();
391 Brean 778
    ToolBox::wait(SLEEP);
358 KeyOz 779
 
780
    for (int z = 0; z < l_WayPoints.count(); z++)
781
    {
782
        Longitude = l_WayPoints[z].Longitude;
783
        Latitude  = l_WayPoints[z].Latitude;
784
 
785
        if (Longitude < 100)
786
            Longitude *= 10000000+0.5;
787
 
788
        if (Latitude < 100)
789
            Latitude *= 10000000+0.5;
790
 
399 Brean 791
        Waypoint_t WayPoint;
358 KeyOz 792
        //fülle Wegpunkt-Daten
793
        WayPoint.Position.Altitude = 0;
794
        WayPoint.Position.Longitude = int32_t(Longitude);
795
        WayPoint.Position.Latitude =  int32_t(Latitude);
796
        WayPoint.Position.Status = NEWDATA;
797
        WayPoint.Heading = -1;
798
        WayPoint.ToleranceRadius = 5;
799
        WayPoint.HoldTime = l_WayPoints[z].Time;
800
        WayPoint.Event_Flag = 0;
801
        WayPoint.reserve[0] = 0; // reserve
802
        WayPoint.reserve[1] = 0; // reserve
803
        WayPoint.reserve[2] = 0; // reserve
804
        WayPoint.reserve[3] = 0; // reserve
805
 
399 Brean 806
        handler->add_waypoint(WayPoint);
358 KeyOz 807
//        ToolBox::Wait(SLEEP);
808
    }
809
}
810
 
306 KeyOz 811
void MKTool::slot_MAP_SetTarget(sWayPoint Target)
812
{
315 KeyOz 813
 
814
    QString s_Lon, s_Lat;
815
    QTextStream t_Lon(&s_Lon);
816
    QTextStream t_Lat(&s_Lat);
817
 
818
    t_Lon.setRealNumberPrecision(9);
819
    t_Lat.setRealNumberPrecision(9);
820
    t_Lon << Target.Longitude;
821
    t_Lat << Target.Latitude;
822
 
823
    le_TarLong->setText(s_Lon);
824
    le_TarLat->setText(s_Lat);
306 KeyOz 825
    sb_TarTime->setValue(Target.Time);
305 KeyOz 826
 
358 KeyOz 827
    slot_pb_SendTarget();
306 KeyOz 828
}
829
 
158 KeyOz 830
void MKTool::slot_ac_Config()
831
{
162 KeyOz 832
    set_Analog Old_Analog1;
158 KeyOz 833
 
162 KeyOz 834
    Old_Analog1 = Settings->Analog1;
835
 
158 KeyOz 836
    dlg_Config *f_Config = new dlg_Config(this);
442 Brean 837
    f_Config->set_Settings(Settings, data->mode.id);
158 KeyOz 838
 
839
    if (f_Config->exec()==QDialog::Accepted)
840
    {
841
        Settings = f_Config->get_Settings();
442 Brean 842
        Settings->write_Settings_Analog(data->mode.id);
158 KeyOz 843
 
163 KeyOz 844
        // Plotter neu einrichten
845
        if (Old_Analog1.PlotView != Settings->Analog1.PlotView)
158 KeyOz 846
        {
163 KeyOz 847
            config_Plot();
158 KeyOz 848
        }
849
 
163 KeyOz 850
        // CVS-Datei neu anlegen.
241 KeyOz 851
        if ((logger->is_active()) && (Old_Analog1.LogView != Settings->Analog1.LogView))
158 KeyOz 852
        {
239 Brean 853
            logger->close();
240 Brean 854
            logger->start_Log();
158 KeyOz 855
        }
856
 
857
    }
858
}
859
 
239 Brean 860
//aktualisiere Logging-Status
241 KeyOz 861
void MKTool::update_Log()
862
{
239 Brean 863
    if (logger->is_active())
864
    {
272 KeyOz 865
 
358 KeyOz 866
        ac_RecordCSV->setText(tr("Log Stop"));
239 Brean 867
        lb_Status->setText(tr("Log-Record gestartet."));
868
    }
869
    else
870
    {
358 KeyOz 871
        ac_RecordCSV->setText(tr("Log Aufzeichnen"));
239 Brean 872
        lb_Status->setText(tr("Log-Record gestopt."));
873
    }
874
}
875
 
876
//starte/stoppe Logging, wenn auf den entsprechenden Button gedrückt wurde
877
void MKTool::slot_RecordLog()
878
{
879
    if (!logger->is_active())
880
        logger->start_Log();
881
    else
882
        logger->close();
241 KeyOz 883
 
239 Brean 884
    update_Log();
885
}
886
 
159 KeyOz 887
void MKTool::slot_ac_Preferences()
888
{
889
    dlg_Preferences *f_Preferences = new dlg_Preferences(this);
890
 
166 KeyOz 891
    Settings->TTY.Port = le_Port->text();
163 KeyOz 892
    f_Preferences->set_Settings(Settings);
893
 
159 KeyOz 894
    if (f_Preferences->exec()==QDialog::Accepted)
895
    {
163 KeyOz 896
        Settings = f_Preferences->get_Settings();
897
        Settings->write_Settings();
166 KeyOz 898
        le_Port->setText(Settings->TTY.Port);
899
        config_Plot();
159 KeyOz 900
    }
901
}
902
 
158 KeyOz 903
void MKTool::slot_ac_StartPlotter()
904
{
905
    if (ac_StartPlotter->isChecked())
906
    {
199 KeyOz 907
        lb_Status->setText(tr("Datenplotter gestartet."));
358 KeyOz 908
        ac_StartPlotter->setText(tr("Stop Plotter"));
909
        pb_StartPlotter->setText(tr("Stop Plotter"));
158 KeyOz 910
    }
911
    else
912
    {
199 KeyOz 913
        lb_Status->setText(tr("Datenplotter gestopt."));
358 KeyOz 914
        ac_StartPlotter->setText(tr("Start Plotter"));
915
        pb_StartPlotter->setText(tr("Start Plotter"));
158 KeyOz 916
    }
917
}
918
 
919
void MKTool::slot_ac_View()
920
{
227 KeyOz 921
    int Aktive = -1;
158 KeyOz 922
 
923
    QAction *Action = (QAction*)sender();
924
 
925
    if (Action->objectName() == QString("ac_View0"))
926
        Aktive = 0;
927
    if (Action->objectName() == QString("ac_View1"))
928
        Aktive = 1;
929
    if (Action->objectName() == QString("ac_View2"))
930
        Aktive = 2;
931
    if (Action->objectName() == QString("ac_View3"))
932
        Aktive = 3;
933
    if (Action->objectName() == QString("ac_View4"))
934
        Aktive = 4;
935
    if (Action->objectName() == QString("ac_View5"))
936
        Aktive = 5;
272 KeyOz 937
    if (Action->objectName() == QString("ac_View6"))
938
        Aktive = 6;
158 KeyOz 939
 
940
    QString TabName = QString("Tab_%1").arg(Aktive);
941
 
942
    if (!Action->isChecked())
943
    {
944
        for (int a = 0; a < tab_Main->count(); a++)
945
        {
946
            if (tab_Main->widget(a)->objectName() == TabName)
947
            {
948
                tab_Main->removeTab(a);
949
            }
950
        }
951
    }
952
    else
953
    {
227 KeyOz 954
        tab_Main->insertTab(Aktive, TabWidgets[Aktive], Action->icon(), Action->text());
158 KeyOz 955
    }
956
}
957
 
199 KeyOz 958
void MKTool::slot_ac_FastNavi() // DONE NC 0.12i
158 KeyOz 959
{
199 KeyOz 960
    if (!ac_NoNavi->isChecked())
158 KeyOz 961
    {
199 KeyOz 962
        if (ac_FastNavi->isChecked())
166 KeyOz 963
        {
199 KeyOz 964
            lb_Status->setText(tr("Fordere schnelle NaviDaten an."));
399 Brean 965
            handler->set_navictrl_debug(Settings->Data.Navi_Fast / 10);
199 KeyOz 966
        }
967
        else
968
        {
969
            lb_Status->setText(tr("Fordere langsame NaviDaten an."));
399 Brean 970
            handler->set_navictrl_debug(Settings->Data.Navi_Slow / 10);
199 KeyOz 971
        }
972
    }
973
}
974
 
975
void MKTool::slot_ac_NoNavi() // DONE NC 0.12i
976
{
977
    if (ac_NoNavi->isChecked())
978
    {
979
        lb_Status->setText(tr("NaviDaten abstellen."));
399 Brean 980
        handler->stop_navictrl_debug();
199 KeyOz 981
    }
982
    else
983
    {
984
        if (ac_FastNavi->isChecked())
985
        {
986
            lb_Status->setText(tr("Fordere schnelle NaviDaten an."));
399 Brean 987
            handler->set_navictrl_debug(Settings->Data.Navi_Fast / 10);
199 KeyOz 988
        }
989
        else
990
        {
991
            lb_Status->setText(tr("Fordere langsame NaviDaten an."));
399 Brean 992
            handler->set_navictrl_debug(Settings->Data.Navi_Slow / 10);
199 KeyOz 993
        }
994
    }
995
}
996
 
997
void MKTool::slot_ac_FastDebug() // DONE 0.71g
998
{
999
    if (!ac_NoDebug->isChecked())
1000
    {
1001
        if (ac_FastDebug->isChecked())
1002
        {
1003
            lb_Status->setText(tr("Fordere schnelle DebugDaten an."));
399 Brean 1004
            handler->set_all_debug(Settings->Data.Debug_Fast / 10);
166 KeyOz 1005
        }
1006
        else
1007
        {
199 KeyOz 1008
            lb_Status->setText(tr("Fordere langsame DebugDaten an."));
399 Brean 1009
            handler->set_all_debug(Settings->Data.Debug_Slow / 10);
166 KeyOz 1010
        }
1011
    }
1012
}
1013
 
199 KeyOz 1014
void MKTool::slot_ac_NoDebug() // DONE 0.71g
166 KeyOz 1015
{
199 KeyOz 1016
    if (ac_NoDebug->isChecked())
166 KeyOz 1017
    {
199 KeyOz 1018
        lb_Status->setText(tr("DebugDaten abstellen."));
441 Brean 1019
//FIXME: Move Ticker to libMK/QTCommunication.cpp
1020
//        TickerEvent[3] = false;
399 Brean 1021
        handler->stop_all_debug();
166 KeyOz 1022
    }
158 KeyOz 1023
    else
1024
    {
167 KeyOz 1025
        // Wenn MK3MAG dann andauernd Daten neu anfragen.
441 Brean 1026
//FIXME: Move Ticker to libMK/QTCommunication.cpp
440 Brean 1027
/*        if (Mode.ID == ADDRESS_MK3MAG)
1028
            TickerEvent[3] = true;*/
167 KeyOz 1029
 
199 KeyOz 1030
        if (ac_FastDebug->isChecked())
166 KeyOz 1031
        {
199 KeyOz 1032
            lb_Status->setText(tr("Fordere schnelle DebugDaten an."));
399 Brean 1033
            handler->set_all_debug(Settings->Data.Debug_Fast / 10);
166 KeyOz 1034
        }
1035
        else
1036
        {
199 KeyOz 1037
            lb_Status->setText(tr("Fordere langsame DebugDaten an."));
399 Brean 1038
            handler->set_all_debug(Settings->Data.Debug_Slow / 10);
166 KeyOz 1039
        }
1040
    }
158 KeyOz 1041
}
1042
 
1043
void MKTool::slot_ac_About()
1044
{
1045
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
1046
}
1047
 
159 KeyOz 1048
void MKTool::slot_ac_GetLabels() // DONE 0.71g
158 KeyOz 1049
{
199 KeyOz 1050
    lb_Status->setText(tr("Analoglabels auslesen."));
399 Brean 1051
    handler->get_analog();
158 KeyOz 1052
}
1053
 
199 KeyOz 1054
void MKTool::slot_ac_StartServer()
1055
{
1056
    if (ac_StartServer->isChecked())
1057
    {
306 KeyOz 1058
        lb_Status->setText(tr("KML-Server gestartet."));
1059
        KML_Server->start_Server(Settings->Server.Port.toInt(), Settings);
199 KeyOz 1060
    }
1061
    else
1062
    {
306 KeyOz 1063
        lb_Status->setText(tr("KML-Server gestopt."));
1064
        KML_Server->stop_Server();
199 KeyOz 1065
    }
1066
}
159 KeyOz 1067
 
227 KeyOz 1068
 
158 KeyOz 1069
//  Daten-Plotter
1070
/////////////////
1071
void MKTool::update_Plot()
1072
{
1073
    for (int a = 0; a < MaxAnalog; a++)
1074
    {
1075
        Plot[a]->setData(aID,aData[a],NextPlot - 1);
1076
    }
1077
 
166 KeyOz 1078
    if ((NextPlot > Settings->Data.Plotter_Count))
158 KeyOz 1079
    {
166 KeyOz 1080
        scroll_plot->setMaximum(NextPlot - Settings->Data.Plotter_Count);
158 KeyOz 1081
    }
1082
 
166 KeyOz 1083
    if ((scroll_plot->value() == NextPlot - (Settings->Data.Plotter_Count + 1)))
158 KeyOz 1084
    {
166 KeyOz 1085
        qwtPlot->setAxisScale(QwtPlot::xBottom,NextPlot - Settings->Data.Plotter_Count,NextPlot,0);
1086
        scroll_plot->setValue(NextPlot - Settings->Data.Plotter_Count);
158 KeyOz 1087
    }
1088
 
1089
    qwtPlot->replot();
1090
}
1091
 
1092
void MKTool::config_Plot()
1093
{
166 KeyOz 1094
//    qDebug("Plotter rekonfiguriert..!!");
1095
    qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0);
1096
 
158 KeyOz 1097
    for (int a = 0; a < MaxAnalog; a++)
1098
    {
1099
        Plot[a]->detach();
162 KeyOz 1100
        Plot[a]->setPen(QPen(QColor(Def_Colors[a])));
158 KeyOz 1101
 
162 KeyOz 1102
        if (Settings->Analog1.PlotView[a])
1103
        {
1104
            Plot[a]->setTitle(Settings->Analog1.Label[a]);
158 KeyOz 1105
            Plot[a]->attach(qwtPlot);
162 KeyOz 1106
        }
158 KeyOz 1107
    }
166 KeyOz 1108
    qwtPlot->replot();
158 KeyOz 1109
}
1110
 
1111
void MKTool::slot_ScrollPlot(int Pos)
1112
{
166 KeyOz 1113
    qwtPlot->setAxisScale(QwtPlot::xBottom,Pos,Pos + Settings->Data.Plotter_Count,0);
158 KeyOz 1114
    qwtPlot->replot();
1115
}
1116
 
1117
 
1118
// Firmeware-Update
1119
///////////////////
1120
void MKTool::slot_pb_Update()
1121
{
167 KeyOz 1122
    QString Device;
1123
    QString Hardware;
158 KeyOz 1124
 
167 KeyOz 1125
    if (rb_FC->isChecked())
1126
    {
1127
        Device   = "m644";
1128
        Hardware = "FlightCtrl";
1129
    }
1130
    else if (rb_MK3MAG->isChecked())
1131
    {
1132
        Device   = "m168";
1133
        Hardware = "MK3MAG";
1134
    }
1135
    else if (rb_BL->isChecked())
1136
    {
1137
        Device   = "m8";
1138
        Hardware = "BL-Ctrl";
1139
    }
166 KeyOz 1140
 
358 KeyOz 1141
    QString Message = trUtf8("Firmeware-Datei \n\n");
166 KeyOz 1142
    Message = Message + le_HexFile->text() + "\n\n";
358 KeyOz 1143
    Message = Message + trUtf8("an ") + Hardware + trUtf8(" mit AVRDUDE - Seriel & Bootloader über ") + le_Port->text() + trUtf8(" übertragen?\n");
166 KeyOz 1144
 
1145
    if (le_HexFile->text() == "")
162 KeyOz 1146
    {
166 KeyOz 1147
        QMessageBox::warning(this, QA_NAME, trUtf8("Bitte Firmeware-Datei wählen."), QMessageBox::Ok);
162 KeyOz 1148
    }
166 KeyOz 1149
    else if (QMessageBox::warning(this, QA_NAME, Message, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
1150
    {
306 KeyOz 1151
        QString Programm = Settings->DIR.AVRDUDE;
162 KeyOz 1152
 
166 KeyOz 1153
        QStringList Argumente;
162 KeyOz 1154
 
166 KeyOz 1155
        Update = new QProcess();
162 KeyOz 1156
 
396 Brean 1157
//FIXME: put this in QTCommunication.cpp
1158
/*        if (o_Connection->isOpen())
166 KeyOz 1159
        {
1160
            slot_OpenPort();
1161
        }
396 Brean 1162
*/
166 KeyOz 1163
        Argumente << "-P";
1164
        Argumente << le_Port->text();
1165
        Argumente << "-p";
1166
        Argumente << Device;
1167
        Argumente << "-c";
1168
        Argumente << "butterfly";
1169
        Argumente << "-b";
1170
        Argumente << "57600";
1171
        Argumente << "-U";
1172
        Argumente << "flash:w:" + le_HexFile->text();
1173
 
1174
//    QString Programm = "/home/Manuel/bin/avrdude -p m644 -P /dev/ttyS0 -c butterfly -b 57600 -U flash:w:/home/Manuel/Documents/Mikrokopter/Firmeware/FlightCtrl/Flight-Ctrl_MEGA644_V0_71h.hex";
1175
 
1176
        te_Shell->setText(""); // Ausgabefenster säubern
1177
 
1178
        connect(Update, SIGNAL(readyReadStandardOutput()), this, SLOT(slot_UpdateShell()) );
1179
        connect(Update, SIGNAL(readyReadStandardError()), this, SLOT(slot_UpdateShell()) );
1180
 
1181
        Update->start(Programm, Argumente); // Programmaufruf
1182
    }
158 KeyOz 1183
}
1184
 
1185
void MKTool::slot_UpdateShell()
1186
{
162 KeyOz 1187
    QByteArray Output;
158 KeyOz 1188
 
166 KeyOz 1189
    Output = Update->readAllStandardError(); // Shellausgabe an Variable
162 KeyOz 1190
    te_Shell->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1191
    te_Shell->insertPlainText(QString::fromUtf8(Output));
158 KeyOz 1192
 
166 KeyOz 1193
    Output = Update->readAll();
1194
    te_Shell->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1195
    te_Shell->insertPlainText(QString::fromUtf8(Output));
158 KeyOz 1196
}
1197
 
166 KeyOz 1198
void MKTool::slot_pb_HexFile()
1199
{
1200
    QString FileName = QFileDialog::getOpenFileName(this,trUtf8(("Firmeware-Datei wählen")),"",
1201
                                tr("Intel Hex(*.hex);;Alle Dateien (*)"));
1202
    if (!FileName.isEmpty())
1203
    {
1204
        le_HexFile->setText(FileName);
1205
    }
1206
}
158 KeyOz 1207
 
1208
 
167 KeyOz 1209
// Wechsel der Tabs erkennen
159 KeyOz 1210
void MKTool::slot_TabChanged(int Tab) // DONE 0.71g
158 KeyOz 1211
{
1212
    Tab = Tab;
162 KeyOz 1213
    if (tab_Main->count() != 0)
158 KeyOz 1214
    {
306 KeyOz 1215
        if ((tab_Main->currentWidget()->objectName() == QString("Tab_2")) && (f_Settings->listWidget->currentRow() == 1))
162 KeyOz 1216
        {
399 Brean 1217
//FIXME: Do we really need the ppm-channels if we change the page?
1218
// maybe this is a bug or the description on 
1219
// http://www.mikrokopter.com/ucwiki/en/SerialCommands
1220
// is WRONG!
1221
            handler->get_ppm_channels();
441 Brean 1222
//FIXME: Move Ticker to libMK/QTCommunication.cpp
1223
//            Ticker->setInterval(500);
1224
//            TickerEvent[1] = true;
162 KeyOz 1225
        }
1226
        else
1227
        {
441 Brean 1228
//FIXME: Move Ticker to libMK/QTCommunication.cpp
1229
//            Ticker->setInterval(2000);
1230
//            TickerEvent[1] = false;
162 KeyOz 1231
        }
159 KeyOz 1232
    }
158 KeyOz 1233
}
1234
 
167 KeyOz 1235
// LCD-Seiten weiterschalten
159 KeyOz 1236
void MKTool::slot_LCD_UP() // DONE 0.71g
158 KeyOz 1237
{
399 Brean 1238
    handler->lcd_up();
159 KeyOz 1239
}
1240
 
1241
void MKTool::slot_LCD_DOWN() // DONE 0.71g
1242
{
399 Brean 1243
    handler->lcd_down();
159 KeyOz 1244
}
1245
 
167 KeyOz 1246
// Settings aus MK lesen / in MK schreiben
199 KeyOz 1247
void MKTool::slot_GetFCSettings() // DONE 0.71g
159 KeyOz 1248
{
199 KeyOz 1249
    lb_Status->setText(tr("Lese FlightCtrl-Settings aus."));
399 Brean 1250
    handler->get_flightctrl_settings(f_Settings->sb_Set->value());
158 KeyOz 1251
}
1252
 
199 KeyOz 1253
void MKTool::slot_SetFCSettings() // DONE 0.71g
158 KeyOz 1254
{
399 Brean 1255
    handler->set_flightctrl_settings(f_Settings->GetFCSettings());
199 KeyOz 1256
    lb_Status->setText(tr("Schreibe FlightCtrl-Settings."));
158 KeyOz 1257
}
1258
 
159 KeyOz 1259
 
167 KeyOz 1260
// Save GUI-Preferences
1261
///////////////////////
1262
void MKTool::set_Preferences()
158 KeyOz 1263
{
163 KeyOz 1264
    Settings->GUI.TabViews.setBit(0, ac_View0->isChecked());
1265
    Settings->GUI.TabViews.setBit(1, ac_View1->isChecked());
1266
    Settings->GUI.TabViews.setBit(2, ac_View2->isChecked());
1267
    Settings->GUI.TabViews.setBit(3, ac_View3->isChecked());
1268
    Settings->GUI.TabViews.setBit(4, ac_View4->isChecked());
1269
    Settings->GUI.TabViews.setBit(5, ac_View5->isChecked());
227 KeyOz 1270
    Settings->GUI.TabViews.setBit(6, ac_View6->isChecked());
158 KeyOz 1271
 
227 KeyOz 1272
    Settings->GUI.ToolViews.setBit(0, tb_Allgemein->isVisibleTo(this));
1273
    Settings->GUI.ToolViews.setBit(1, tb_Werkzeuge->isVisibleTo(this));
1274
    Settings->GUI.ToolViews.setBit(2, tb_Debug->isVisibleTo(this));
1275
    Settings->GUI.ToolViews.setBit(3, tb_TTY->isVisibleTo(this));
1276
    Settings->GUI.ToolViews.setBit(4, tb_Hardware->isVisibleTo(this));
1277
 
162 KeyOz 1278
    Settings->GUI.Term_Info   = cb_ShowMSG->isChecked();
1279
    Settings->GUI.Term_Data   = cb_ShowData->isChecked();
1280
    Settings->GUI.Term_Always = cb_ShowAlways->isChecked();
166 KeyOz 1281
    Settings->GUI.Term_Send   = cb_ShowSend->isChecked();
167 KeyOz 1282
    Settings->GUI.isMax       = isMaximized();
1283
    Settings->GUI.Size        = size();
1284
    Settings->GUI.Point       = pos();
162 KeyOz 1285
 
163 KeyOz 1286
    Settings->TTY.Port = le_Port->text();
158 KeyOz 1287
}
1288
 
1289
void MKTool::show_DebugData()
1290
{
441 Brean 1291
//FIXME: log analogdata in libMK/Communication.h or libMK/Parser.h
440 Brean 1292
/*    if (logger->is_active())
1293
        logger->write(AnalogData);*/
158 KeyOz 1294
 
1295
    if (ac_StartPlotter->isChecked())
1296
    {
1297
        aID[NextPlot] = NextPlot;
440 Brean 1298
        //FIXME: get analogData from handler
1299
        /*
158 KeyOz 1300
        for (int a = 0; a < MaxAnalog; a++)
1301
        {
1302
            aData[a][NextPlot] = AnalogData[a];
440 Brean 1303
        }*/
158 KeyOz 1304
        NextPlot++;
1305
 
1306
        if ((tab_Main->currentWidget()->objectName() == QString("Tab_1")))
1307
            update_Plot();
1308
    }
1309
 
441 Brean 1310
    //fill labels with analog values from data
1311
    for (int i = 0; i < 32; i++) {
1312
        le_Analog[i]->setText(QString("%1").arg(data->analogData[i]));
1313
    }
227 KeyOz 1314
 
442 Brean 1315
    if ((data->mode.id == ADDRESS_FC) && (FCSettings[P_GYRO_ACC_FAKTOR] > 0))
227 KeyOz 1316
    {
441 Brean 1317
        //set battery
1318
        //TODO: save battery, compas and link quality directly in data (data->battery)
1319
        bar_UBAT->setValue(data->analogData[9]);
1320
        //link quality
1321
        bar_RX->setValue(data->analogData[10]);
1322
        //compas
1323
        Compass->setValue(data->analogData[8]);
227 KeyOz 1324
 
441 Brean 1325
        int Roll = (data->analogData[1] * FCSettings[P_GYRO_ACC_FAKTOR]) / 1024;
1326
        int Nick = (data->analogData[0] * FCSettings[P_GYRO_ACC_FAKTOR]) / 1024;
227 KeyOz 1327
 
1328
        if (Roll > 128)
1329
            Roll = Roll - 255;
1330
 
1331
        if (Nick > 128)
1332
            Nick = Nick - 255;
1333
 
1334
        Attitude->setAngle(Roll);
1335
        Attitude->setGradient(double(double(Nick) / 100.0));
1336
    }
158 KeyOz 1337
}
1338
 
449 Brean 1339
//FIXME: HERE!
1340
/*
199 KeyOz 1341
void MKTool::new_NaviData(sRxData RX)
1342
{
306 KeyOz 1343
//    qDebug("Navi-Data");
440 Brean 1344
    sNaviData navi = data->navi;
391 Brean 1345
    switch(RX.decode[N_NC_FLAGS])
306 KeyOz 1346
    {
358 KeyOz 1347
        case 0x01 : lb_Mode->setText(tr("Free")); break;
1348
        case 0x02 : lb_Mode->setText(tr("Position Hold")); break;
1349
        case 0x04 : lb_Mode->setText(tr("Coming Home")); break;
1350
        case 0x08 : lb_Mode->setText(tr("Range Limit")); break;
1351
        case 0x10 : lb_Mode->setText(tr("Serial Error")); break;
1352
        case 0x20 : lb_Mode->setText(tr("Target reached")); break;
1353
        case 0x40 : lb_Mode->setText(tr("Manual Control")); break;
306 KeyOz 1354
    }
1355
 
440 Brean 1356
    navi.Current.Longitude = Parser::dataToLong(RX.decode, N_CUR_LONGITUDE, true);
1357
    navi.Current.Latitude  = Parser::dataToLong(RX.decode, N_CUR_LATITUDE,  true);
1358
    navi.Current.Altitude  = Parser::dataToLong(RX.decode, N_CUR_ALTITUDE,  true);
1359
    navi.Target.Longitude  = Parser::dataToLong(RX.decode, N_TAR_LONGITUDE, true);
1360
    navi.Target.Latitude   = Parser::dataToLong(RX.decode, N_TAR_LATITUDE,  true);
1361
    navi.Target.Altitude   = Parser::dataToLong(RX.decode, N_TAR_ALTITUDE,  true);
199 KeyOz 1362
 
391 Brean 1363
    le_CDistance->setText(QString("%1 cm").arg(Parser::dataToInt(RX.decode, N_HOME_DISTANCE)));
1364
    le_CWPA->setText(QString("%1").arg(RX.decode[N_WP_INDEX]));
1365
    le_CWPT->setText(QString("%1").arg(RX.decode[N_WP_NUMBER]));
1366
    le_CSats->setText(QString("%1").arg(RX.decode[N_SATS_IN_USER]));
227 KeyOz 1367
 
391 Brean 1368
    qwt_Rate->setValue(double(Parser::dataToInt(RX.decode, N_VARIOMETER, true)));
227 KeyOz 1369
 
391 Brean 1370
    le_CTime->setText(QString("%1 sec.").arg(Parser::dataToInt(RX.decode, N_FLYING_TIME)));
227 KeyOz 1371
 
391 Brean 1372
    bar_UBAT->setValue(RX.decode[N_UBAT]);
227 KeyOz 1373
 
391 Brean 1374
    double Speed = double((Parser::dataToLong(RX.decode, N_GROUND_SPEED)) / 10.0);
227 KeyOz 1375
 
1376
    if ((Speed > 4.5) && SpeedMeter->property("END") == 5)
1377
    {
1378
        SpeedMeter->setRange(0.0, 10.0);
1379
        SpeedMeter->setScale(1, 2, 1);
1380
        SpeedMeter->setProperty("END", 10);
1381
    }
1382
 
1383
    if ((Speed > 9) && SpeedMeter->property("END") == 10)
1384
    {
1385
        SpeedMeter->setRange(0.0, 20.0);
1386
        SpeedMeter->setScale(1, 2, 2);
1387
        SpeedMeter->setProperty("END", 20);
1388
    }
1389
 
1390
    SpeedMeter->setValue(Speed);
1391
 
391 Brean 1392
    Compass->setValue(Parser::dataToInt(RX.decode, N_COMAPSS_HEADING)); //(68)
227 KeyOz 1393
 
391 Brean 1394
    bar_RX->setValue(RX.decode[N_RC_QUALITY]);
227 KeyOz 1395
 
391 Brean 1396
    int Nick = RX.decode[N_ANGLE_NICK];
1397
    int Roll = RX.decode[N_ANGLE_ROLL];
227 KeyOz 1398
 
1399
    if (Roll > 128)
1400
        Roll = Roll - 255;
1401
 
1402
    if (Nick > 128)
1403
        Nick = Nick - 255;
1404
 
1405
    Attitude->setAngle(Roll);
234 KeyOz 1406
    Attitude->setGradient(double(0.0 - (double(Nick) / 100.0)));
227 KeyOz 1407
 
440 Brean 1408
    sNaviData naviData;
1409
 
1410
    naviData.Longitude = Parser::getFloat(navi.Current.Longitude,7);
1411
    naviData.Latitude  = Parser::getFloat(navi.Current.Latitude,7);
1412
    naviData.Altitude  = Parser::getFloat(navi.Current.Altitude,3);
199 KeyOz 1413
 
440 Brean 1414
    le_CurLong->setText(QString::number(naviData.Longitude));
1415
    le_CurLat->setText(QString::number(naviData.Latitude));
199 KeyOz 1416
 
440 Brean 1417
    KML_Server->store_NaviString(naviData);
199 KeyOz 1418
 
440 Brean 1419
    f_Map->add_Position(naviData.Longitude, naviData.Latitude);
306 KeyOz 1420
 
272 KeyOz 1421
    if ((QMK_Server->property("Connect")) == true)
227 KeyOz 1422
    {
440 Brean 1423
//        qDebug("Send Data to Server...");
1424
        QMK_Server->NewPosition(naviData);
227 KeyOz 1425
    }
199 KeyOz 1426
}
449 Brean 1427
*/
272 KeyOz 1428
// Kopter-Kommunikations-Bereich, Befehle senden und Daten empfangen
1429
////////////////////////////////////////////////////////////////////
158 KeyOz 1430
 
1431
// Neues Datenpacket empfangen -> Verarbeiten
449 Brean 1432
//FIXME: HERE!
1433
/*void MKTool::slot_newData(sRxData RX) // DONE 0.71g
158 KeyOz 1434
{
393 Brean 1435
    //handler->receiveData(RX)
162 KeyOz 1436
 
272 KeyOz 1437
    // TODO: Roh-Daten senden zum QMK-Server dazu Sendebuffer bauen.
1438
    if ((QMK_Server->property("Connect")) == true)
1439
    {
1440
//        QMK_Server->send_RawData(RX.String);
1441
    }
1442
 
393 Brean 1443
    slot_showTerminal(1, QString(RX.str.c_str()));
158 KeyOz 1444
}
449 Brean 1445
*/
250 KeyOz 1446
void MKTool::slot_showTerminal(int Typ, QString Text)
158 KeyOz 1447
{
250 KeyOz 1448
    switch(Typ)
158 KeyOz 1449
    {
250 KeyOz 1450
        case 1 :
158 KeyOz 1451
        {
250 KeyOz 1452
            if ((cb_ShowData->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked())))
158 KeyOz 1453
            {
250 KeyOz 1454
                te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1455
                te_RX->insertHtml("<span style=\"color:#00008b;\">" + Text + "<br /></span>");
158 KeyOz 1456
            }
250 KeyOz 1457
        }
1458
        break;
1459
        case 2 :
1460
        {
1461
            if ((cb_ShowMSG->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked())))
158 KeyOz 1462
            {
307 KeyOz 1463
                if (Text.length() > 0)
1464
                {
1465
                    te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1466
                    te_RX->insertHtml("<span style=\"color:#008b00;\">" + Text + "</span><br />");
1467
                }
158 KeyOz 1468
            }
1469
        }
250 KeyOz 1470
        break;
1471
        case 3 :
158 KeyOz 1472
        {
250 KeyOz 1473
            if (cb_ShowSend->isChecked())
158 KeyOz 1474
            {
250 KeyOz 1475
                te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1476
                te_RX->insertHtml("<span style='color:#8b0000;'>" + Text + "<br /></span>");
158 KeyOz 1477
            }
1478
        }
250 KeyOz 1479
        break;
158 KeyOz 1480
    }
1481
}
1482
 
272 KeyOz 1483
// Verbindung zum Kopter herstellen / Trennen
158 KeyOz 1484
void MKTool::slot_OpenPort()
1485
{
440 Brean 1486
//FIXME: Put this in libMK/QTCommunication.cpp
396 Brean 1487
/*
306 KeyOz 1488
    if (o_Connection->isOpen())
250 KeyOz 1489
    {
199 KeyOz 1490
        TX_Data[0] = Settings->Data.Debug_Off / 10;
306 KeyOz 1491
        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
391 Brean 1492
        ToolBox::wait(SLEEP);
158 KeyOz 1493
 
199 KeyOz 1494
        if (Mode.ID == ADDRESS_NC)
1495
        {
1496
            TX_Data[0] = Settings->Data.Navi_Off / 10;
306 KeyOz 1497
            o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
391 Brean 1498
            ToolBox::wait(SLEEP);
199 KeyOz 1499
        }
1500
 
272 KeyOz 1501
        if (Mode.ID == ADDRESS_FC)
199 KeyOz 1502
        {
1503
            TX_Data[0] = 0;
1504
            TX_Data[1] = 0;
1505
            TX_Data[2] = 0;
1506
            TX_Data[3] = 0;
306 KeyOz 1507
            o_Connection->send_Cmd('t', ADDRESS_FC, TX_Data, 4, false);
391 Brean 1508
            ToolBox::wait(SLEEP);
199 KeyOz 1509
        }
250 KeyOz 1510
 
306 KeyOz 1511
        o_Connection->Close();
250 KeyOz 1512
 
358 KeyOz 1513
        ac_ConnectTTY->setText(tr("Kopter Verbinden"));
199 KeyOz 1514
        le_Port->setEnabled(true);
1515
 
167 KeyOz 1516
        Ticker->stop();
158 KeyOz 1517
    }
1518
    else
1519
    {
263 KeyOz 1520
        int i_Type;
1521
        if (le_Port->text().contains(QString("IP:")))
158 KeyOz 1522
        {
263 KeyOz 1523
            i_Type = C_IP;
1524
        }
1525
        else
1526
        {
1527
            i_Type = C_TTY;
1528
        }
1529
 
306 KeyOz 1530
        if (o_Connection->Open(i_Type, le_Port->text()))
263 KeyOz 1531
        {
358 KeyOz 1532
            ac_ConnectTTY->setText(tr("Kopter Trennen"));
199 KeyOz 1533
            le_Port->setEnabled(false);
158 KeyOz 1534
 
306 KeyOz 1535
            o_Connection->send_Cmd('v', ADDRESS_ALL, TX_Data, 0, true);
159 KeyOz 1536
 
167 KeyOz 1537
            Ticker->start(2000);
158 KeyOz 1538
        }
1539
    }
396 Brean 1540
*/
158 KeyOz 1541
}
1542
 
1543
// Programm beenden
1544
///////////////////
162 KeyOz 1545
 
1546
MKTool::~MKTool()
158 KeyOz 1547
{
440 Brean 1548
//FIXME: Put this in libMK/QTCommunication.cpp
396 Brean 1549
/*
306 KeyOz 1550
    if (o_Connection->isOpen())
158 KeyOz 1551
    {
306 KeyOz 1552
        o_Connection->Close();
158 KeyOz 1553
    }
396 Brean 1554
*/
167 KeyOz 1555
    set_Preferences();
162 KeyOz 1556
    Settings->write_Settings();
158 KeyOz 1557
 
239 Brean 1558
    logger->close();
158 KeyOz 1559
}