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