Subversion Repositories Projects

Rev

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