mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-02 23:20:20 +00:00
Create one function to determine the supported transports
This should make sure we create a consistent view based on all the information available. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5faa167e9f
commit
028299193a
3 changed files with 33 additions and 27 deletions
|
@ -107,28 +107,14 @@ void fill_computer_list()
|
||||||
dc_iterator_t *iterator = NULL;
|
dc_iterator_t *iterator = NULL;
|
||||||
dc_descriptor_t *descriptor = NULL;
|
dc_descriptor_t *descriptor = NULL;
|
||||||
|
|
||||||
// start out with the list of transports that libdivecomputer claims to support
|
unsigned int transportMask = get_supported_transports(NULL);
|
||||||
// dc_context_get_transports ignores its context argument...
|
|
||||||
int transportMask = dc_context_get_transports(NULL);
|
|
||||||
|
|
||||||
// then add the ones that we have our own implementations for
|
|
||||||
#if defined(BT_SUPPORT)
|
|
||||||
transportMask |= DC_TRANSPORT_BLUETOOTH;
|
|
||||||
#endif
|
|
||||||
#if defined(BLE_SUPPORT)
|
|
||||||
transportMask |= DC_TRANSPORT_BLE;
|
|
||||||
#endif
|
|
||||||
#if defined(Q_OS_IOS)
|
|
||||||
// libdivecomputer always claims to support serial, but on iOS we actually don't support that
|
|
||||||
transportMask &= ~DC_TRANSPORT_SERIAL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
fill_supported_mobile_list();
|
fill_supported_mobile_list();
|
||||||
|
|
||||||
dc_descriptor_iterator(&iterator);
|
dc_descriptor_iterator(&iterator);
|
||||||
while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) {
|
while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) {
|
||||||
// mask out the transports that aren't supported
|
// mask out the transports that aren't supported
|
||||||
int transports = dc_descriptor_get_transports(descriptor) & transportMask;
|
unsigned int transports = dc_descriptor_get_transports(descriptor) & transportMask;
|
||||||
if (transports == 0)
|
if (transports == 0)
|
||||||
// none of the transports are available, skip
|
// none of the transports are available, skip
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1229,19 +1229,37 @@ static char *transport_to_string(int t)
|
||||||
*
|
*
|
||||||
* This could have various platform rules too..
|
* This could have various platform rules too..
|
||||||
*/
|
*/
|
||||||
static unsigned int get_supported_transports(device_data_t *data)
|
unsigned int get_supported_transports(device_data_t *data)
|
||||||
{
|
{
|
||||||
unsigned int supported;
|
// start out with the list of transports that libdivecomputer claims to support
|
||||||
|
// dc_context_get_transports ignores its context argument...
|
||||||
|
unsigned int supported = dc_context_get_transports(NULL);
|
||||||
|
|
||||||
/*
|
// then add the ones that we have our own implementations for
|
||||||
* We don't support BT or BLE unless bluetooth_mode was set,
|
#if defined(BT_SUPPORT)
|
||||||
* and if it was we won't try any of the other transports.
|
supported |= DC_TRANSPORT_BLUETOOTH;
|
||||||
*/
|
#endif
|
||||||
supported = ~(DC_TRANSPORT_BLUETOOTH | DC_TRANSPORT_BLE);
|
#if defined(BLE_SUPPORT)
|
||||||
if (data->bluetooth_mode) {
|
supported |= DC_TRANSPORT_BLE;
|
||||||
supported = ~supported;
|
#endif
|
||||||
if (!strncmp(data->devname, "LE:", 3))
|
#if defined(Q_OS_IOS)
|
||||||
supported = DC_TRANSPORT_BLE;
|
// libdivecomputer always claims to support serial, but on iOS we actually don't support that
|
||||||
|
supported &= ~DC_TRANSPORT_SERIAL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
/*
|
||||||
|
* If we have device data available, we can refine this:
|
||||||
|
* We don't support BT or BLE unless bluetooth_mode was set,
|
||||||
|
* and if it was we won't try any of the other transports.
|
||||||
|
*/
|
||||||
|
if (data->bluetooth_mode) {
|
||||||
|
supported &= (DC_TRANSPORT_BLUETOOTH | DC_TRANSPORT_BLE);
|
||||||
|
if (!strncmp(data->devname, "LE:", 3))
|
||||||
|
supported &= DC_TRANSPORT_BLE;
|
||||||
|
} else {
|
||||||
|
supported &= ~(DC_TRANSPORT_BLUETOOTH | DC_TRANSPORT_BLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
report_error("get_supported_transports returns");
|
report_error("get_supported_transports returns");
|
||||||
report_error(transport_to_string(supported));
|
report_error(transport_to_string(supported));
|
||||||
|
|
|
@ -63,6 +63,8 @@ dc_status_t ftdi_open(dc_iostream_t **iostream, dc_context_t *context);
|
||||||
|
|
||||||
dc_status_t divecomputer_device_open(device_data_t *data);
|
dc_status_t divecomputer_device_open(device_data_t *data);
|
||||||
|
|
||||||
|
unsigned int get_supported_transports(device_data_t *data);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue