Simplify code by reducing nesting level.
This commit is contained in:
parent
6f5f21f996
commit
f6958dabcd
|
@ -304,7 +304,9 @@ int upload_firmware(libusb_device *dev)
|
|||
|
||||
static void close_device(struct sigrok_device_instance *sdi)
|
||||
{
|
||||
if (sdi->usb->devhdl) {
|
||||
if (sdi->usb->devhdl == NULL)
|
||||
return;
|
||||
|
||||
g_message("closing device %d on %d.%d interface %d", sdi->index,
|
||||
sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
|
||||
libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE);
|
||||
|
@ -312,7 +314,6 @@ static void close_device(struct sigrok_device_instance *sdi)
|
|||
sdi->usb->devhdl = NULL;
|
||||
sdi->status = ST_INACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
static int configure_probes(GSList * probes)
|
||||
{
|
||||
|
@ -386,34 +387,28 @@ static int hw_init(char *deviceinfo)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (des.idVendor == USB_VENDOR && des.idProduct == USB_PRODUCT) {
|
||||
/* Definitely a Saleae Logic... */
|
||||
if (des.idVendor != USB_VENDOR || des.idProduct != USB_PRODUCT)
|
||||
continue; /* Not a Saleae Logic... */
|
||||
|
||||
sdi = sigrok_device_instance_new(devcnt,
|
||||
ST_INITIALIZING, USB_VENDOR_NAME,
|
||||
USB_MODEL_NAME, USB_MODEL_VERSION);
|
||||
sdi = sigrok_device_instance_new(devcnt, ST_INITIALIZING,
|
||||
USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION);
|
||||
if (!sdi)
|
||||
return 0;
|
||||
device_instances =
|
||||
g_slist_append(device_instances, sdi);
|
||||
device_instances = g_slist_append(device_instances, sdi);
|
||||
|
||||
if (check_conf_profile(devlist[i]) == 0) {
|
||||
if (upload_firmware(devlist[i]) > 0)
|
||||
/*
|
||||
* Continue on the off chance that the
|
||||
* device is in a working state.
|
||||
* TODO: Could maybe try a USB reset,
|
||||
* Continue on the off chance that the device is in a
|
||||
* working state. TODO: Could maybe try a USB reset,
|
||||
* or uploading the firmware again.
|
||||
*/
|
||||
if (upload_firmware(devlist[i]) > 0)
|
||||
g_warning("firmware upload failed for device %d", devcnt);
|
||||
|
||||
sdi->usb = usb_device_instance_new
|
||||
(libusb_get_bus_number(devlist[i]), 0, NULL);
|
||||
} else {
|
||||
/*
|
||||
* Already has the firmware on it, so fix the
|
||||
* new address.
|
||||
*/
|
||||
/* Already has the firmware, so fix the new address. */
|
||||
sdi->usb = usb_device_instance_new
|
||||
(libusb_get_bus_number(devlist[i]),
|
||||
libusb_get_device_address(devlist[i]),
|
||||
|
@ -421,7 +416,6 @@ static int hw_init(char *deviceinfo)
|
|||
}
|
||||
devcnt++;
|
||||
}
|
||||
}
|
||||
libusb_free_device_list(devlist, 1);
|
||||
|
||||
return devcnt;
|
||||
|
@ -617,18 +611,19 @@ void receive_transfer(struct libusb_transfer *transfer)
|
|||
int cur_buflen, trigger_offset, i;
|
||||
unsigned char *cur_buf, *new_buf;
|
||||
|
||||
if (transfer == NULL) {
|
||||
/* hw_stop_acquisition() is telling us to stop. */
|
||||
if (transfer == NULL)
|
||||
num_samples = -1;
|
||||
}
|
||||
|
||||
if (num_samples == -1) {
|
||||
/*
|
||||
* Acquisition has already ended, just free any queued up
|
||||
* If acquisition has already ended, just free any queued up
|
||||
* transfer that come in.
|
||||
*/
|
||||
if (num_samples == -1) {
|
||||
libusb_free_transfer(transfer);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
g_message("receive_transfer(): status %d received %d bytes",
|
||||
transfer->status, transfer->actual_length);
|
||||
|
||||
|
@ -649,9 +644,9 @@ void receive_transfer(struct libusb_transfer *transfer)
|
|||
if (cur_buflen == 0) {
|
||||
empty_transfer_count++;
|
||||
if (empty_transfer_count > MAX_EMPTY_TRANSFERS) {
|
||||
/* The FX2 gave up. End the acquisition, the
|
||||
* frontend will work out that the samplecount
|
||||
* is short.
|
||||
/*
|
||||
* The FX2 gave up. End the acquisition, the frontend
|
||||
* will work out that the samplecount is short.
|
||||
*/
|
||||
packet.type = DF_END;
|
||||
session_bus(user_data, &packet);
|
||||
|
@ -668,8 +663,7 @@ void receive_transfer(struct libusb_transfer *transfer)
|
|||
if ((cur_buf[i] & trigger_mask[trigger_stage])
|
||||
== trigger_value[trigger_stage]) {
|
||||
/* Match on this trigger stage. */
|
||||
trigger_buffer[trigger_stage] =
|
||||
cur_buf[i];
|
||||
trigger_buffer[trigger_stage] = cur_buf[i];
|
||||
trigger_stage++;
|
||||
if (trigger_stage == NUM_TRIGGER_STAGES
|
||||
|| trigger_mask[trigger_stage] == 0) {
|
||||
|
@ -730,7 +724,6 @@ void receive_transfer(struct libusb_transfer *transfer)
|
|||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int hw_start_acquisition(int device_index, gpointer session_device_id)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue