MainToolBarController.cc 4.18 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief QGC Main Tool Bar
 *   @author Gus Grubba <mavlink@grubba.com>
 */

#include <QQmlContext>
#include <QQmlEngine>

33
#include "MainToolBarController.h"
Don Gagne's avatar
Don Gagne committed
34
#include "ScreenToolsController.h"
35
#include "MainWindow.h"
dogmaphobic's avatar
dogmaphobic committed
36
#include "UASMessageView.h"
37 38
#include "UASMessageHandler.h"
#include "QGCApplication.h"
39
#include "MultiVehicleManager.h"
40
#include "UAS.h"
dogmaphobic's avatar
dogmaphobic committed
41

42 43
MainToolBarController::MainToolBarController(QObject* parent)
    : QObject(parent)
44
    , _vehicle(NULL)
Don Gagne's avatar
Don Gagne committed
45
    , _mav(NULL)
46
    , _progressBarValue(0.0f)
47 48
    , _telemetryRRSSI(0)
    , _telemetryLRSSI(0)
dogmaphobic's avatar
dogmaphobic committed
49
{
50
    _activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
51
    // RSSI (didn't like standard connection)
52
    connect(qgcApp()->toolbox()->mavlinkProtocol(),
53 54
        SIGNAL(radioStatusChanged(LinkInterface*, unsigned, unsigned, int, int, unsigned, unsigned, unsigned)), this,
        SLOT(_telemetryChanged(LinkInterface*, unsigned, unsigned, int, int, unsigned, unsigned, unsigned)));
55
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &MainToolBarController::_activeVehicleChanged);
dogmaphobic's avatar
dogmaphobic committed
56 57
}

58
MainToolBarController::~MainToolBarController()
dogmaphobic's avatar
dogmaphobic committed
59 60 61 62
{

}

63
void MainToolBarController::onSetupView()
64
{
65
    MainWindow::instance()->showSetupView();
66 67
}

68
void MainToolBarController::onPlanView()
69
{
70
    MainWindow::instance()->showPlanView();
71 72
}

73
void MainToolBarController::onFlyView()
dogmaphobic's avatar
dogmaphobic committed
74
{
75
    MainWindow::instance()->showFlyView();
dogmaphobic's avatar
dogmaphobic committed
76 77
}

78
void MainToolBarController::_activeVehicleChanged(Vehicle* vehicle)
79
{
80 81
    // Disconnect the previous one (if any)
    if (_vehicle) {
82
        disconnect(_vehicle->autopilotPlugin(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
83
        _mav = NULL;
84
        _vehicle = NULL;
85
    }
dogmaphobic's avatar
dogmaphobic committed
86

dogmaphobic's avatar
dogmaphobic committed
87
    // Connect new system
88
    if (vehicle)
dogmaphobic's avatar
dogmaphobic committed
89
    {
90 91
        _vehicle = vehicle;
        _mav = vehicle->uas();
92
        connect(_vehicle->autopilotPlugin(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
dogmaphobic's avatar
dogmaphobic committed
93
    }
94 95
}

dogmaphobic's avatar
dogmaphobic committed
96
void MainToolBarController::_telemetryChanged(LinkInterface*, unsigned rxerrors, unsigned fixed, int rssi, int remrssi, unsigned txbuf, unsigned noise, unsigned remnoise)
97
{
98 99
    if(_telemetryLRSSI != rssi) {
        _telemetryLRSSI = rssi;
100
        emit telemetryLRSSIChanged(_telemetryLRSSI);
101
    }
102 103
    if(_telemetryRRSSI != remrssi) {
        _telemetryRRSSI = remrssi;
Don Gagne's avatar
Don Gagne committed
104
        emit telemetryRRSSIChanged(_telemetryRRSSI);
105
    }
dogmaphobic's avatar
dogmaphobic committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    if(_telemetryRXErrors != rxerrors) {
        _telemetryRXErrors = rxerrors;
        emit telemetryRXErrorsChanged(_telemetryRXErrors);
    }
    if(_telemetryFixed != fixed) {
        _telemetryFixed = fixed;
        emit telemetryFixedChanged(_telemetryFixed);
    }
    if(_telemetryTXBuffer != txbuf) {
        _telemetryTXBuffer = txbuf;
        emit telemetryTXBufferChanged(_telemetryTXBuffer);
    }
    if(_telemetryLNoise != noise) {
        _telemetryLNoise = noise;
        emit telemetryLNoiseChanged(_telemetryLNoise);
    }
    if(_telemetryRNoise != remnoise) {
        _telemetryRNoise = remnoise;
        emit telemetryRNoiseChanged(_telemetryRNoise);
    }
dogmaphobic's avatar
dogmaphobic committed
126 127
}

128
void MainToolBarController::_setProgressBarValue(float value)
129 130 131 132
{
    _progressBarValue = value;
    emit progressBarValueChanged(value);
}