diff options
-rw-r--r-- | core/downloadfromdcthread.cpp | 10 | ||||
-rw-r--r-- | core/downloadfromdcthread.h | 5 | ||||
-rw-r--r-- | core/libdivecomputer.c | 4 | ||||
-rw-r--r-- | core/libdivecomputer.h | 3 | ||||
-rw-r--r-- | core/serial_usb_android.cpp | 11 | ||||
-rw-r--r-- | core/serial_usb_android.h | 3 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 12 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.h | 1 |
8 files changed, 38 insertions, 11 deletions
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index c71a96fd9..2517b7fb6 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -220,6 +220,9 @@ DCDeviceData::DCDeviceData() #else data.libdc_log = false; #endif +#if defined(Q_OS_ANDROID) + data.androidUsbDeviceDescriptor = nullptr; +#endif } DCDeviceData *DCDeviceData::instance() @@ -320,6 +323,13 @@ void DCDeviceData::setDevName(const QString &devName) data.devname = copy_qstring(devName); } +#if defined(Q_OS_ANDROID) +void DCDeviceData::setUsbDevice(void *device) +{ + data.androidUsbDeviceDescriptor = device; +} +#endif + void DCDeviceData::setDevBluetoothName(const QString &name) { m_devBluetoothName = name; diff --git a/core/downloadfromdcthread.h b/core/downloadfromdcthread.h index 4284c2cc6..f142a4243 100644 --- a/core/downloadfromdcthread.h +++ b/core/downloadfromdcthread.h @@ -31,7 +31,7 @@ public: int diveId() const; /* this needs to be a pointer to make the C-API happy */ - device_data_t* internalData(); + device_data_t *internalData(); QStringList getProductListFromVendor(const QString& vendor); int getMatchingAddress(const QString &vendor, const QString &product); @@ -49,6 +49,9 @@ public: void setForceDownload(bool force); void setSaveDump(bool dumpMode); void setSaveLog(bool saveLog); +#if defined(Q_OS_ANDROID) + void setUsbDevice(void *device); +#endif private: device_data_t data; diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 475a78ef0..bc0836c3c 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -1336,8 +1336,8 @@ dc_status_t divecomputer_device_open(device_data_t *data) return ftdi_open(&data->iostream, context); #endif #ifdef __ANDROID__ - if (!strcasecmp(data->devname, "usb-serial")) - return serial_usb_android_open(&data->iostream, context); + if (data->androidUsbDeviceDescriptor) + return serial_usb_android_open(&data->iostream, context, data->androidUsbDeviceDescriptor); #endif rc = dc_serial_open(&data->iostream, context, data->devname); if (rc == DC_STATUS_SUCCESS) diff --git a/core/libdivecomputer.h b/core/libdivecomputer.h index e24143a7b..f8a919bbe 100644 --- a/core/libdivecomputer.h +++ b/core/libdivecomputer.h @@ -48,6 +48,7 @@ typedef struct dc_user_device_t FILE *libdc_logfile; struct dive_table *download_table; struct dive_site_table *sites; + void *androidUsbDeviceDescriptor; } device_data_t; const char *errmsg (dc_status_t rc); @@ -67,7 +68,7 @@ extern char *dumpfile_name; dc_status_t ble_packet_open(dc_iostream_t **iostream, dc_context_t *context, const char* devaddr, void *userdata); dc_status_t rfcomm_stream_open(dc_iostream_t **iostream, dc_context_t *context, const char* devaddr); dc_status_t ftdi_open(dc_iostream_t **iostream, dc_context_t *context); -dc_status_t serial_usb_android_open(dc_iostream_t **iostream, dc_context_t *context); +dc_status_t serial_usb_android_open(dc_iostream_t **iostream, dc_context_t *context, void *androidUsbDevice); dc_status_t divecomputer_device_open(device_data_t *data); diff --git a/core/serial_usb_android.cpp b/core/serial_usb_android.cpp index 8da56b510..7583f5011 100644 --- a/core/serial_usb_android.cpp +++ b/core/serial_usb_android.cpp @@ -348,13 +348,12 @@ std::vector<android_usb_serial_device_descriptor> serial_usb_android_get_devices * For testing and compatibility only, can be removed after the UI changes. Behaves exactly like the "old" * implementation if only one device is attached. */ -dc_status_t serial_usb_android_open(dc_iostream_t **iostream, dc_context_t *context) +dc_status_t serial_usb_android_open(dc_iostream_t **iostream, dc_context_t *context, void *androidUsbDevice) { - std::vector<android_usb_serial_device_descriptor> devices = serial_usb_android_get_devices(); - - if(devices.empty()) + if (!androidUsbDevice) return DC_STATUS_NODEVICE; + android_usb_serial_device_descriptor *usbDeviceDescriptor = (android_usb_serial_device_descriptor *)androidUsbDevice; - return serial_usb_android_open(iostream, context, devices[0].usbDevice, devices[0].className); - + // danger, danger, we need to pick the correct device here - passing the index around assumes that the table didn't change + return serial_usb_android_open(iostream, context, usbDeviceDescriptor->usbDevice, usbDeviceDescriptor->className); } diff --git a/core/serial_usb_android.h b/core/serial_usb_android.h index 37083c7cf..578fb1a9e 100644 --- a/core/serial_usb_android.h +++ b/core/serial_usb_android.h @@ -19,6 +19,7 @@ struct android_usb_serial_device_descriptor { uint16_t vid; }; -std::vector<android_usb_serial_device_descriptor> serial_usb_android_get_devices(bool driverSelection); +std::vector<android_usb_serial_device_descriptor> serial_usb_android_get_devices(); +android_usb_serial_device_descriptor getDescriptor(QAndroidJniObject usbDevice); #endif diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 1a9a54a86..e7a557155 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1999,6 +1999,18 @@ void QMLManager::DC_setProduct(const QString& product) void QMLManager::DC_setDevName(const QString& devName) { DCDeviceData::instance()->setDevName(devName); +#if defined(Q_OS_ANDROID) + // get the currently valid list of devices and set up the USB device descriptor + // if the connection string matches a connection in that list + androidSerialDevices = serial_usb_android_get_devices(); + std::string connection = devName.toStdString(); + for (unsigned int i = 0; i < androidSerialDevices.size(); i++) { + if (androidSerialDevices[i].uiRepresentation == connection) { + appendTextToLog(QString("setDevName matches USB device %1").arg(i)); + DCDeviceData::instance()->setUsbDevice((void *)&androidSerialDevices[i]); + } + } +#endif } void QMLManager::DC_setDevBluetoothName(const QString& devBluetoothName) diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index 88bb350bf..08fead029 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -233,6 +233,7 @@ public slots: void btRescan(); #if defined(Q_OS_ANDROID) void showDownloadPage(QAndroidJniObject usbDevice); + QString getProductVendorConnectionIdx(android_usb_serial_device_descriptor descriptor); #endif void divesChanged(const QVector<dive *> &dives, DiveField field); |