Update the example application
The application is now responsible for setting up the USB based I/O stream.
This commit is contained in:
parent
c72dc4aa73
commit
5380b247af
@ -31,6 +31,7 @@
|
||||
#include <libdivecomputer/serial.h>
|
||||
#include <libdivecomputer/bluetooth.h>
|
||||
#include <libdivecomputer/irda.h>
|
||||
#include <libdivecomputer/usb.h>
|
||||
#include <libdivecomputer/usbhid.h>
|
||||
|
||||
#include "common.h"
|
||||
@ -398,6 +399,41 @@ dctool_file_read (const char *filename)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static dc_status_t
|
||||
dctool_usb_open (dc_iostream_t **out, dc_context_t *context, dc_descriptor_t *descriptor)
|
||||
{
|
||||
dc_status_t status = DC_STATUS_SUCCESS;
|
||||
dc_iostream_t *iostream = NULL;
|
||||
|
||||
// Discover the usb device.
|
||||
dc_iterator_t *iterator = NULL;
|
||||
dc_usb_device_t *device = NULL;
|
||||
dc_usb_iterator_new (&iterator, context, descriptor);
|
||||
while (dc_iterator_next (iterator, &device) == DC_STATUS_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
dc_iterator_free (iterator);
|
||||
|
||||
if (device == NULL) {
|
||||
ERROR ("No dive computer found.");
|
||||
status = DC_STATUS_NODEVICE;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Open the usb device.
|
||||
status = dc_usb_open (&iostream, context, device);
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
ERROR ("Failed to open the usb device.");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
*out = iostream;
|
||||
|
||||
cleanup:
|
||||
dc_usb_device_free (device);
|
||||
return status;
|
||||
}
|
||||
|
||||
static dc_status_t
|
||||
dctool_usbhid_open (dc_iostream_t **out, dc_context_t *context, dc_descriptor_t *descriptor)
|
||||
{
|
||||
@ -532,7 +568,7 @@ dctool_iostream_open (dc_iostream_t **iostream, dc_context_t *context, dc_descri
|
||||
case DC_TRANSPORT_SERIAL:
|
||||
return dc_serial_open (iostream, context, devname);
|
||||
case DC_TRANSPORT_USB:
|
||||
return DC_STATUS_SUCCESS;
|
||||
return dctool_usb_open(iostream, context, descriptor);
|
||||
case DC_TRANSPORT_USBHID:
|
||||
return dctool_usbhid_open(iostream, context, descriptor);
|
||||
case DC_TRANSPORT_IRDA:
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
#include <libdivecomputer/serial.h>
|
||||
#include <libdivecomputer/irda.h>
|
||||
#include <libdivecomputer/bluetooth.h>
|
||||
#include <libdivecomputer/usb.h>
|
||||
#include <libdivecomputer/usbhid.h>
|
||||
|
||||
#include "dctool.h"
|
||||
@ -59,6 +60,9 @@ scan (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transpo
|
||||
case DC_TRANSPORT_BLUETOOTH:
|
||||
status = dc_bluetooth_iterator_new (&iterator, context, descriptor);
|
||||
break;
|
||||
case DC_TRANSPORT_USB:
|
||||
status = dc_usb_iterator_new (&iterator, context, descriptor);
|
||||
break;
|
||||
case DC_TRANSPORT_USBHID:
|
||||
status = dc_usbhid_iterator_new (&iterator, context, descriptor);
|
||||
break;
|
||||
@ -90,6 +94,10 @@ scan (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transpo
|
||||
dc_bluetooth_device_get_name (device));
|
||||
dc_bluetooth_device_free (device);
|
||||
break;
|
||||
case DC_TRANSPORT_USB:
|
||||
printf ("%04x:%04x\n", dc_usb_device_get_vid (device), dc_usb_device_get_pid (device));
|
||||
dc_usb_device_free (device);
|
||||
break;
|
||||
case DC_TRANSPORT_USBHID:
|
||||
printf ("%04x:%04x\n", dc_usbhid_device_get_vid (device), dc_usbhid_device_get_pid (device));
|
||||
dc_usbhid_device_free (device);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user