Example #1
0
static void
ch_assemble_device_added_cb (GUsbContext *ctx,
                             GUsbDevice *device,
                             ChAssemblePrivate *priv)
{
    switch (ch_device_get_mode (device)) {
    case CH_DEVICE_MODE_BOOTLOADER:
    case CH_DEVICE_MODE_BOOTLOADER2:
    case CH_DEVICE_MODE_BOOTLOADER_PLUS:
    case CH_DEVICE_MODE_BOOTLOADER_ALS:
        g_debug ("Added ColorHug Bootloader: %s",
                 g_usb_device_get_platform_id (device));
        if (priv->device != NULL)
            g_object_unref (priv->device);
        priv->device = g_object_ref (device);
        ch_assemble_got_device_bl (priv);
        break;
    case CH_DEVICE_MODE_FIRMWARE:
    case CH_DEVICE_MODE_FIRMWARE2:
    case CH_DEVICE_MODE_FIRMWARE_PLUS:
    case CH_DEVICE_MODE_FIRMWARE_ALS:
        g_debug ("Added ColorHug Firmware: %s",
                 g_usb_device_get_platform_id (device));
        if (priv->device != NULL)
            g_object_unref (priv->device);
        priv->device = g_object_ref (device);
        ch_assemble_got_device_fw (priv);
        break;
    default:
        break;
    }
}
Example #2
0
static void
ch_assemble_flash_firmware (ChAssemblePrivate *priv)
{
    gsize len;
    g_autoptr(GError) error = NULL;
    g_autofree gchar *fn = NULL;
    g_autofree guint8 *data = NULL;

    /* set to false */
    ch_device_queue_set_flash_success (priv->device_queue,
                                       priv->device, 0);

    switch (ch_device_get_mode (priv->device)) {
    case CH_DEVICE_MODE_BOOTLOADER:
    case CH_DEVICE_MODE_BOOTLOADER2:
    case CH_DEVICE_MODE_BOOTLOADER_ALS:

        /* read firmware */
        ch_assemble_set_color (priv, 0.25f, 0.25f, 0.25f);
        ch_assemble_set_label (priv, _("Loading firmware..."));
        fn = g_strdup_printf ("./firmware/%s/firmware.bin",
                              _ch_device_get_download_id (priv->device));
        if (!g_file_get_contents (fn, (gchar **) &data, &len, &error)) {
            g_warning ("Failed to open firmware file %s: %s",
                       fn, error->message);
            return;
        }

        /* write to device */
        ch_assemble_set_color (priv, 0.5f, 0.5f, 0.5f);
        ch_assemble_set_label (priv, _("Writing firmware..."));
        ch_device_queue_write_firmware (priv->device_queue, priv->device,
                                        data, len);
        break;
    default:
        break;
    }

    ch_device_queue_process_async (priv->device_queue,
                                   CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE,
                                   NULL,
                                   ch_assemble_firmware_cb,
                                   priv);
}
Example #3
0
/**
 * _ch_device_get_download_id:
 * @device: the #GUsbDevice
 *
 * Returns the string identifier to use for the device type.
 *
 * Return value: string, e.g. "colorhug2"
 *
 * Since: x.x.x
 **/
static const gchar *
_ch_device_get_download_id (GUsbDevice *device)
{
    const char *str = NULL;
    switch (ch_device_get_mode (device)) {
    case CH_DEVICE_MODE_LEGACY:
    case CH_DEVICE_MODE_BOOTLOADER:
    case CH_DEVICE_MODE_FIRMWARE:
        str = "colorhug";
        break;
    case CH_DEVICE_MODE_BOOTLOADER2:
    case CH_DEVICE_MODE_FIRMWARE2:
        str = "colorhug2";
        break;
    case CH_DEVICE_MODE_BOOTLOADER_PLUS:
    case CH_DEVICE_MODE_FIRMWARE_PLUS:
        str = "colorhug-plus";
        break;
    default:
        break;
    }
    return str;
}
Example #4
0
static void
fu_provider_chug_device_added_cb (GUsbContext *ctx,
				  GUsbDevice *device,
				  FuProviderChug *provider_chug)
{
	FuProviderChugPrivate *priv = GET_PRIVATE (provider_chug);
	FuProviderChugItem *item;
	ChDeviceMode mode;
	g_autofree gchar *device_key = NULL;

	/* ignore */
	mode = ch_device_get_mode (device);
	if (mode == CH_DEVICE_MODE_UNKNOWN)
		return;

	/* this is using DFU now */
	if (mode == CH_DEVICE_MODE_BOOTLOADER_PLUS ||
	    mode == CH_DEVICE_MODE_FIRMWARE_PLUS)
		return;

	/* is already in database */
	device_key = fu_provider_chug_get_device_key (device);
	item = g_hash_table_lookup (priv->devices, device_key);
	if (item == NULL) {
		item = g_new0 (FuProviderChugItem, 1);
		item->provider_chug = g_object_ref (provider_chug);
		item->usb_device = g_object_ref (device);
		item->device = fu_device_new ();
		fu_device_set_id (item->device, device_key);
		fu_device_set_equivalent_id (item->device,
					     g_usb_device_get_platform_id (device));
		fu_device_add_guid (item->device, ch_device_get_guid (device));
		fu_device_add_flag (item->device, FU_DEVICE_FLAG_ALLOW_OFFLINE);
		fu_device_add_flag (item->device, FU_DEVICE_FLAG_ALLOW_ONLINE);

		/* try to get the serial number -- if opening failed then
		 * poll until the device is not busy */
		fu_provider_chug_get_firmware_version (item);
		if (!item->got_version && item->timeout_open_id == 0) {
			item->timeout_open_id = g_timeout_add_seconds (FU_PROVIDER_CHUG_POLL_REOPEN,
				fu_provider_chug_open_cb, item);
		}

		/* insert to hash */
		g_hash_table_insert (priv->devices, g_strdup (device_key), item);
	} else {
		/* update the device */
		g_object_unref (item->usb_device);
		item->usb_device = g_object_ref (device);
	}

	/* set the display name */
	switch (mode) {
	case CH_DEVICE_MODE_BOOTLOADER:
	case CH_DEVICE_MODE_FIRMWARE:
	case CH_DEVICE_MODE_LEGACY:
		fu_device_set_name (item->device, "ColorHug");
		break;
	case CH_DEVICE_MODE_BOOTLOADER2:
	case CH_DEVICE_MODE_FIRMWARE2:
		fu_device_set_name (item->device, "ColorHug2");
		break;
	case CH_DEVICE_MODE_BOOTLOADER_PLUS:
	case CH_DEVICE_MODE_FIRMWARE_PLUS:
		fu_device_set_name (item->device, "ColorHug+");
		break;
	case CH_DEVICE_MODE_BOOTLOADER_ALS:
	case CH_DEVICE_MODE_FIRMWARE_ALS:
		fu_device_set_name (item->device, "ColorHugALS");
		break;
	default:
		fu_device_set_name (item->device, "ColorHug??");
		break;
	}

	/* is the device in bootloader mode */
	switch (mode) {
	case CH_DEVICE_MODE_BOOTLOADER:
	case CH_DEVICE_MODE_BOOTLOADER2:
	case CH_DEVICE_MODE_BOOTLOADER_PLUS:
	case CH_DEVICE_MODE_BOOTLOADER_ALS:
		item->is_bootloader = TRUE;
		break;
	default:
		item->is_bootloader = FALSE;
		break;
	}
	fu_provider_device_add (FU_PROVIDER (provider_chug), item->device);
}