MainToolBarController.cc 3.15 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
    , _progressBarValue(0.0f)
34 35
    , _telemetryRRSSI(0)
    , _telemetryLRSSI(0)
dogmaphobic's avatar
dogmaphobic committed
36
{
37
    _activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
38
    connect(qgcApp()->toolbox()->mavlinkProtocol(),     &MAVLinkProtocol::radioStatusChanged, this, &MainToolBarController::_telemetryChanged);
39
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &MainToolBarController::_activeVehicleChanged);
dogmaphobic's avatar
dogmaphobic committed
40 41
}

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

}

47
void MainToolBarController::_activeVehicleChanged(Vehicle* vehicle)
48
{
49 50
    // Disconnect the previous one (if any)
    if (_vehicle) {
51
        disconnect(_vehicle->parameterManager(), &ParameterManager::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
52
        _mav = NULL;
53
        _vehicle = NULL;
54
    }
dogmaphobic's avatar
dogmaphobic committed
55

dogmaphobic's avatar
dogmaphobic committed
56
    // Connect new system
57
    if (vehicle)
dogmaphobic's avatar
dogmaphobic committed
58
    {
59 60
        _vehicle = vehicle;
        _mav = vehicle->uas();
61
        connect(_vehicle->parameterManager(), &ParameterManager::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
dogmaphobic's avatar
dogmaphobic committed
62
    }
63 64
}

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

97
void MainToolBarController::_setProgressBarValue(float value)
98 99 100 101
{
    _progressBarValue = value;
    emit progressBarValueChanged(value);
}