Subversion Repositories Projects

Rev

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

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