Commit 50101778 authored by dogmaphobic's avatar dogmaphobic

Show user friendly port name in Serial Settings combo box.

parent eb811905
......@@ -62,7 +62,7 @@ SerialLink::~SerialLink()
bool SerialLink::_isBootloader()
{
QList<QSerialPortInfo> portList = QSerialPortInfo::availablePorts();
QList<QSerialPortInfo> portList = QSerialPortInfo::availablePorts();
if( portList.count() == 0){
return false;
}
......@@ -581,14 +581,3 @@ void SerialConfiguration::loadSettings(QSettings& settings, const QString& root)
if(settings.contains("portName")) _portName = settings.value("portName").toString();
settings.endGroup();
}
QList<QString> SerialConfiguration::getCurrentPorts()
{
QList<QString> ports;
QList<QSerialPortInfo> portList = QSerialPortInfo::availablePorts();
foreach (const QSerialPortInfo &info, portList)
{
ports.append(info.systemLocation());
}
return ports;
}
......@@ -81,9 +81,6 @@ public:
void saveSettings(QSettings& settings, const QString& root);
void updateSettings();
/*! @brief Get a list of the currently available ports */
static QList<QString> getCurrentPorts();
private:
int _baud;
int _dataBits;
......
......@@ -142,6 +142,7 @@ void QGCLinkConfiguration::_fixUnnamed(LinkConfiguration* config)
#ifdef Q_OS_WIN32
tname.replace("\\\\.\\", "");
#else
tname.replace("/dev/cu.", "");
tname.replace("/dev/", "");
#endif
config->setName(QString("Serial Device on %1").arg(tname));
......
......@@ -32,6 +32,7 @@ This file is part of the QGROUNDCONTROL project
#include <QSettings>
#include <QFileInfoList>
#include <QDebug>
#include <QSerialPortInfo>
#include <SerialConfigurationWindow.h>
#include <SerialLink.h>
......@@ -42,7 +43,6 @@ This file is part of the QGROUNDCONTROL project
SerialConfigurationWindow::SerialConfigurationWindow(SerialConfiguration *config, QWidget *parent, Qt::WindowFlags flags)
: QWidget(parent, flags)
, _userConfigured(false)
{
_ui.setupUi(this);
Q_ASSERT(config != NULL);
......@@ -112,16 +112,15 @@ SerialConfigurationWindow::SerialConfigurationWindow(SerialConfiguration *config
}
// Connect the individual user interface inputs
connect(_ui.portName, SIGNAL(editTextChanged(QString)), this, SLOT(setPortName(QString)));
connect(_ui.portName, SIGNAL(currentIndexChanged(QString)), this, SLOT(setPortName(QString)));
connect(_ui.baudRate, SIGNAL(activated(int)), this, SLOT(setBaudRate(int)));
connect(_ui.flowControlCheckBox,SIGNAL(toggled(bool)), this, SLOT(enableFlowControl(bool)));
connect(_ui.parNone, SIGNAL(toggled(bool)), this, SLOT(setParityNone(bool)));
connect(_ui.parOdd, SIGNAL(toggled(bool)), this, SLOT(setParityOdd(bool)));
connect(_ui.parEven, SIGNAL(toggled(bool)), this, SLOT(setParityEven(bool)));
connect(_ui.dataBitsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setDataBits(int)));
connect(_ui.stopBitsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setStopBits(int)));
connect(_ui.advCheckBox, SIGNAL(clicked(bool)), _ui.advGroupBox, SLOT(setVisible(bool)));
connect(_ui.portName, SIGNAL(currentIndexChanged(int)), this, SLOT(setPortName(int)));
connect(_ui.baudRate, SIGNAL(activated(int)), this, SLOT(setBaudRate(int)));
connect(_ui.flowControlCheckBox,SIGNAL(toggled(bool)), this, SLOT(enableFlowControl(bool)));
connect(_ui.parNone, SIGNAL(toggled(bool)), this, SLOT(setParityNone(bool)));
connect(_ui.parOdd, SIGNAL(toggled(bool)), this, SLOT(setParityOdd(bool)));
connect(_ui.parEven, SIGNAL(toggled(bool)), this, SLOT(setParityEven(bool)));
connect(_ui.dataBitsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setDataBits(int)));
connect(_ui.stopBitsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setStopBits(int)));
connect(_ui.advCheckBox, SIGNAL(clicked(bool)), _ui.advGroupBox, SLOT(setVisible(bool)));
_ui.advCheckBox->setCheckable(true);
_ui.advCheckBox->setChecked(false);
......@@ -179,26 +178,38 @@ void SerialConfigurationWindow::hideEvent(QHideEvent* event)
bool SerialConfigurationWindow::setupPortList()
{
// Get the ports available on this system
QList<QString> ports = SerialConfiguration::getCurrentPorts();
QString storedName = _config->portName();
bool storedFound = false;
// Add the ports in reverse order, because we prepend them to the list
for (int i = ports.count() - 1; i >= 0; --i)
bool changed = false;
// Iterate found ports
QList<QSerialPortInfo> portList = QSerialPortInfo::availablePorts();
foreach (const QSerialPortInfo &info, portList)
{
// Prepend newly found port to the list
if (_ui.portName->findText(ports[i]) < 0)
QString name = info.portName();
// Append newly found port to the list
if (_ui.portName->findText(name) < 0)
{
_ui.portName->insertItem(0, ports[i]);
if (!_userConfigured) _ui.portName->setEditText(ports[i]);
// We show the user the "short name" but store the full port name
_ui.portName->addItem(name, QVariant(info.systemLocation()));
changed = true;
}
// Check if the stored link name is still present
if (ports[i].contains(storedName) || storedName.contains(ports[i]))
storedFound = true;
}
if (storedFound)
_ui.portName->setEditText(storedName);
return (ports.count() > 0);
// See if configured port (if any) is present
if(changed) {
int idx = _ui.portName->count() - 1;
if(!_config->portName().isEmpty()) {
idx = _ui.portName->findData(QVariant(_config->portName()));
if(idx < 0) {
idx = 0;
}
}
_ui.portName->setCurrentIndex(idx);
if(_ui.portName->count() > 0) {
_ui.portName->setEditText(_ui.portName->itemText(idx));
}
if(_config->portName().isEmpty()) {
setPortName(idx);
}
}
return (_ui.portName->count() > 0);
}
void SerialConfigurationWindow::enableFlowControl(bool flow)
......@@ -221,16 +232,13 @@ void SerialConfigurationWindow::setParityEven(bool accept)
if (accept) _config->setParity(QSerialPort::EvenParity);
}
void SerialConfigurationWindow::setPortName(QString port)
void SerialConfigurationWindow::setPortName(int index)
{
#ifdef Q_OS_WIN
port = port.split("-").first();
#endif
port = port.trimmed();
if (_config->portName() != port) {
_config->setPortName(port);
// Get the full port name and store it in the config
QString pname = _ui.portName->itemData(index).toString();
if (_config->portName() != pname) {
_config->setPortName(pname);
}
userConfigured = true;
}
void SerialConfigurationWindow::setBaudRate(int index)
......
......@@ -53,7 +53,7 @@ public slots:
void setParityNone(bool accept);
void setParityOdd(bool accept);
void setParityEven(bool accept);
void setPortName(QString port);
void setPortName(int index);
void setBaudRate(int index);
void setDataBits(int bits);
void setStopBits(int bits);
......@@ -72,8 +72,6 @@ protected:
bool userConfigured; ///< Switch to detect if current values are user-selected and shouldn't be overriden
private:
bool _userConfigured;
Ui::serialSettings _ui;
SerialConfiguration* _config;
QTimer* _portCheckTimer;
......
......@@ -32,16 +32,19 @@
</size>
</property>
<property name="toolTip">
<string>The serial port to which the system is connected. All ports listed here should work.</string>
<string>The serial port to which the system is connected.</string>
</property>
<property name="statusTip">
<string>The serial port to which the system is connected. All ports listed here should work.</string>
<string>The serial port to which the system is connected.</string>
</property>
<property name="whatsThis">
<string>The serial port to which the system is connected. All ports listed here should work.</string>
<string>The serial port to which the system is connected.</string>
</property>
<property name="editable">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="maxCount">
<number>100</number>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
......
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