static void ch_assemble_got_device_bl (ChAssemblePrivate *priv) { g_autoptr(GError) error = NULL; /* open device */ if (!ch_device_open (priv->device, &error)) { g_warning ("Failed to open: %s", error->message); /* TRANSLATORS: permissions error perhaps? */ ch_assemble_set_label (priv, _("Failed to open device")); ch_assemble_set_color (priv, 0, 0, 0); return; } /* test the device */ ch_assemble_set_label (priv, _("Testing device...")); ch_assemble_set_color (priv, 0.5f, 0.5f, 0.5f); ch_device_queue_self_test (priv->device_queue, priv->device); ch_device_queue_process_async (priv->device_queue, CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE, NULL, ch_assemble_self_test_cb, priv); }
static void fu_provider_chug_get_firmware_version (FuProviderChugItem *item) { FuProviderChugPrivate *priv = GET_PRIVATE (item->provider_chug); guint16 major; guint16 micro; guint16 minor; guint8 idx; g_autoptr(GError) error = NULL; g_autofree gchar *version = NULL; /* try to get the version without claiming interface */ if (!g_usb_device_open (item->usb_device, &error)) { g_debug ("Failed to open, polling: %s", error->message); return; } idx = g_usb_device_get_custom_index (item->usb_device, G_USB_DEVICE_CLASS_VENDOR_SPECIFIC, 'F', 'W', NULL); if (idx != 0x00) { g_autofree gchar *tmp = NULL; tmp = g_usb_device_get_string_descriptor (item->usb_device, idx, NULL); if (tmp != NULL) { item->got_version = TRUE; g_debug ("obtained fwver using extension '%s'", tmp); fu_device_set_version (item->device, tmp); goto out; } } g_usb_device_close (item->usb_device, NULL); /* attempt to open the device and get the serial number */ if (!ch_device_open (item->usb_device, &error)) { g_debug ("Failed to claim interface, polling: %s", error->message); return; } ch_device_queue_get_firmware_ver (priv->device_queue, item->usb_device, &major, &minor, µ); if (!ch_device_queue_process (priv->device_queue, CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE, NULL, &error)) { g_warning ("Failed to get serial: %s", error->message); goto out; } /* got things the old fashioned way */ item->got_version = TRUE; version = g_strdup_printf ("%i.%i.%i", major, minor, micro); g_debug ("obtained fwver using API '%s'", version); fu_device_set_version (item->device, version); out: /* we're done here */ g_clear_error (&error); if (!g_usb_device_close (item->usb_device, &error)) g_debug ("Failed to close: %s", error->message); }
static gboolean connect_device (GUsbDeviceList *list, GUsbDevice **device_out, GError **error) { gboolean ret; GUsbDevice *device = NULL; /* find the first colorhug */ g_usb_device_list_coldplug (list); device = g_usb_device_list_find_by_vid_pid (list, CH_USB_VID_LEGACY, CH_USB_PID_LEGACY, NULL); if (device == NULL) { device = g_usb_device_list_find_by_vid_pid (list, CH_USB_VID, CH_USB_PID_BOOTLOADER, NULL); } if (device == NULL) { device = g_usb_device_list_find_by_vid_pid (list, CH_USB_VID, CH_USB_PID_FIRMWARE, error); } if (device == NULL) { device = g_usb_device_list_find_by_vid_pid (list, CH_USB_VID, CH_USB_PID_BOOTLOADER2, NULL); } if (device == NULL) { device = g_usb_device_list_find_by_vid_pid (list, CH_USB_VID, CH_USB_PID_FIRMWARE2, error); } if (device == NULL) { ret = FALSE; goto out; } /* open device */ ret = ch_device_open (device, error); if (!ret) goto out; g_warning ("Device ready!"); *device_out = g_object_ref (device); out: return ret; }
static gboolean fu_provider_chug_open (FuProviderChugItem *item, GError **error) { g_autoptr(GError) error_local = NULL; if (!ch_device_open (item->usb_device, &error_local)) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_READ, "failed to open %s device: %s", fu_device_get_id (item->device), error_local->message); return FALSE; } return TRUE; }