MainToolBarController.cc 3.89 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"
dogmaphobic's avatar
dogmaphobic committed
35
#include "UASMessageView.h"
36 37
#include "UASMessageHandler.h"
#include "QGCApplication.h"
38
#include "MultiVehicleManager.h"
39
#include "UAS.h"
dogmaphobic's avatar
dogmaphobic committed
40

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

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

}

62
void MainToolBarController::_activeVehicleChanged(Vehicle* vehicle)
63
{
64 65
    // Disconnect the previous one (if any)
    if (_vehicle) {
66
        disconnect(_vehicle->autopilotPlugin(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
67
        _mav = NULL;
68
        _vehicle = NULL;
69
    }
dogmaphobic's avatar
dogmaphobic committed
70

dogmaphobic's avatar
dogmaphobic committed
71
    // Connect new system
72
    if (vehicle)
dogmaphobic's avatar
dogmaphobic committed
73
    {
74 75
        _vehicle = vehicle;
        _mav = vehicle->uas();
76
        connect(_vehicle->autopilotPlugin(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
dogmaphobic's avatar
dogmaphobic committed
77
    }
78 79
}

dogmaphobic's avatar
dogmaphobic committed
80
void MainToolBarController::_telemetryChanged(LinkInterface*, unsigned rxerrors, unsigned fixed, int rssi, int remrssi, unsigned txbuf, unsigned noise, unsigned remnoise)
81
{
82 83
    if(_telemetryLRSSI != rssi) {
        _telemetryLRSSI = rssi;
84
        emit telemetryLRSSIChanged(_telemetryLRSSI);
85
    }
86 87
    if(_telemetryRRSSI != remrssi) {
        _telemetryRRSSI = remrssi;
Don Gagne's avatar
Don Gagne committed
88
        emit telemetryRRSSIChanged(_telemetryRRSSI);
89
    }
dogmaphobic's avatar
dogmaphobic committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    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
110 111
}

112
void MainToolBarController::_setProgressBarValue(float value)
113 114 115 116
{
    _progressBarValue = value;
    emit progressBarValueChanged(value);
}