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

42 43
MainToolBarController::MainToolBarController(QObject* parent)
    : QObject(parent)
44
    , _vehicle(NULL)
Don Gagne's avatar
Don Gagne committed
45
    , _mav(NULL)
46
    , _progressBarValue(0.0f)
47 48
    , _telemetryRRSSI(0)
    , _telemetryLRSSI(0)
49
    , _toolbarMessageVisible(false)
dogmaphobic's avatar
dogmaphobic committed
50
{
51
    _activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
dogmaphobic's avatar
dogmaphobic committed
52

53
    // RSSI (didn't like standard connection)
54
    connect(qgcApp()->toolbox()->mavlinkProtocol(),
55 56
        SIGNAL(radioStatusChanged(LinkInterface*, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned)), this,
        SLOT(_telemetryChanged(LinkInterface*, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned)));
dogmaphobic's avatar
dogmaphobic committed
57

58
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &MainToolBarController::_activeVehicleChanged);
dogmaphobic's avatar
dogmaphobic committed
59 60
}

61
MainToolBarController::~MainToolBarController()
dogmaphobic's avatar
dogmaphobic committed
62 63 64 65
{

}

66
void MainToolBarController::onSetupView()
67
{
68
    MainWindow::instance()->showSetupView();
69 70
}

71
void MainToolBarController::onPlanView()
72
{
73
    MainWindow::instance()->showPlanView();
74 75
}

76
void MainToolBarController::onFlyView()
dogmaphobic's avatar
dogmaphobic committed
77
{
78
    MainWindow::instance()->showFlyView();
dogmaphobic's avatar
dogmaphobic committed
79 80
}

81
void MainToolBarController::_activeVehicleChanged(Vehicle* vehicle)
82
{
83 84
    // Disconnect the previous one (if any)
    if (_vehicle) {
85
        disconnect(_vehicle->autopilotPlugin(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
86
        _mav = NULL;
87
        _vehicle = NULL;
88
    }
dogmaphobic's avatar
dogmaphobic committed
89

dogmaphobic's avatar
dogmaphobic committed
90
    // Connect new system
91
    if (vehicle)
dogmaphobic's avatar
dogmaphobic committed
92
    {
93 94
        _vehicle = vehicle;
        _mav = vehicle->uas();
95
        connect(_vehicle->autopilotPlugin(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
dogmaphobic's avatar
dogmaphobic committed
96
    }
97 98
}

99
void MainToolBarController::_telemetryChanged(LinkInterface*, unsigned, unsigned, unsigned rssi, unsigned remrssi, unsigned, unsigned, unsigned)
100
{
Don Gagne's avatar
Don Gagne committed
101 102 103
    if((unsigned)_telemetryLRSSI != rssi) {
        // According to the Silabs data sheet, the RSSI value is 0.5db per bit
        _telemetryLRSSI = rssi >> 1;
104
        emit telemetryLRSSIChanged(_telemetryLRSSI);
105
    }
Don Gagne's avatar
Don Gagne committed
106 107 108 109
    if((unsigned)_telemetryRRSSI != remrssi) {
        // According to the Silabs data sheet, the RSSI value is 0.5db per bit
        _telemetryRRSSI = remrssi >> 1;
        emit telemetryRRSSIChanged(_telemetryRRSSI);
110
    }
dogmaphobic's avatar
dogmaphobic committed
111 112
}

113
void MainToolBarController::_setProgressBarValue(float value)
114 115 116 117
{
    _progressBarValue = value;
    emit progressBarValueChanged(value);
}
Don Gagne's avatar
Don Gagne committed
118

119
void MainToolBarController::showToolBarMessage(const QString& message)
120 121
{
    _toolbarMessageQueueMutex.lock();
dogmaphobic's avatar
dogmaphobic committed
122

123
    if (_toolbarMessageQueue.count() == 0 && !_toolbarMessageVisible) {
124
        QTimer::singleShot(500, this, &MainToolBarController::_delayedShowToolBarMessage);
125
    }
dogmaphobic's avatar
dogmaphobic committed
126

127
    _toolbarMessageQueue += message;
dogmaphobic's avatar
dogmaphobic committed
128

129 130 131
    _toolbarMessageQueueMutex.unlock();
}

132
void MainToolBarController::_delayedShowToolBarMessage(void)
133 134
{
    QString messages;
dogmaphobic's avatar
dogmaphobic committed
135

136 137
    if (!_toolbarMessageVisible) {
        _toolbarMessageQueueMutex.lock();
dogmaphobic's avatar
dogmaphobic committed
138

139 140 141 142
        foreach (QString message, _toolbarMessageQueue) {
            messages += message + "\n";
        }
        _toolbarMessageQueue.clear();
dogmaphobic's avatar
dogmaphobic committed
143

144
        _toolbarMessageQueueMutex.unlock();
dogmaphobic's avatar
dogmaphobic committed
145

146 147 148 149 150 151 152
        if (!messages.isEmpty()) {
            _toolbarMessageVisible = true;
            emit showMessage(messages);
        }
    }
}

153
void MainToolBarController::onToolBarMessageClosed(void)
154 155 156
{
    _toolbarMessageVisible = false;
    _delayedShowToolBarMessage();
Don Gagne's avatar
Don Gagne committed
157
}
Don Gagne's avatar
Don Gagne committed
158 159 160 161 162

void MainToolBarController::showSettings(void)
{
    MainWindow::instance()->showSettings();
}
Don Gagne's avatar
Don Gagne committed
163 164 165 166 167

void MainToolBarController::manageLinks(void)
{
    MainWindow::instance()->manageLinks();
}