MainToolBarController.cc 2.71 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9 10 11 12 13 14 15 16 17 18 19


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

#include <QQmlContext>
#include <QQmlEngine>

20
#include "MainToolBarController.h"
Don Gagne's avatar
Don Gagne committed
21
#include "ScreenToolsController.h"
dogmaphobic's avatar
dogmaphobic committed
22
#include "UASMessageView.h"
23 24
#include "UASMessageHandler.h"
#include "QGCApplication.h"
25
#include "MultiVehicleManager.h"
26
#include "UAS.h"
27
#include "ParameterManager.h"
dogmaphobic's avatar
dogmaphobic committed
28

29 30
MainToolBarController::MainToolBarController(QObject* parent)
    : QObject(parent)
31
    , _vehicle(NULL)
Don Gagne's avatar
Don Gagne committed
32
    , _mav(NULL)
33 34
    , _telemetryRRSSI(0)
    , _telemetryLRSSI(0)
dogmaphobic's avatar
dogmaphobic committed
35
{
36
    _activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
37
    connect(qgcApp()->toolbox()->mavlinkProtocol(),     &MAVLinkProtocol::radioStatusChanged, this, &MainToolBarController::_telemetryChanged);
38
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &MainToolBarController::_activeVehicleChanged);
dogmaphobic's avatar
dogmaphobic committed
39 40
}

41
MainToolBarController::~MainToolBarController()
dogmaphobic's avatar
dogmaphobic committed
42 43 44 45
{

}

46
void MainToolBarController::_activeVehicleChanged(Vehicle* vehicle)
47
{
48 49
    // Disconnect the previous one (if any)
    if (_vehicle) {
50
        _mav = NULL;
51
        _vehicle = NULL;
52
    }
dogmaphobic's avatar
dogmaphobic committed
53

dogmaphobic's avatar
dogmaphobic committed
54
    // Connect new system
55
    if (vehicle)
dogmaphobic's avatar
dogmaphobic committed
56
    {
57 58
        _vehicle = vehicle;
        _mav = vehicle->uas();
dogmaphobic's avatar
dogmaphobic committed
59
    }
60 61
}

dogmaphobic's avatar
dogmaphobic committed
62
void MainToolBarController::_telemetryChanged(LinkInterface*, unsigned rxerrors, unsigned fixed, int rssi, int remrssi, unsigned txbuf, unsigned noise, unsigned remnoise)
63
{
64 65
    if(_telemetryLRSSI != rssi) {
        _telemetryLRSSI = rssi;
66
        emit telemetryLRSSIChanged(_telemetryLRSSI);
67
    }
68 69
    if(_telemetryRRSSI != remrssi) {
        _telemetryRRSSI = remrssi;
Don Gagne's avatar
Don Gagne committed
70
        emit telemetryRRSSIChanged(_telemetryRRSSI);
71
    }
dogmaphobic's avatar
dogmaphobic committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    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
92
}