MainToolBarController.cc 3.71 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
    connect(qgcApp()->toolbox()->mavlinkProtocol(),     &MAVLinkProtocol::radioStatusChanged, this, &MainToolBarController::_telemetryChanged);
51
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &MainToolBarController::_activeVehicleChanged);
dogmaphobic's avatar
dogmaphobic committed
52 53
}

54
MainToolBarController::~MainToolBarController()
dogmaphobic's avatar
dogmaphobic committed
55 56 57 58
{

}

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

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

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

109
void MainToolBarController::_setProgressBarValue(float value)
110 111 112 113
{
    _progressBarValue = value;
    emit progressBarValueChanged(value);
}