Subversion Repositories Projects

Rev

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