mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-28 17:54:15 +01:00
OP356/GCS - Makes the dropbox show devices "friendly name". Type of connection and previous serial number accessible via tooltip.
Kind of hacky, we should refractor connectionManager but that can wait for after V1. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@3103 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
3665209195
commit
6bcacb1630
@ -106,11 +106,11 @@ void ConnectionManager::init()
|
|||||||
*/
|
*/
|
||||||
bool ConnectionManager::connectDevice()
|
bool ConnectionManager::connectDevice()
|
||||||
{
|
{
|
||||||
devListItem connection_device = findDevice(m_availableDevList->currentText());
|
devListItem connection_device = findDevice(m_availableDevList->itemData(m_availableDevList->currentIndex(),Qt::ToolTipRole).toString());
|
||||||
if (!connection_device.connection)
|
if (!connection_device.connection)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QIODevice *io_dev = connection_device.connection->openDevice(connection_device.devName);
|
QIODevice *io_dev = connection_device.connection->openDevice(connection_device.Name);
|
||||||
if (!io_dev)
|
if (!io_dev)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -244,15 +244,15 @@ void ConnectionManager::onConnectPressed()
|
|||||||
/**
|
/**
|
||||||
* Find a device by its displayed (visible on screen) name
|
* Find a device by its displayed (visible on screen) name
|
||||||
*/
|
*/
|
||||||
devListItem ConnectionManager::findDevice(const QString &displayedName)
|
devListItem ConnectionManager::findDevice(const QString &devName)
|
||||||
{
|
{
|
||||||
foreach (devListItem d, m_devList)
|
foreach (devListItem d, m_devList)
|
||||||
{
|
{
|
||||||
if (d.displayedName == displayedName)
|
if (d.devName == devName)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "findDevice: cannot find " << displayedName << " in device list";
|
qDebug() << "findDevice: cannot find " << devName << " in device list";
|
||||||
|
|
||||||
devListItem d;
|
devListItem d;
|
||||||
d.connection = NULL;
|
d.connection = NULL;
|
||||||
@ -316,13 +316,13 @@ void ConnectionManager::unregisterAll(IConnection *connection)
|
|||||||
/**
|
/**
|
||||||
* Register a device from a specific connection plugin
|
* Register a device from a specific connection plugin
|
||||||
*/
|
*/
|
||||||
void ConnectionManager::registerDevice(IConnection *conn, const QString &devN, const QString &disp)
|
void ConnectionManager::registerDevice(IConnection *conn, const QString &devN, const QString &name, const QString &disp)
|
||||||
{
|
{
|
||||||
devListItem d;
|
devListItem d;
|
||||||
d.connection = conn;
|
d.connection = conn;
|
||||||
d.devName = devN;
|
d.devName = devN;
|
||||||
d.displayedName = disp;
|
d.Name = name;
|
||||||
|
d.displayName=disp;
|
||||||
m_devList.append(d);
|
m_devList.append(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,20 +340,21 @@ void ConnectionManager::devChanged(IConnection *connection)
|
|||||||
unregisterAll(connection);
|
unregisterAll(connection);
|
||||||
|
|
||||||
//and add them back in the list
|
//and add them back in the list
|
||||||
QStringList availableDev = connection->availableDevices();
|
QList <IConnection::device> availableDev = connection->availableDevices();
|
||||||
foreach (QString dev, availableDev)
|
foreach (IConnection::device dev, availableDev)
|
||||||
{
|
{
|
||||||
QString cbName = connection->shortName() + ": " + dev;
|
QString cbName = connection->shortName() + ": " + dev.name;
|
||||||
registerDevice(connection, dev, cbName);
|
registerDevice(connection,cbName,dev.name,dev.displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//add all the list again to the combobox
|
//add all the list again to the combobox
|
||||||
foreach (devListItem d, m_devList)
|
foreach (devListItem d, m_devList)
|
||||||
{
|
{
|
||||||
m_availableDevList->addItem(d.displayedName);
|
m_availableDevList->addItem(d.displayName);
|
||||||
|
m_availableDevList->setItemData(m_availableDevList->count()-1,(const QString)d.devName,Qt::ToolTipRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
//disable connection button if the list is empty
|
//disable connection button if the liNameif (m_availableDevList->count() > 0)
|
||||||
if (m_availableDevList->count() > 0)
|
if (m_availableDevList->count() > 0)
|
||||||
m_connectBtn->setEnabled(true);
|
m_connectBtn->setEnabled(true);
|
||||||
else
|
else
|
||||||
|
@ -54,7 +54,8 @@ struct devListItem
|
|||||||
{
|
{
|
||||||
IConnection *connection;
|
IConnection *connection;
|
||||||
QString devName;
|
QString devName;
|
||||||
QString displayedName;
|
QString Name;
|
||||||
|
QString displayName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -76,8 +77,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void unregisterAll(IConnection *connection);
|
void unregisterAll(IConnection *connection);
|
||||||
void registerDevice(IConnection *conn, const QString &devN, const QString &disp);
|
void registerDevice(IConnection *conn, const QString &devN, const QString &name, const QString &disp);
|
||||||
devListItem findDevice(const QString &displayedName);
|
devListItem findDevice(const QString &devName);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceConnected(QIODevice *dev);
|
void deviceConnected(QIODevice *dev);
|
||||||
|
@ -49,7 +49,14 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Return the list of devices found on the system
|
* Return the list of devices found on the system
|
||||||
*/
|
*/
|
||||||
virtual QStringList availableDevices() = 0;
|
struct device
|
||||||
|
{
|
||||||
|
QString name;
|
||||||
|
QString displayName;
|
||||||
|
bool operator==(device i){return this->name==i.name;}
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual QList <device> availableDevices() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a device, and return a QIODevice interface from it
|
* Open a device, and return a QIODevice interface from it
|
||||||
|
@ -160,12 +160,14 @@ void IPconnectionConnection::onEnumerationChanged()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
QStringList IPconnectionConnection::availableDevices()
|
QList <Core::IConnection::device> IPconnectionConnection::availableDevices()
|
||||||
{
|
{
|
||||||
QStringList list;
|
QList <Core::IConnection::device> list;
|
||||||
|
device d;
|
||||||
|
d.displayName=(const QString )m_config->HostName();
|
||||||
|
d.name=(const QString )m_config->HostName();
|
||||||
//we only have one "device" as defined by the configuration m_config
|
//we only have one "device" as defined by the configuration m_config
|
||||||
list.append((const QString )m_config->HostName());
|
list.append(d);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public:
|
|||||||
IPconnectionConnection();
|
IPconnectionConnection();
|
||||||
virtual ~IPconnectionConnection();
|
virtual ~IPconnectionConnection();
|
||||||
|
|
||||||
virtual QStringList availableDevices();
|
virtual QList <Core::IConnection::device> availableDevices();
|
||||||
virtual QIODevice *openDevice(const QString &deviceName);
|
virtual QIODevice *openDevice(const QString &deviceName);
|
||||||
virtual void closeDevice(const QString &deviceName);
|
virtual void closeDevice(const QString &deviceName);
|
||||||
|
|
||||||
|
@ -58,10 +58,13 @@ void LoggingConnection::onEnumerationChanged()
|
|||||||
emit availableDevChanged(this);
|
emit availableDevChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList LoggingConnection::availableDevices()
|
QList <Core::IConnection::device> LoggingConnection::availableDevices()
|
||||||
{
|
{
|
||||||
QStringList list;
|
QList <device> list;
|
||||||
list << "Logfile replay...";
|
device d;
|
||||||
|
d.displayName="Logfile replay...";
|
||||||
|
d.name="Logfile replay...";
|
||||||
|
list <<d;
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public:
|
|||||||
LoggingConnection();
|
LoggingConnection();
|
||||||
virtual ~LoggingConnection();
|
virtual ~LoggingConnection();
|
||||||
|
|
||||||
virtual QStringList availableDevices();
|
virtual QList <Core::IConnection::device> availableDevices();
|
||||||
virtual QIODevice *openDevice(const QString &deviceName);
|
virtual QIODevice *openDevice(const QString &deviceName);
|
||||||
virtual void closeDevice(const QString &deviceName);
|
virtual void closeDevice(const QString &deviceName);
|
||||||
|
|
||||||
|
@ -79,14 +79,17 @@ void RawHIDConnection::onDeviceDisconnected()
|
|||||||
/**
|
/**
|
||||||
Returns the list of all currently available devices
|
Returns the list of all currently available devices
|
||||||
*/
|
*/
|
||||||
QStringList RawHIDConnection::availableDevices()
|
QList < Core::IConnection::device> RawHIDConnection::availableDevices()
|
||||||
{
|
{
|
||||||
QStringList devices;
|
QList < Core::IConnection::device> devices;
|
||||||
|
|
||||||
QList<USBPortInfo> portsList = m_usbMonitor->availableDevices(USBMonitor::idVendor_OpenPilot, -1, -1,USBMonitor::Running);
|
QList<USBPortInfo> portsList = m_usbMonitor->availableDevices(USBMonitor::idVendor_OpenPilot, -1, -1,USBMonitor::Running);
|
||||||
// We currently list devices by their serial number
|
// We currently list devices by their serial number
|
||||||
|
device dev;
|
||||||
foreach(USBPortInfo prt, portsList) {
|
foreach(USBPortInfo prt, portsList) {
|
||||||
devices.append(prt.serialNumber);
|
dev.name=prt.serialNumber;
|
||||||
|
dev.displayName=prt.product;
|
||||||
|
devices.append(dev);
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public:
|
|||||||
RawHIDConnection();
|
RawHIDConnection();
|
||||||
virtual ~RawHIDConnection();
|
virtual ~RawHIDConnection();
|
||||||
|
|
||||||
virtual QStringList availableDevices();
|
virtual QList < Core::IConnection::device> availableDevices();
|
||||||
virtual QIODevice *openDevice(const QString &deviceName);
|
virtual QIODevice *openDevice(const QString &deviceName);
|
||||||
virtual void closeDevice(const QString &deviceName);
|
virtual void closeDevice(const QString &deviceName);
|
||||||
|
|
||||||
|
@ -53,13 +53,13 @@ SerialEnumerationThread::~SerialEnumerationThread()
|
|||||||
|
|
||||||
void SerialEnumerationThread::run()
|
void SerialEnumerationThread::run()
|
||||||
{
|
{
|
||||||
QStringList devices = m_serial->availableDevices();
|
QList <Core::IConnection::device> devices = m_serial->availableDevices();
|
||||||
|
|
||||||
while(m_running)
|
while(m_running)
|
||||||
{
|
{
|
||||||
if(!m_serial->deviceOpened())
|
if(!m_serial->deviceOpened())
|
||||||
{
|
{
|
||||||
QStringList newDev = m_serial->availableDevices();
|
QList <Core::IConnection::device> newDev = m_serial->availableDevices();
|
||||||
if(devices != newDev)
|
if(devices != newDev)
|
||||||
{
|
{
|
||||||
devices = newDev;
|
devices = newDev;
|
||||||
@ -111,9 +111,9 @@ bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2)
|
|||||||
return s1.portName<s2.portName;
|
return s1.portName<s2.portName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SerialConnection::availableDevices()
|
QList <Core::IConnection::device> SerialConnection::availableDevices()
|
||||||
{
|
{
|
||||||
QStringList list;
|
QList <Core::IConnection::device> list;
|
||||||
|
|
||||||
if (enablePolling) {
|
if (enablePolling) {
|
||||||
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
||||||
@ -121,7 +121,10 @@ QStringList SerialConnection::availableDevices()
|
|||||||
//sort the list by port number (nice idea from PT_Dreamer :))
|
//sort the list by port number (nice idea from PT_Dreamer :))
|
||||||
qSort(ports.begin(), ports.end(),sortPorts);
|
qSort(ports.begin(), ports.end(),sortPorts);
|
||||||
foreach( QextPortInfo port, ports ) {
|
foreach( QextPortInfo port, ports ) {
|
||||||
list.append(port.friendName);
|
device d;
|
||||||
|
d.displayName=port.friendName;
|
||||||
|
d.name=port.friendName;
|
||||||
|
list.append(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public:
|
|||||||
SerialConnection();
|
SerialConnection();
|
||||||
virtual ~SerialConnection();
|
virtual ~SerialConnection();
|
||||||
|
|
||||||
virtual QStringList availableDevices();
|
virtual QList <Core::IConnection::device> availableDevices();
|
||||||
virtual QIODevice *openDevice(const QString &deviceName);
|
virtual QIODevice *openDevice(const QString &deviceName);
|
||||||
virtual void closeDevice(const QString &deviceName);
|
virtual void closeDevice(const QString &deviceName);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user