Commit 96d573bc authored by Michael Carpenter's avatar Michael Carpenter

Change for an initial SeriaLink, and QGCToolBar having a selection menu next to the connect button

parent 1f55e9c1
......@@ -52,6 +52,7 @@ This file is part of the QGROUNDCONTROL project
#endif
#include "UDPLink.h"
#include "MAVLinkSimulationLink.h"
#include "SerialLink.h"
/**
......@@ -157,6 +158,11 @@ QGCCore::QGCCore(int &argc, char* argv[]) : QApplication(argc, argv)
MAVLinkSimulationLink* simulationLink = new MAVLinkSimulationLink(":/demo-log.txt");
simulationLink->disconnect();
//We want to have a default serial link available for "quick" connecting.
SerialLink *slink = new SerialLink();
MainWindow::instance()->addLink(slink);
mainWindow = MainWindow::instance(splashScreen);
// Remove splash screen
......
......@@ -24,6 +24,7 @@ This file is part of the QGROUNDCONTROL project
#include <QToolButton>
#include <QLabel>
#include <QSpacerItem>
#include "SerialLink.h"
#include "QGCToolBar.h"
#include "UASManager.h"
#include "MainWindow.h"
......@@ -160,6 +161,11 @@ void QGCToolBar::createUI()
spacer->setStyleSheet("* { margin: 0px; background-color: transparent; min-height: 24px}");
addWidget(spacer);
portComboBox = new QComboBox(this);
portComboBox->setToolTip(tr("Choose the COM port to use"));
portComboBox->setEnabled(true);
portComboBox->setMinimumWidth(200);
addWidget(portComboBox);
connectButton = new QPushButton(tr("Connect"), this);
connectButton->setToolTip(tr("Connect wireless link to MAV"));
connectButton->setCheckable(true);
......@@ -523,12 +529,15 @@ void QGCToolBar::addLink(LinkInterface* link)
connect(currentLink, SIGNAL(connected(bool)), this, SLOT(updateLinkState(bool)));
updateLinkState(link->isConnected());
}
updateComboBox();
}
void QGCToolBar::removeLink(LinkInterface* link)
{
if (link == currentLink) {
currentLink = NULL;
//portComboBox->setEnabled(false);
//portComboBox->clear();
// XXX magic number
if (LinkManager::instance()->getLinks().count() > 2) {
currentLink = LinkManager::instance()->getLinks().last();
......@@ -537,6 +546,32 @@ void QGCToolBar::removeLink(LinkInterface* link)
connectButton->setText(tr("New Link"));
}
}
updateComboBox();
}
void QGCToolBar::updateComboBox()
{
portComboBox->clear();
for (int i=0;i<LinkManager::instance()->getLinks().count();i++)
{
SerialLink *slink = qobject_cast<SerialLink*>(LinkManager::instance()->getLinks()[i]);
if (slink)
{
//It's a serial link
QVector<QString> *portlist = slink->getCurrentPorts();
//if (!slink->isConnected())
//{
for (int j=0;j<portlist->size();j++)
{
portComboBox->addItem("Serial port:" + QString::number(i) + ":" + portlist->at(j));
}
//}
//We only really want to display from unconnected sources.
}
else
{
portComboBox->addItem(LinkManager::instance()->getLinks()[i]->getName());
}
}
}
void QGCToolBar::updateLinkState(bool connected)
......@@ -566,7 +601,25 @@ void QGCToolBar::connectLink(bool connect)
{
MainWindow::instance()->addLink();
} else if (connect) {
LinkManager::instance()->getLinks().last()->connect();
if (portComboBox->currentText().split(":").count()>2)
{
int linknum = portComboBox->currentText().split(":")[1].toInt();
SerialLink *link = qobject_cast<SerialLink*>(LinkManager::instance()->getLinks().at(linknum));
if (link)
{
QString portname = portComboBox->currentText().split(":")[2];
if (portname.indexOf('-') != -1)
{
portname = portname.split("-")[0];
}
link->setPortName(portname.trimmed());
}
link->connect();
}
else
{
LinkManager::instance()->getLinks().last()->connect();
}
} else if (!connect && LinkManager::instance()->getLinks().count() > 2) {
LinkManager::instance()->getLinks().last()->disconnect();
}
......
......@@ -30,6 +30,7 @@ This file is part of the QGROUNDCONTROL project
#include <QPushButton>
#include <QLabel>
#include <QProgressBar>
#include <QComboBox>
#include "UASInterface.h"
#include "QGCMAVLinkLogPlayer.h"
......@@ -88,7 +89,7 @@ protected:
void storeSettings();
void loadSettings();
void createUI();
void updateComboBox();
UASInterface* mav;
QToolButton* symbolButton;
QLabel* toolBarNameLabel;
......@@ -103,6 +104,7 @@ protected:
QProgressBar* toolBarBatteryBar;
QLabel* toolBarBatteryVoltageLabel;
QGCMAVLinkLogPlayer* player;
QComboBox *portComboBox;
bool changed;
float batteryPercent;
float batteryVoltage;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment