Browse Source

Merge pull request #1361 from dogmaphobic/portNaming

Show user friendly port name in Serial Settings combo box.
QGC4.4
Don Gagne 10 years ago
parent
commit
967cfe3b23
  1. 11
      src/comm/SerialLink.cc
  2. 3
      src/comm/SerialLink.h
  3. 1
      src/ui/QGCLinkConfiguration.cc
  4. 62
      src/ui/SerialConfigurationWindow.cc
  5. 4
      src/ui/SerialConfigurationWindow.h
  6. 11
      src/ui/SerialSettings.ui

11
src/comm/SerialLink.cc

@ -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();
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;
}

3
src/comm/SerialLink.h

@ -81,9 +81,6 @@ public: @@ -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;

1
src/ui/QGCLinkConfiguration.cc

@ -142,6 +142,7 @@ void QGCLinkConfiguration::_fixUnnamed(LinkConfiguration* config) @@ -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));

62
src/ui/SerialConfigurationWindow.cc

@ -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 <QFileInfoList>
#include <QDebug>
#include <QSerialPortInfo>
#include <SerialConfigurationWindow.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)
: QWidget(parent, flags)
, _userConfigured(false)
{
_ui.setupUi(this);
Q_ASSERT(config != NULL);
@ -112,8 +112,7 @@ SerialConfigurationWindow::SerialConfigurationWindow(SerialConfiguration *config @@ -112,8 +112,7 @@ 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.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)));
@ -179,26 +178,38 @@ void SerialConfigurationWindow::hideEvent(QHideEvent* event) @@ -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) @@ -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)

4
src/ui/SerialConfigurationWindow.h

@ -53,7 +53,7 @@ public slots: @@ -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: @@ -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;

11
src/ui/SerialSettings.ui

@ -32,16 +32,19 @@ @@ -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>

Loading…
Cancel
Save