Fixed device detection problems on Mac OS X -- seems to work now on

Snow Leopard and Lion.
This commit is contained in:
Doug Brown 2012-05-18 19:39:24 -07:00
parent 0e9736dcb2
commit 1fdde6e9d5
2 changed files with 51 additions and 29 deletions

View File

@ -788,13 +788,18 @@ void Programmer::startBootloaderCommand(uint8_t commandByte, uint32_t newState)
sendByte(GetBootloaderState);
}
#include <QTimer>
void Programmer::portDiscovered(const QextPortInfo &info)
{
if ((foundState == ProgrammerBoardNotFound) &&
(info.vendorID == PROGRAMMER_USB_VENDOR_ID) &&
(info.productID == PROGRAMMER_USB_DEVICE_ID))
(info.productID == PROGRAMMER_USB_DEVICE_ID) &&
(info.portName != ""))
{
// Note: I check that portName != "" because QextSerialEnumerator seems to give me
// 2 notifications that match the vendor ID -- one is the real deal, and the other
// has a blank port name. If I match on the blank port name one, it breaks.
#ifdef Q_WS_WIN
programmerBoardPortName = "\\\\.\\" + info.portName;
#else
@ -802,6 +807,22 @@ void Programmer::portDiscovered(const QextPortInfo &info)
#endif
foundState = ProgrammerBoardFound;
// I create a temporary timer here because opening it immediately seems to crash
// Mac OS X in my limited testing. Don't worry about a memory leak -- the
// portDiscovered_internal() slot will delete the newly-allocated QTimer.
QTimer *t = new QTimer();
connect(t, SIGNAL(timeout()), SLOT(portDiscovered_internal()));
t->setInterval(50);
t->setSingleShot(true);
t->start();
}
}
void Programmer::portDiscovered_internal()
{
// Delete the QTimer that sent us this signal. Ugly, but it works...
sender()->deleteLater();
closePort();
serialPort->setPortName(programmerBoardPortName);
@ -831,12 +852,12 @@ void Programmer::portDiscovered(const QextPortInfo &info)
emit programmerBoardConnected();
}
}
}
void Programmer::portRemoved(const QextPortInfo &info)
{
if ((info.vendorID == PROGRAMMER_USB_VENDOR_ID) &&
(info.productID == PROGRAMMER_USB_DEVICE_ID))
(info.productID == PROGRAMMER_USB_DEVICE_ID) &&
(foundState == ProgrammerBoardFound))
{
programmerBoardPortName = "";
foundState = ProgrammerBoardNotFound;

View File

@ -146,6 +146,7 @@ private slots:
void dataReady();
void portDiscovered(const QextPortInfo &info);
void portDiscovered_internal();
void portRemoved(const QextPortInfo &info);
};