Subversion Repositories Projects

Rev

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