MainToolBarController.cc 3.12 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"
dogmaphobic's avatar
dogmaphobic committed
27

28 29
MainToolBarController::MainToolBarController(QObject* parent)
    : QObject(parent)
30
    , _vehicle(NULL)
Don Gagne's avatar
Don Gagne committed
31
    , _mav(NULL)
32
    , _progressBarValue(0.0f)
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
        disconnect(_vehicle->autopilotPlugin(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
51
        _mav = NULL;
52
        _vehicle = NULL;
53
    }
dogmaphobic's avatar
dogmaphobic committed
54

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

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

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