Commit 5d504847 authored by Don Gagne's avatar Don Gagne

Merge pull request #1571 from DonLakeFlyer/FitAndFinish

Fit and finish
parents 2025a83b eeca0a84
......@@ -150,7 +150,6 @@ INCLUDEPATH += \
src/QmlControls \
src/uas \
src/ui \
src/ui/configuration \
src/ui/flightdisplay \
src/ui/linechart \
src/ui/map \
......@@ -165,8 +164,6 @@ INCLUDEPATH += \
FORMS += \
src/QGCQmlWidgetHolder.ui \
src/ui/configuration/SerialSettingsDialog.ui \
src/ui/configuration/terminalconsole.ui \
src/ui/DebugConsole.ui \
src/ui/HDDisplay.ui \
src/ui/Linechart.ui \
......@@ -275,10 +272,6 @@ HEADERS += \
src/uas/UASManagerInterface.h \
src/uas/UASMessageHandler.h \
src/uas/UASWaypointManager.h \
src/ui/configuration/ApmHighlighter.h \
src/ui/configuration/console.h \
src/ui/configuration/SerialSettingsDialog.h \
src/ui/configuration/terminalconsole.h \
src/ui/DebugConsole.h \
src/ui/flightdisplay/FlightDisplay.h \
src/ui/HDDisplay.h \
......@@ -406,10 +399,6 @@ SOURCES += \
src/uas/UASManager.cc \
src/uas/UASMessageHandler.cc \
src/uas/UASWaypointManager.cc \
src/ui/configuration/ApmHighlighter.cc \
src/ui/configuration/console.cpp \
src/ui/configuration/SerialSettingsDialog.cc \
src/ui/configuration/terminalconsole.cpp \
src/ui/DebugConsole.cc \
src/ui/flightdisplay/FlightDisplay.cc \
src/ui/HDDisplay.cc \
......
......@@ -129,7 +129,7 @@ QGCView {
QGCLabel {
anchors.top: headingSpacer.bottom
width: parent.width - applyButton.width - 5
text: "Select you airframe type and specific vehicle bellow. Click 'Apply and Restart' when ready and your vehicle will be disconnected, rebooted to the new settings and re-connected."
text: "Select your airframe type and specific vehicle bellow. Click 'Apply and Restart' when ready and your vehicle will be disconnected, rebooted to the new settings and re-connected."
wrapMode: Text.WordWrap
}
......
......@@ -30,7 +30,7 @@
#include <QFont>
#include <QFontMetrics>
const double ScreenTools::_defaultFontPointSize = 12;
const double ScreenTools::_defaultFontPointSize = 13;
ScreenTools::ScreenTools()
{
......
......@@ -514,7 +514,7 @@ void MockLink::_handleParamRequestList(const mavlink_message_t& msg)
foreach(QString paramName, _mapParamName2Value[componentId].keys()) {
if (skipParam) {
// We've already sent the first param
skipParam = true;
skipParam = false;
paramIndex++;
} else {
char paramId[MAVLINK_MSG_ID_PARAM_VALUE_LEN];
......
......@@ -68,18 +68,22 @@ void MainWindowTest::_connectWindowClose_test(MAV_AUTOPILOT autopilot)
link->setAutopilotType(autopilot);
LinkManager::instance()->_addLink(link);
linkMgr->connectLink(link);
QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through
// Wait for the uas to work it's way through the various threads
QSignalSpy spyUas(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)));
QCOMPARE(spyUas.wait(5000), true);
// Cycle through all the top level views
_mainToolBar->onSetupView();
QTest::qWait(1000);
QTest::qWait(200);
_mainToolBar->onPlanView();
QTest::qWait(1000);
QTest::qWait(200);
_mainToolBar->onFlyView();
QTest::qWait(1000);
QTest::qWait(200);
_mainToolBar->onAnalyzeView();
QTest::qWait(1000);
QTest::qWait(200);
// On MainWindow close we should get a message box telling the user to disconnect first. Cancel should do nothing.
setExpectedMessageBox(QGCMessageBox::Cancel);
......
......@@ -62,8 +62,6 @@ This file is part of the QGROUNDCONTROL project
#include "UASRawStatusView.h"
#include "FlightDisplay.h"
#include "SetupView.h"
#include "SerialSettingsDialog.h"
#include "terminalconsole.h"
#include "QGCUASFileViewMulti.h"
#include "QGCApplication.h"
#include "QGCFileDialog.h"
......@@ -302,16 +300,14 @@ MainWindow::MainWindow(QSplashScreen* splashScreen)
_ui.actionPlan->setShortcut(QApplication::translate("MainWindow", "Meta+2", 0));
_ui.actionFlight->setShortcut(QApplication::translate("MainWindow", "Meta+3", 0));
_ui.actionAnalyze->setShortcut(QApplication::translate("MainWindow", "Meta+4", 0));
_ui.actionTerminalView->setShortcut(QApplication::translate("MainWindow", "Meta+5", 0));
_ui.actionSimulationView->setShortcut(QApplication::translate("MainWindow", "Meta+6", 0));
_ui.actionSimulationView->setShortcut(QApplication::translate("MainWindow", "Meta+5", 0));
_ui.actionFullscreen->setShortcut(QApplication::translate("MainWindow", "Meta+Return", 0));
#else
_ui.actionSetup->setShortcut(QApplication::translate("MainWindow", "Ctrl+1", 0));
_ui.actionPlan->setShortcut(QApplication::translate("MainWindow", "Ctrl+2", 0));
_ui.actionFlight->setShortcut(QApplication::translate("MainWindow", "Ctrl+3", 0));
_ui.actionAnalyze->setShortcut(QApplication::translate("MainWindow", "Ctrl+4", 0));
_ui.actionTerminalView->setShortcut(QApplication::translate("MainWindow", "Ctrl+5", 0));
_ui.actionSimulationView->setShortcut(QApplication::translate("MainWindow", "Ctrl+6", 0));
_ui.actionSimulationView->setShortcut(QApplication::translate("MainWindow", "Ctrl+5", 0));
_ui.actionFullscreen->setShortcut(QApplication::translate("MainWindow", "Ctrl+Return", 0));
#endif
......@@ -503,14 +499,6 @@ void MainWindow::_buildSimView(void)
}
}
void MainWindow::_buildTerminalView(void)
{
if (!_terminalView) {
_terminalView = new TerminalConsole(this);
_terminalView->setVisible(false);
}
}
/// Shows or hides the specified dock widget, creating if necessary
void MainWindow::_showDockWidget(const QString& name, bool show)
{
......@@ -707,7 +695,6 @@ void MainWindow::loadSettings()
case VIEW_FLIGHT:
case VIEW_SIMULATION:
case VIEW_SETUP:
case VIEW_TERMINAL:
_currentView = currentViewCandidate;
break;
default:
......@@ -773,7 +760,6 @@ void MainWindow::connectCommonActions()
perspectives->addAction(_ui.actionSimulationView);
perspectives->addAction(_ui.actionPlan);
perspectives->addAction(_ui.actionSetup);
perspectives->addAction(_ui.actionTerminalView);
perspectives->addAction(_ui.actionExperimentalPlanView);
perspectives->setExclusive(true);
......@@ -808,11 +794,6 @@ void MainWindow::connectCommonActions()
_ui.actionSetup->setChecked(true);
_ui.actionSetup->activate(QAction::Trigger);
}
if (_currentView == VIEW_TERMINAL)
{
_ui.actionTerminalView->setChecked(true);
_ui.actionTerminalView->activate(QAction::Trigger);
}
// The UAS actions are not enabled without connection to system
_ui.actionLiftoff->setEnabled(false);
......@@ -840,7 +821,6 @@ void MainWindow::connectCommonActions()
connect(_ui.actionAnalyze, SIGNAL(triggered()), this, SLOT(loadAnalyzeView()));
connect(_ui.actionPlan, SIGNAL(triggered()), this, SLOT(loadPlanView()));
connect(_ui.actionExperimentalPlanView, SIGNAL(triggered()), this, SLOT(loadOldPlanView()));
connect(_ui.actionTerminalView,SIGNAL(triggered()),this,SLOT(loadTerminalView()));
// Help Actions
connect(_ui.actionOnline_Documentation, SIGNAL(triggered()), this, SLOT(showHelp()));
......@@ -1002,11 +982,6 @@ void MainWindow::_loadCurrentViewState(void)
defaultWidgets = "UNMANNED_SYSTEM_CONTROL_DOCKWIDGET,WAYPOINT_LIST_DOCKWIDGET,PARAMETER_INTERFACE_DOCKWIDGET,PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET";
break;
case VIEW_TERMINAL:
_buildTerminalView();
centerView = _terminalView;
break;
default:
Q_ASSERT(false);
break;
......@@ -1150,17 +1125,6 @@ void MainWindow::loadSetupView()
}
}
void MainWindow::loadTerminalView()
{
if (_currentView != VIEW_TERMINAL)
{
_storeCurrentViewState();
_currentView = VIEW_TERMINAL;
_ui.actionTerminalView->setChecked(true);
_loadCurrentViewState();
}
}
void MainWindow::loadFlightView()
{
if (_currentView != VIEW_FLIGHT)
......
......@@ -161,8 +161,6 @@ public slots:
void loadPlanView();
/** @brief Load Old (Qt Widget) Map View (Mission) */
void loadOldPlanView();
/** @brief Load Terminal Console views */
void loadTerminalView();
/** @brief Manage Links */
void manageLinks();
......@@ -235,8 +233,8 @@ protected:
VIEW_FLIGHT, // Flight/Fly/Operate view mode. Used for 1st-person observation of the vehicle.
VIEW_SIMULATION, // HIL Simulation view. Useful overview of the entire system when doing hardware-in-the-loop simulations.
VIEW_SETUP, // Setup view. Used for initializing the system for operation. Includes UI for calibration, firmware updating/checking, and parameter modifcation.
VIEW_TERMINAL, // Terminal interface. Used for communicating with the remote system, usually in a special configuration input mode.
VIEW_LOCAL3D, // Unused
VIEW_UNUSED1, // Unused (don't remove, or it will screw up saved settigns indices)
VIEW_UNUSED2, // Unused (don't remove, or it will screw up saved settigns indices)
VIEW_EXPERIMENTAL_PLAN, // Original (Qt Widget) Mission/Map/Plan view mode. Used for setting mission waypoints and high-level system commands.
} VIEW_SECTIONS;
......
......@@ -98,7 +98,6 @@
<addaction name="separator"/>
</widget>
<addaction name="actionExperimentalPlanView"/>
<addaction name="actionTerminalView"/>
<addaction name="actionSimulationView"/>
<addaction name="separator"/>
<addaction name="separator"/>
......@@ -297,14 +296,6 @@
<string>HIL Simulation</string>
</property>
</action>
<action name="actionTerminalView">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Terminal</string>
</property>
</action>
<action name="actionStatusBar">
<property name="checkable">
<bool>true</bool>
......
/*=====================================================================
APM_PLANNER Open Source Ground Control Station
(c) 2013, Bill Bonney <billbonney@communistech.com>
This file is part of the APM_PLANNER project
APM_PLANNER 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.
APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief APM Highligther for ArduPilot Console.
*
* @author Bill Bonney <billbonney@communistech.com>
*
*/
#include "ApmHighlighter.h"
APMHighlighter::APMHighlighter(QObject *parent) :
QSyntaxHighlighter(parent)
{
}
void APMHighlighter::highlightBlock(const QString &text)
{
QTextCharFormat myClassFormat;
myClassFormat.setFontWeight(QFont::Bold);
myClassFormat.setForeground(Qt::darkMagenta);
QString pattern = "^\\Ardu[A-Za-z]+\\b";
QRegExp expression(pattern);
int index = text.indexOf(expression);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, myClassFormat);
index = text.indexOf(expression, index + length);
}
}
/*=====================================================================
APM_PLANNER Open Source Ground Control Station
(c) 2013, Bill Bonney <billbonney@communistech.com>
This file is part of the APM_PLANNER project
APM_PLANNER 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.
APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief APM Highligther for ArduPilot Console.
*
* @author Bill Bonney <billbonney@communistech.com>
*
*/
#ifndef APMHIGHLIGHTER_H
#define APMHIGHLIGHTER_H
#include "ApmHighlighter.h"
#include <QSyntaxHighlighter>
class APMHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
explicit APMHighlighter(QObject *parent = 0);
void highlightBlock(const QString &text);
signals:
public slots:
};
#endif // APMHIGHLIGHTER_H
#include "ParamWidget.h"
ParamWidget::ParamWidget(QString param,QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
m_param = param;
connect(ui.doubleSpinBox,SIGNAL(editingFinished()),this,SLOT(doubleSpinEditFinished()));
connect(ui.intSpinBox,SIGNAL(editingFinished()),this,SLOT(intSpinEditFinished()));
connect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
connect(ui.valueSlider,SIGNAL(sliderReleased()),this,SLOT(valueSliderReleased()));
}
void ParamWidget::doubleSpinEditFinished()
{
ui.valueSlider->setValue(((ui.doubleSpinBox->value() - m_min) / (m_max - m_min)) * 100.0);
emit doubleValueChanged(m_param,ui.doubleSpinBox->value());
}
void ParamWidget::intSpinEditFinished()
{
ui.valueSlider->setValue(((ui.intSpinBox->value() - m_min) / (m_max - m_min)) * 100.0);
emit intValueChanged(m_param,ui.intSpinBox->value());
}
void ParamWidget::comboIndexChanged(int index)
{
emit intValueChanged(m_param,m_valueList[index].first);
}
void ParamWidget::valueSliderReleased()
{
//Set the spin box, and emit a signal.
if (type == INT)
{
ui.intSpinBox->setValue(((ui.valueSlider->value() / 100.0) * (m_max - m_min)) + m_min);
emit intValueChanged(m_param,ui.intSpinBox->value());
}
else if (type == DOUBLE)
{
ui.doubleSpinBox->setValue(((ui.valueSlider->value() / 100.0) * (m_max - m_min)) + m_min);
emit doubleValueChanged(m_param,ui.doubleSpinBox->value());
}
}
ParamWidget::~ParamWidget()
{
}
void ParamWidget::setupInt(QString title,QString description,int value,int min,int max)
{
Q_UNUSED(value);
type = INT;
ui.titleLabel->setText("<h3>" + title + "</h3>");
ui.descriptionLabel->setText(description);
ui.valueComboBox->hide();
ui.valueSlider->show();
ui.intSpinBox->show();
ui.doubleSpinBox->hide();
if (min == 0 && max == 0)
{
m_min = 0;
m_max = 65535;
}
else
{
m_min = min;
m_max = max;
}
ui.intSpinBox->setMinimum(m_min);
ui.intSpinBox->setMaximum(m_max);
}
void ParamWidget::setupDouble(QString title,QString description,double value,double min,double max)
{
Q_UNUSED(value);
type = DOUBLE;
ui.titleLabel->setText("<h3>" + title + "</h3>");
ui.descriptionLabel->setText(description);
ui.valueComboBox->hide();
ui.valueSlider->show();
ui.intSpinBox->hide();
ui.doubleSpinBox->show();
if (min == 0 && max == 0)
{
m_min = 0;
m_max = 65535;
}
else
{
m_min = min;
m_max = max;
}
ui.doubleSpinBox->setMinimum(m_min);
ui.doubleSpinBox->setMaximum(m_max);
}
void ParamWidget::setupCombo(QString title,QString description,QList<QPair<int,QString> > list)
{
type = COMBO;
ui.titleLabel->setText("<h3>" + title + "</h3>");
ui.descriptionLabel->setText(description);
ui.valueComboBox->show();
ui.valueSlider->hide();
ui.intSpinBox->hide();
ui.doubleSpinBox->hide();
m_valueList = list;
ui.valueComboBox->clear();
disconnect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
for (int i=0;i<m_valueList.size();i++)
{
ui.valueComboBox->addItem(m_valueList[i].second);
}
connect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
}
void ParamWidget::setValue(double value)
{
if (type == INT)
{
ui.intSpinBox->setValue(value);
ui.valueSlider->setValue(((value - m_min) / (m_max - m_min)) * 100.0);
}
else if (type == DOUBLE)
{
ui.doubleSpinBox->setValue(value);
ui.valueSlider->setValue(((value - m_min) / (m_max - m_min)) * 100.0);
}
else if (type == COMBO)
{
for (int i=0;i<m_valueList.size();i++)
{
if ((int)value == m_valueList[i].first)
{
disconnect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
ui.valueComboBox->setCurrentIndex(i);
connect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
return;
}
}
}
}
#ifndef PARAMWIDGET_H
#define PARAMWIDGET_H
#include <QWidget>
#include "ui_ParamWidget.h"
class ParamWidget : public QWidget
{
Q_OBJECT
public:
explicit ParamWidget(QString param,QWidget *parent = 0);
~ParamWidget();
void setupInt(QString title,QString description,int value,int min,int max);
void setupDouble(QString title,QString description,double value,double min,double max);
void setupCombo(QString title,QString description,QList<QPair<int,QString> > list);
void setValue(double value);
signals:
void doubleValueChanged(QString param,double value);
void intValueChanged(QString param,int value);
private slots:
void doubleSpinEditFinished();
void intSpinEditFinished();
void comboIndexChanged(int index);
void valueSliderReleased();
private:
QString m_param;
enum VIEWTYPE
{
INT,
DOUBLE,
COMBO
};
double m_min;
double m_max;
double m_dvalue;
int m_ivalue;
VIEWTYPE type;
QList<QPair<int,QString> > m_valueList;
Ui::ParamWidget ui;
};
#endif // PARAMWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParamWidget</class>
<widget class="QWidget" name="ParamWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>619</width>
<height>207</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="titleLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="descriptionLabel">
<property name="text">
<string>TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSpinBox" name="intSpinBox"/>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox"/>
</item>
<item>
<widget class="QSlider" name="valueSlider">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="valueComboBox"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/*=====================================================================
APM_PLANNER Open Source Ground Control Station
(c) 2013, Bill Bonney <billbonney@communistech.com>
This file is part of the APM_PLANNER project
APM_PLANNER 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.
APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Serial Settings View.
*
* @author Bill Bonney <billbonney@communistech.com>
*
* Influenced from Qt examples by :-
* Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
* Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
*
*/
#include "SerialSettingsDialog.h"
#include "terminalconsole.h"
#include "ui_SerialSettingsDialog.h"
#ifdef __android__
#include "qserialport.h"
#include "qserialportinfo.h"
#else
#include <QSerialPort>
#include <QSerialPortInfo>
#endif
#include <QIntValidator>
#include <QLineEdit>
QT_USE_NAMESPACE
SerialSettingsDialog::SerialSettingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SerialSettingsDialog)
{
ui->setupUi(this);
m_intValidator = new QIntValidator(0, 4000000, this);
ui->baudRateBox->setInsertPolicy(QComboBox::NoInsert);
connect(ui->applyButton, SIGNAL(clicked()),
this, SLOT(apply()));
connect(ui->serialPortInfoListBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(showPortInfo(int)));
connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(checkCustomBaudRatePolicy(int)));
fillPortsParameters();
fillPortsInfo();
updateSettings();
}
SerialSettingsDialog::~SerialSettingsDialog()
{
delete ui;
}
const SerialSettings& SerialSettingsDialog::settings() const
{
return m_currentSettings;
}
void SerialSettingsDialog::showPortInfo(int idx)
{
if (idx != -1) {
QStringList list = ui->serialPortInfoListBox->itemData(idx).toStringList();
ui->descriptionLabel->setText(tr("Description: %1").arg(list.at(1)));
ui->manufacturerLabel->setText(tr("Manufacturer: %1").arg(list.at(2)));
ui->locationLabel->setText(tr("Location: %1").arg(list.at(3)));
ui->vidLabel->setText(tr("Vendor Identifier: %1").arg(list.at(4)));
ui->pidLabel->setText(tr("Product Identifier: %1").arg(list.at(5)));
}
}
void SerialSettingsDialog::apply()
{
updateSettings();
hide();
}
void SerialSettingsDialog::checkCustomBaudRatePolicy(int idx)
{
bool isCustomBaudRate = !ui->baudRateBox->itemData(idx).isValid();
ui->baudRateBox->setEditable(isCustomBaudRate);
if (isCustomBaudRate) {
ui->baudRateBox->clearEditText();
QLineEdit *edit = ui->baudRateBox->lineEdit();
edit->setValidator(m_intValidator);
}
}
void SerialSettingsDialog::fillPortsParameters()
{
// fill baud rate (is not the entire list of available values,
// desired values??, add your independently)
ui->baudRateBox->addItem(QLatin1String("115200"), QSerialPort::Baud115200);
ui->baudRateBox->addItem(QLatin1String("57600"), QSerialPort::Baud57600);
ui->baudRateBox->addItem(QLatin1String("38400"), QSerialPort::Baud38400);
ui->baudRateBox->addItem(QLatin1String("19200"), QSerialPort::Baud19200);
ui->baudRateBox->addItem(QLatin1String("19200"), QSerialPort::Baud19200);
ui->baudRateBox->addItem(QLatin1String("9600"), QSerialPort::Baud9600);
ui->baudRateBox->addItem(QLatin1String("Custom"));
// fill data bits
ui->dataBitsBox->addItem(QLatin1String("5"), QSerialPort::Data5);
ui->dataBitsBox->addItem(QLatin1String("6"), QSerialPort::Data6);
ui->dataBitsBox->addItem(QLatin1String("7"), QSerialPort::Data7);
ui->dataBitsBox->addItem(QLatin1String("8"), QSerialPort::Data8);
ui->dataBitsBox->setCurrentIndex(3);
// fill parity
ui->parityBox->addItem(QLatin1String("None"), QSerialPort::NoParity);
ui->parityBox->addItem(QLatin1String("Even"), QSerialPort::EvenParity);
ui->parityBox->addItem(QLatin1String("Odd"), QSerialPort::OddParity);
ui->parityBox->addItem(QLatin1String("Mark"), QSerialPort::MarkParity);
ui->parityBox->addItem(QLatin1String("Space"), QSerialPort::SpaceParity);
// fill stop bits
ui->stopBitsBox->addItem(QLatin1String("1"), QSerialPort::OneStop);
#ifdef Q_OS_WIN
ui->stopBitsBox->addItem(QLatin1String("1.5"), QSerialPort::OneAndHalfStop);
#endif
ui->stopBitsBox->addItem(QLatin1String("2"), QSerialPort::TwoStop);
// fill flow control
ui->flowControlBox->addItem(QLatin1String("None"), QSerialPort::NoFlowControl);
ui->flowControlBox->addItem(QLatin1String("RTS/CTS"), QSerialPort::HardwareControl);
ui->flowControlBox->addItem(QLatin1String("XON/XOFF"), QSerialPort::SoftwareControl);
}
void SerialSettingsDialog::fillPortsInfo()
{
ui->serialPortInfoListBox->clear();
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
QStringList list;
list << info.portName()
<< info.description()
<< info.manufacturer()
<< info.systemLocation()
<< (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString())
<< (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : QString());
ui->serialPortInfoListBox->insertItem(0, list.first(), list);
}
}
void SerialSettingsDialog::updateSettings()
{
m_currentSettings.name = ui->serialPortInfoListBox->currentText();
// Baud Rate
if (ui->baudRateBox->currentIndex() == 4) {
// custom baud rate
m_currentSettings.baudRate = ui->baudRateBox->currentText().toInt();
} else {
// standard baud rate
m_currentSettings.baudRate = static_cast<QSerialPort::BaudRate>(
ui->baudRateBox->itemData(ui->baudRateBox->currentIndex()).toInt());
}
// Data bits
m_currentSettings.dataBits = static_cast<QSerialPort::DataBits>(
ui->dataBitsBox->itemData(ui->dataBitsBox->currentIndex()).toInt());
// Parity
m_currentSettings.parity = static_cast<QSerialPort::Parity>(
ui->parityBox->itemData(ui->parityBox->currentIndex()).toInt());
// Stop bits
m_currentSettings.stopBits = static_cast<QSerialPort::StopBits>(
ui->stopBitsBox->itemData(ui->stopBitsBox->currentIndex()).toInt());
// Flow control
m_currentSettings.flowControl = static_cast<QSerialPort::FlowControl>(
ui->flowControlBox->itemData(ui->flowControlBox->currentIndex()).toInt());
}
/*=====================================================================
APM_PLANNER Open Source Ground Control Station
(c) 2013, Bill Bonney <billbonney@communistech.com>
This file is part of the APM_PLANNER project
APM_PLANNER 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.
APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Serial Settings View.
*
* @author Bill Bonney <billbonney@communistech.com>
*
* Influenced from Qt examples by :-
* Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
* Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
*
*/
#ifndef SERIALSETTINGSDIALOG_H
#define SERIALSETTINGSDIALOG_H
#include <QDialog>
#ifdef __android__
#include "qserialport.h"
#else
#include <QSerialPort>
#endif
namespace Ui {
class SerialSettingsDialog;
}
class QIntValidator;
class SerialSettings {
public:
SerialSettings() : name(""),
baudRate(115200),
dataBits(QSerialPort::Data8),
parity(QSerialPort::NoParity),
stopBits(QSerialPort::OneStop),
flowControl(QSerialPort::NoFlowControl){}
public:
QString name;
qint32 baudRate;
QSerialPort::DataBits dataBits;
QSerialPort::Parity parity;
QSerialPort::StopBits stopBits;
QSerialPort::FlowControl flowControl;
};
class SerialSettingsDialog : public QDialog
{
Q_OBJECT
public:
explicit SerialSettingsDialog(QWidget *parent = 0);
~SerialSettingsDialog();
const SerialSettings &settings() const;
private slots:
void showPortInfo(int idx);
void apply();
void checkCustomBaudRatePolicy(int idx);
private:
void fillPortsParameters();
void fillPortsInfo();
void updateSettings();
private:
Ui::SerialSettingsDialog *ui;
SerialSettings m_currentSettings;
QIntValidator *m_intValidator;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SerialSettingsDialog</class>
<widget class="QDialog" name="SerialSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>401</width>
<height>250</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QGroupBox" name="selectBox">
<property name="title">
<string>Select Serial Port</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QComboBox" name="serialPortInfoListBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="descriptionLabel">
<property name="text">
<string>Description:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="manufacturerLabel">
<property name="text">
<string>Manufacturer:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="locationLabel">
<property name="text">
<string>Location:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="vidLabel">
<property name="text">
<string>Vendor ID:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="pidLabel">
<property name="text">
<string>Product ID:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>96</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="applyButton">
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QGroupBox" name="parametersBox">
<property name="title">
<string>Select Parameters</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="baudRateLabel">
<property name="text">
<string>BaudRate:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="baudRateBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="dataBitsLabel">
<property name="text">
<string>Data bits:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="dataBitsBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="parityLabel">
<property name="text">
<string>Parity:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="parityBox"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="stopBitsLabel">
<property name="text">
<string>Stop bits:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="stopBitsBox"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="flowControlLabel">
<property name="text">
<string>Flow control:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="flowControlBox"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "terminalconsole.h"
#include "ui_terminalconsole.h"
TerminalConsole::TerminalConsole(QWidget *parent) :
QWidget(parent),
ui(new Ui::TerminalConsole)
{
ui->setupUi(this);
}
TerminalConsole::~TerminalConsole()
{
delete ui;
}
/*=====================================================================
APM_PLANNER Open Source Ground Control Station
(c) 2013, Bill Bonney <billbonney@communistech.com>
This file is part of the APM_PLANNER project
APM_PLANNER 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.
APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Text Console.
*
* @author Bill Bonney <billbonney@communistech.com>
*
* Influenced from Qt examples by :-
* Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
* Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
*
*/
#include "console.h"
#include "ApmHighlighter.h"
#include <QScrollBar>
#include <QtCore/QDebug>
Console::Console(QWidget *parent)
: QPlainTextEdit(parent)
, localEchoEnabled(false)
{
document()->setMaximumBlockCount(100);
QPalette p = palette();
p.setColor(QPalette::Base, Qt::black);
p.setColor(QPalette::Text, Qt::green);
setPalette(p);
m_highlighter = new APMHighlighter(document());
}
void Console::putData(const QByteArray &data)
{
insertPlainText(QString(data));
QScrollBar *bar = verticalScrollBar();
bar->setValue(bar->maximum());
}
void Console::setLocalEchoEnabled(bool set)
{
localEchoEnabled = set;
}
void Console::keyPressEvent(QKeyEvent *e)
{
switch (e->key()) {
case Qt::Key_Backspace:
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Up:
case Qt::Key_Down:
// skip processing
break;
default:
if (localEchoEnabled)
QPlainTextEdit::keyPressEvent(e);
emit getData(e->text().toLocal8Bit());
}
}
void Console::mousePressEvent(QMouseEvent *e)
{
Q_UNUSED(e)
setFocus();
}
void Console::mouseDoubleClickEvent(QMouseEvent *e)
{
Q_UNUSED(e)
}
void Console::contextMenuEvent(QContextMenuEvent *e)
{
Q_UNUSED(e)
}
/*=====================================================================
APM_PLANNER Open Source Ground Control Station
(c) 2013, Bill Bonney <billbonney@communistech.com>
This file is part of the APM_PLANNER project
APM_PLANNER 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.
APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Text Console.
*
* @author Bill Bonney <billbonney@communistech.com>
*
* Influenced from Qt examples by :-
* Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
* Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
*
*/
#ifndef CONSOLE_H
#define CONSOLE_H
#include <QPlainTextEdit>
class APMHighlighter;
class Console : public QPlainTextEdit
{
Q_OBJECT
signals:
void getData(const QByteArray &data);
public:
explicit Console(QWidget *parent = 0);
void putData(const QByteArray &data);
void setLocalEchoEnabled(bool set);
protected:
virtual void keyPressEvent(QKeyEvent *e);
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseDoubleClickEvent(QMouseEvent *e);
virtual void contextMenuEvent(QContextMenuEvent *e);
private:
bool localEchoEnabled;
APMHighlighter* m_highlighter;
};
#endif // CONSOLE_H
/*=====================================================================
APM_PLANNER Open Source Ground Control Station
(c) 2013, Bill Bonney <billbonney@communistech.com>
This file is part of the APM_PLANNER project
APM_PLANNER 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.
APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Terminal Console display View.
*
* @author Bill Bonney <billbonney@communistech.com>
*
* Influenced from Qt examples by :-
* Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
* Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
*
*/
#include "SerialSettingsDialog.h"
#include "terminalconsole.h"
#include "ui_terminalconsole.h"
#include "console.h"
#include "QGCConfig.h"
#include "QGCMessageBox.h"
#include <QDebug>
#include <QSettings>
#include <QStatusBar>
#include <QVBoxLayout>
#include <QComboBox>
#ifdef __android__
#include "qserialport.h"
#include "qserialportinfo.h"
#else
#include <QSerialPort>
#include <QSerialPortInfo>
#endif
TerminalConsole::TerminalConsole(QWidget *parent) :
QWidget(parent),
ui(new Ui::TerminalConsole),
m_consoleMode(APM)
{
ui->setupUi(this);
// create the cosole and add it to the centralwidget
m_console = new Console;
m_console->setEnabled(false);
m_statusBar = new QStatusBar;
QLayout* layout = ui->terminalGroupBox->layout();
layout->addWidget(m_console);
layout->addWidget(m_statusBar);
m_serial = new QSerialPort(this);
m_settingsDialog = new SerialSettingsDialog;
ui->connectButton->setEnabled(true);
ui->disconnectButton->setEnabled(false);
ui->settingsButton->setEnabled(true);
addBaudComboBoxConfig();
fillPortsInfo(*ui->linkComboBox);
loadSettings();
if (m_settings.name == "") {
setLink(ui->linkComboBox->currentIndex());
} else {
ui->linkComboBox->setCurrentIndex(0);
}
addConsoleModesComboBoxConfig();
initConnections();
}
void TerminalConsole::addBaudComboBoxConfig()
{
ui->consoleModeBox->addItem(QLatin1String("APM"), APM);
ui->consoleModeBox->addItem(QLatin1String("PX4"), PX4);
}
void TerminalConsole::addConsoleModesComboBoxConfig()
{
ui->baudComboBox->addItem(QLatin1String("115200"), QSerialPort::Baud115200);
ui->baudComboBox->addItem(QLatin1String("57600"), QSerialPort::Baud57600);
ui->baudComboBox->addItem(QLatin1String("38400"), QSerialPort::Baud38400);
ui->baudComboBox->addItem(QLatin1String("19200"), QSerialPort::Baud19200);
ui->baudComboBox->addItem(QLatin1String("19200"), QSerialPort::Baud19200);
ui->baudComboBox->addItem(QLatin1String("9600"), QSerialPort::Baud9600);
}
void TerminalConsole::fillPortsInfo(QComboBox &comboxBox)
{
comboxBox.clear();
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
QStringList list;
list << info.portName()
<< info.description()
<< info.manufacturer()
<< info.systemLocation()
<< (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString())
<< (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : QString());
comboxBox.insertItem(0,list.first(), list);
//qDebug() << "Inserting " << list.first();
}
}
TerminalConsole::~TerminalConsole()
{
delete m_console;
delete m_statusBar;
delete m_settingsDialog;
delete ui;
}
void TerminalConsole::openSerialPort()
{
openSerialPort(m_settings);
}
void TerminalConsole::openSerialPort(const SerialSettings &settings)
{
m_serial->setPortName(settings.name);
if (m_serial->open(QIODevice::ReadWrite)) {
if (m_serial->setBaudRate(settings.baudRate)
&& m_serial->setDataBits(settings.dataBits)
&& m_serial->setParity(settings.parity)
&& m_serial->setStopBits(settings.stopBits)
&& m_serial->setFlowControl(settings.flowControl)) {
m_console->setEnabled(true);
m_console->setLocalEchoEnabled(false);
ui->connectButton->setEnabled(false);
ui->disconnectButton->setEnabled(true);
ui->settingsButton->setEnabled(false);
m_statusBar->showMessage(tr("Connected to %1 : baud %2z")
.arg(settings.name).arg(QString::number(settings.baudRate)));
qDebug() << "Open Terminal Console Serial Port";
writeSettings(); // Save last successful connection
sendResetCommand();
} else {
m_serial->close();
QGCMessageBox::critical(tr("Error"), m_serial->errorString());
m_statusBar->showMessage(tr("Open error"));
}
} else {
QGCMessageBox::critical(tr("Error"), m_serial->errorString());
m_statusBar->showMessage(tr("Configure error"));
}
}
void TerminalConsole::closeSerialPort()
{
m_serial->close();
m_console->setEnabled(false);
ui->connectButton->setEnabled(true);
ui->disconnectButton->setEnabled(false);
ui->settingsButton->setEnabled(true);
m_statusBar->showMessage(tr("Disconnected"));
}
void TerminalConsole::sendResetCommand()
{
if (m_serial->isOpen()) {
m_serial->setDataTerminalReady(true);
m_serial->waitForBytesWritten(250);
m_serial->setDataTerminalReady(false);
}
}
void TerminalConsole::writeData(const QByteArray &data)
{
// qDebug() << "writeData:" << data;
m_serial->write(data);
}
void TerminalConsole::readData()
{
QByteArray data = m_serial->readAll();
// qDebug() << "readData:" << data;
m_console->putData(data);
switch(m_consoleMode)
{
case APM: // APM
// On reset, send the break sequence and display help
if (data.contains("ENTER 3")) {
m_serial->write("\r\r\r");
m_serial->waitForBytesWritten(10);
m_serial->write("HELP\r");
}
break;
case PX4:
// Do nothing
default:
qDebug() << "Mode not yet implemented";
}
}
void TerminalConsole::handleError(QSerialPort::SerialPortError error)
{
if (error == QSerialPort::ResourceError) {
QGCMessageBox::critical(tr("Critical Error"), m_serial->errorString());
closeSerialPort();
}
}
void TerminalConsole::initConnections()
{
// Ui Connections
connect(ui->connectButton, SIGNAL(released()), this, SLOT(openSerialPort()));
connect(ui->disconnectButton, SIGNAL(released()), this, SLOT(closeSerialPort()));
connect(ui->settingsButton, SIGNAL(released()), m_settingsDialog, SLOT(show()));
connect(ui->clearButton, SIGNAL(released()), m_console, SLOT(clear()));
connect(ui->baudComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setBaudRate(int)));
connect(ui->linkComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setLink(int)));
// connect(ui->linkComboBox, SIGNAL()), this, SLOT(setLink(int)));
// Serial Port Connections
connect(m_serial, SIGNAL(error(QSerialPort::SerialPortError)), this,
SLOT(handleError(QSerialPort::SerialPortError)));
connect(m_serial, SIGNAL(readyRead()), this, SLOT(readData()));
connect(m_console, SIGNAL(getData(QByteArray)), this, SLOT(writeData(QByteArray)));
}
void TerminalConsole::setBaudRate(int index)
{
m_settings.baudRate = static_cast<QSerialPort::BaudRate>(
ui->baudComboBox->itemData(index).toInt());
qDebug() << "Changed Baud to:" << m_settings.baudRate;
}
void TerminalConsole::setLink(int index)
{
Q_UNUSED(index);
m_settings.name = ui->linkComboBox->currentText();
qDebug() << "Changed Link to:" << m_settings.name;
}
void TerminalConsole::loadSettings()
{
// Load defaults from settings
QSettings settings;
if (settings.contains("TERMINALCONSOLE_COMM_PORT"))
{
m_settings.name = settings.value("TERMINALCONSOLE_COMM_PORT").toString();
m_settings.baudRate = settings.value("TERMINALCONSOLE_COMM_BAUD").toInt();
m_settings.parity = static_cast<QSerialPort::Parity>
(settings.value("TERMINALCONSOLE_COMM_PARITY").toInt());
m_settings.stopBits = static_cast<QSerialPort::StopBits>
(settings.value("TERMINALCONSOLE_COMM_STOPBITS").toInt());
m_settings.dataBits = static_cast<QSerialPort::DataBits>
(settings.value("TERMINALCONSOLE_COMM_DATABITS").toInt());
m_settings.flowControl = static_cast<QSerialPort::FlowControl>
(settings.value("TERMINALCONSOLE_COMM_FLOW_CONTROL").toInt());
} else {
// init the structure
}
}
void TerminalConsole::writeSettings()
{
// Store settings
QSettings settings;
settings.setValue("TERMINALCONSOLE_COMM_PORT", m_settings.name);
settings.setValue("TERMINALCONSOLE_COMM_BAUD", m_settings.baudRate);
settings.setValue("TERMINALCONSOLE_COMM_PARITY", m_settings.parity);
settings.setValue("TERMINALCONSOLE_COMM_STOPBITS", m_settings.stopBits);
settings.setValue("TERMINALCONSOLE_COMM_DATABITS", m_settings.dataBits);
settings.setValue("TERMINALCONSOLE_COMM_FLOW_CONTROL", m_settings.flowControl);
}
/*=====================================================================
APM_PLANNER Open Source Ground Control Station
(c) 2013, Bill Bonney <billbonney@communistech.com>
This file is part of the APM_PLANNER project
APM_PLANNER 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.
APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Terminal Console display View.
*
* @author Bill Bonney <billbonney@communistech.com>
*
* Influenced from Qt examples by :-
* Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
* Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
*
*/
#ifndef TERMINALCONSOLE_H
#define TERMINALCONSOLE_H
#include "SerialSettingsDialog.h"
#include <QWidget>
#ifdef __android__
#include "qserialport.h"
#else
#include <QSerialPort>
#endif
namespace Ui {
class TerminalConsole;
}
class Console;
class SettingsDialog;
class QStatusBar;
class QComboBox;
class TerminalConsole : public QWidget
{
Q_OBJECT
public:
enum ConsoleMode { APM, PX4 };
public:
explicit TerminalConsole(QWidget *parent = 0);
~TerminalConsole();
private slots:
void openSerialPort();
void openSerialPort(const SerialSettings &settings);
void closeSerialPort();
void writeData(const QByteArray &data);
void readData();
void sendResetCommand();
void handleError(QSerialPort::SerialPortError error);
private slots:
void setBaudRate(int index);
void setLink(int index);
private:
void initConnections();
void addBaudComboBoxConfig();
void fillPortsInfo(QComboBox &comboxBox);
void addConsoleModesComboBoxConfig();
void writeSettings();
void loadSettings();
private:
Ui::TerminalConsole *ui;
Console *m_console;
QStatusBar *m_statusBar;
SerialSettingsDialog *m_settingsDialog;
QSerialPort *m_serial;
SerialSettings m_settings;
ConsoleMode m_consoleMode;
};
#endif // TERMINALCONSOLE_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TerminalConsole</class>
<widget class="QWidget" name="TerminalConsole">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>889</width>
<height>531</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="terminalGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Terminal Output</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item alignment="Qt::AlignRight|Qt::AlignVCenter">
<widget class="QPushButton" name="connectButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>100</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>131</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>CONNECT</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="disconnectButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>131</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>DISCONNECT</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignRight">
<widget class="QComboBox" name="linkComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>123</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>220</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QComboBox" name="baudComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>123</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QComboBox" name="consoleModeBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>123</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>91</width>
<height>23</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="settingsButton">
<property name="text">
<string>Adv. Settings</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearButton">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
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