mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Make device enumeration use the device transport data
This removes some special-case code for Uemis, replacing it with simply passing in the device transport information. This makes device enumeration work for the Garmin Descent (if it is listed by libdivecomputer as a USB storage device, that is). I don't actually do any of the libdivecomputer parsing yet, and only have a stub for the Garmin Descent, but now the directory selection works with that stub. The actual download obviously does not. [Dirk Hohndel: removed obsolete FIXME from code] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
bb067b6ee4
commit
270e9eccad
13 changed files with 40 additions and 33 deletions
|
@ -81,7 +81,7 @@ const char *system_default_filename(void)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
|
int enumerate_devices(device_callback_t callback, void *userdata, unsigned int transport)
|
||||||
{
|
{
|
||||||
/* FIXME: we need to enumerate in some other way on android */
|
/* FIXME: we need to enumerate in some other way on android */
|
||||||
/* qtserialport maybee? */
|
/* qtserialport maybee? */
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#ifndef DISPLAY_H
|
#ifndef DISPLAY_H
|
||||||
#define DISPLAY_H
|
#define DISPLAY_H
|
||||||
|
|
||||||
|
#include "libdivecomputer.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -44,11 +46,7 @@ extern int is_default_dive_computer(const char *, const char *);
|
||||||
|
|
||||||
typedef void (*device_callback_t)(const char *name, void *userdata);
|
typedef void (*device_callback_t)(const char *name, void *userdata);
|
||||||
|
|
||||||
#define DC_TYPE_SERIAL 1
|
int enumerate_devices(device_callback_t callback, void *userdata, unsigned int transport);
|
||||||
#define DC_TYPE_UEMIS 2
|
|
||||||
#define DC_TYPE_OTHER 3
|
|
||||||
|
|
||||||
int enumerate_devices(device_callback_t callback, void *userdata, int dc_type);
|
|
||||||
|
|
||||||
extern const char *default_dive_computer_vendor;
|
extern const char *default_dive_computer_vendor;
|
||||||
extern const char *default_dive_computer_product;
|
extern const char *default_dive_computer_product;
|
||||||
|
|
|
@ -158,6 +158,7 @@ void fill_computer_list()
|
||||||
mydescriptor->product = "Zurich";
|
mydescriptor->product = "Zurich";
|
||||||
mydescriptor->type = DC_FAMILY_NULL;
|
mydescriptor->type = DC_FAMILY_NULL;
|
||||||
mydescriptor->model = 0;
|
mydescriptor->model = 0;
|
||||||
|
mydescriptor->transports = DC_TRANSPORT_USBSTORAGE;
|
||||||
|
|
||||||
if (!vendorList.contains("Uemis"))
|
if (!vendorList.contains("Uemis"))
|
||||||
vendorList.append("Uemis");
|
vendorList.append("Uemis");
|
||||||
|
@ -171,14 +172,15 @@ void fill_computer_list()
|
||||||
qSort(vendorList);
|
qSort(vendorList);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NUMTRANSPORTS 6
|
#define NUMTRANSPORTS 7
|
||||||
static QString transportStringTable[NUMTRANSPORTS] = {
|
static QString transportStringTable[NUMTRANSPORTS] = {
|
||||||
QStringLiteral("SERIAL"),
|
QStringLiteral("SERIAL"),
|
||||||
QStringLiteral("USB"),
|
QStringLiteral("USB"),
|
||||||
QStringLiteral("USBHID"),
|
QStringLiteral("USBHID"),
|
||||||
QStringLiteral("IRDA"),
|
QStringLiteral("IRDA"),
|
||||||
QStringLiteral("BT"),
|
QStringLiteral("BT"),
|
||||||
QStringLiteral("BLE")
|
QStringLiteral("BLE"),
|
||||||
|
QStringLiteral("USBSTORAGE"),
|
||||||
};
|
};
|
||||||
|
|
||||||
static QString getTransportString(unsigned int transport)
|
static QString getTransportString(unsigned int transport)
|
||||||
|
|
|
@ -78,6 +78,7 @@ struct mydescriptor {
|
||||||
const char *product;
|
const char *product;
|
||||||
dc_family_t type;
|
dc_family_t type;
|
||||||
unsigned int model;
|
unsigned int model;
|
||||||
|
unsigned int transports;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This fills the vendor list QStringList and related members.
|
/* This fills the vendor list QStringList and related members.
|
||||||
|
|
|
@ -68,7 +68,7 @@ const char *system_default_filename(void)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
int enumerate_devices(device_callback_t, void *, int)
|
int enumerate_devices(device_callback_t, void *, unsigned int)
|
||||||
{
|
{
|
||||||
// we can't read from devices on iOS
|
// we can't read from devices on iOS
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -12,6 +12,11 @@
|
||||||
#include <libdivecomputer/device.h>
|
#include <libdivecomputer/device.h>
|
||||||
#include <libdivecomputer/parser.h>
|
#include <libdivecomputer/parser.h>
|
||||||
|
|
||||||
|
// Even if we have an old libdivecomputer, Uemis uses this
|
||||||
|
#ifndef DC_TRANSPORT_USBSTORAGE
|
||||||
|
#define DC_TRANSPORT_USBSTORAGE (1 << 6)
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "dive.h"
|
#include "dive.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -97,13 +97,13 @@ const char *system_default_filename(void)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
|
int enumerate_devices(device_callback_t callback, void *userdata, unsigned int transport)
|
||||||
{
|
{
|
||||||
int index = -1, entries = 0;
|
int index = -1, entries = 0;
|
||||||
DIR *dp = NULL;
|
DIR *dp = NULL;
|
||||||
struct dirent *ep = NULL;
|
struct dirent *ep = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
if (dc_type != DC_TYPE_UEMIS) {
|
if (transport & DC_TRANSPORT_SERIAL) {
|
||||||
const char *dirname = "/dev";
|
const char *dirname = "/dev";
|
||||||
const char *patterns[] = {
|
const char *patterns[] = {
|
||||||
"tty.*",
|
"tty.*",
|
||||||
|
@ -135,7 +135,7 @@ int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
|
||||||
}
|
}
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
}
|
}
|
||||||
if (dc_type != DC_TYPE_SERIAL) {
|
if (transport & DC_TRANSPORT_USBSTORAGE) {
|
||||||
const char *dirname = "/Volumes";
|
const char *dirname = "/Volumes";
|
||||||
int num_uemis = 0;
|
int num_uemis = 0;
|
||||||
dp = opendir(dirname);
|
dp = opendir(dirname);
|
||||||
|
|
|
@ -100,7 +100,7 @@ const char *system_default_filename(void)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
|
int enumerate_devices(device_callback_t callback, void *userdata, unsigned int transport)
|
||||||
{
|
{
|
||||||
int index = -1, entries = 0;
|
int index = -1, entries = 0;
|
||||||
DIR *dp = NULL;
|
DIR *dp = NULL;
|
||||||
|
@ -110,7 +110,7 @@ int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
char *fname;
|
char *fname;
|
||||||
size_t len;
|
size_t len;
|
||||||
if (dc_type != DC_TYPE_UEMIS) {
|
if (transport & DC_TRANSPORT_SERIAL) {
|
||||||
const char *dirname = "/dev";
|
const char *dirname = "/dev";
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
const char *patterns[] = {
|
const char *patterns[] = {
|
||||||
|
@ -153,7 +153,7 @@ int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
}
|
}
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (dc_type != DC_TYPE_SERIAL) {
|
if (transport & DC_TRANSPORT_USBSTORAGE) {
|
||||||
int num_uemis = 0;
|
int num_uemis = 0;
|
||||||
file = fopen("/proc/mounts", "r");
|
file = fopen("/proc/mounts", "r");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
|
|
|
@ -117,11 +117,11 @@ const char *system_default_filename(void)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
|
int enumerate_devices(device_callback_t callback, void *userdata, unsigned int transport)
|
||||||
{
|
{
|
||||||
int index = -1;
|
int index = -1;
|
||||||
DWORD i;
|
DWORD i;
|
||||||
if (dc_type != DC_TYPE_UEMIS) {
|
if (transport & DC_TRANSPORT_SERIAL) {
|
||||||
// Open the registry key.
|
// Open the registry key.
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_QUERY_VALUE, &hKey);
|
LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_QUERY_VALUE, &hKey);
|
||||||
|
@ -169,7 +169,7 @@ int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
|
||||||
|
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
}
|
}
|
||||||
if (dc_type != DC_TYPE_SERIAL) {
|
if (transport & DC_TRANSPORT_USBSTORAGE) {
|
||||||
int i;
|
int i;
|
||||||
int count_drives = 0;
|
int count_drives = 0;
|
||||||
const int bufdef = 512;
|
const int bufdef = 512;
|
||||||
|
|
|
@ -398,11 +398,11 @@ static void fillDeviceList(const char *name, void *data)
|
||||||
comboBox->addItem(name);
|
comboBox->addItem(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputerDialog::fill_device_list(int dc_type)
|
void ConfigureDiveComputerDialog::fill_device_list(unsigned int transport)
|
||||||
{
|
{
|
||||||
int deviceIndex;
|
int deviceIndex;
|
||||||
ui.device->clear();
|
ui.device->clear();
|
||||||
deviceIndex = enumerate_devices(fillDeviceList, ui.device, dc_type);
|
deviceIndex = enumerate_devices(fillDeviceList, ui.device, transport);
|
||||||
if (deviceIndex >= 0)
|
if (deviceIndex >= 0)
|
||||||
ui.device->setCurrentIndex(deviceIndex);
|
ui.device->setCurrentIndex(deviceIndex);
|
||||||
}
|
}
|
||||||
|
@ -1445,12 +1445,12 @@ void ConfigureDiveComputerDialog::on_DiveComputerList_currentRowChanged(int curr
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dcType = DC_TYPE_SERIAL;
|
unsigned int transport = DC_TRANSPORT_SERIAL;
|
||||||
|
|
||||||
|
|
||||||
if (selected_vendor == QString("Uemis"))
|
if (selected_vendor == QString("Uemis"))
|
||||||
dcType = DC_TYPE_UEMIS;
|
transport = DC_TRANSPORT_USBSTORAGE;
|
||||||
fill_device_list(dcType);
|
fill_device_list(transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputerDialog::checkLogFile(int state)
|
void ConfigureDiveComputerDialog::checkLogFile(int state)
|
||||||
|
|
|
@ -102,7 +102,7 @@ private:
|
||||||
device_data_t device_data;
|
device_data_t device_data;
|
||||||
void getDeviceData();
|
void getDeviceData();
|
||||||
|
|
||||||
void fill_device_list(int dc_type);
|
void fill_device_list(unsigned int transport);
|
||||||
|
|
||||||
DeviceDetails *deviceDetails;
|
DeviceDetails *deviceDetails;
|
||||||
void populateDeviceDetails();
|
void populateDeviceDetails();
|
||||||
|
|
|
@ -143,7 +143,7 @@ void DownloadFromDCWidget::updateState(states state)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (state == INITIAL) {
|
if (state == INITIAL) {
|
||||||
fill_device_list(DC_TYPE_OTHER);
|
fill_device_list(~0);
|
||||||
ui.progressBar->hide();
|
ui.progressBar->hide();
|
||||||
markChildrenAsEnabled();
|
markChildrenAsEnabled();
|
||||||
timer->stop();
|
timer->stop();
|
||||||
|
@ -231,13 +231,14 @@ void DownloadFromDCWidget::updateState(states state)
|
||||||
|
|
||||||
void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString &vendor)
|
void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString &vendor)
|
||||||
{
|
{
|
||||||
int dcType = DC_TYPE_SERIAL;
|
unsigned int transport;
|
||||||
|
dc_descriptor_t *descriptor;
|
||||||
productModel.setStringList(productList[vendor]);
|
productModel.setStringList(productList[vendor]);
|
||||||
ui.product->setCurrentIndex(0);
|
ui.product->setCurrentIndex(0);
|
||||||
|
|
||||||
if (vendor == QString("Uemis"))
|
descriptor = descriptorLookup.value(ui.vendor->currentText() + ui.product->currentText());
|
||||||
dcType = DC_TYPE_UEMIS;
|
transport = dc_descriptor_get_transports(descriptor);
|
||||||
fill_device_list(dcType);
|
fill_device_list(transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadFromDCWidget::on_product_currentIndexChanged(const QString &)
|
void DownloadFromDCWidget::on_product_currentIndexChanged(const QString &)
|
||||||
|
@ -475,7 +476,7 @@ void DownloadFromDCWidget::updateDeviceEnabled()
|
||||||
descriptor = descriptorLookup.value(ui.vendor->currentText() + ui.product->currentText());
|
descriptor = descriptorLookup.value(ui.vendor->currentText() + ui.product->currentText());
|
||||||
|
|
||||||
// call dc_descriptor_get_transport to see if the dc_transport_t is DC_TRANSPORT_SERIAL
|
// call dc_descriptor_get_transport to see if the dc_transport_t is DC_TRANSPORT_SERIAL
|
||||||
if (dc_descriptor_get_transports(descriptor) & DC_TRANSPORT_SERIAL) {
|
if (dc_descriptor_get_transports(descriptor) & (DC_TRANSPORT_SERIAL | DC_TRANSPORT_USBSTORAGE)) {
|
||||||
// if the dc_transport_t is DC_TRANSPORT_SERIAL, then enable the device node box.
|
// if the dc_transport_t is DC_TRANSPORT_SERIAL, then enable the device node box.
|
||||||
ui.device->setEnabled(true);
|
ui.device->setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -567,11 +568,11 @@ static void fillDeviceList(const char *name, void *data)
|
||||||
comboBox->addItem(name);
|
comboBox->addItem(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadFromDCWidget::fill_device_list(int dc_type)
|
void DownloadFromDCWidget::fill_device_list(unsigned int transport)
|
||||||
{
|
{
|
||||||
int deviceIndex;
|
int deviceIndex;
|
||||||
ui.device->clear();
|
ui.device->clear();
|
||||||
deviceIndex = enumerate_devices(fillDeviceList, ui.device, dc_type);
|
deviceIndex = enumerate_devices(fillDeviceList, ui.device, transport);
|
||||||
if (deviceIndex >= 0)
|
if (deviceIndex >= 0)
|
||||||
ui.device->setCurrentIndex(deviceIndex);
|
ui.device->setCurrentIndex(deviceIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ private:
|
||||||
|
|
||||||
int previousLast;
|
int previousLast;
|
||||||
|
|
||||||
void fill_device_list(int dc_type);
|
void fill_device_list(unsigned int transport);
|
||||||
QTimer *timer;
|
QTimer *timer;
|
||||||
bool dumpWarningShown;
|
bool dumpWarningShown;
|
||||||
OstcFirmwareCheck *ostcFirmwareCheck;
|
OstcFirmwareCheck *ostcFirmwareCheck;
|
||||||
|
|
Loading…
Reference in a new issue