static void fu_provider_chug_init (FuProviderChug *provider_chug) { FuProviderChugPrivate *priv = GET_PRIVATE (provider_chug); priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) fu_provider_chug_device_free); priv->usb_ctx = g_usb_context_new (NULL); priv->device_queue = ch_device_queue_new (); g_signal_connect (priv->usb_ctx, "device-added", G_CALLBACK (fu_provider_chug_device_added_cb), provider_chug); g_signal_connect (priv->usb_ctx, "device-removed", G_CALLBACK (fu_provider_chug_device_removed_cb), provider_chug); }
int main (int argc, char *argv[]) { gboolean ret; GError *error = NULL; GMainLoop *loop = NULL; GUsbContext *ctx; GUsbDevice *device = NULL; int retval = 0; GUsbDeviceList *list = NULL; ChDeviceQueue *device_queue; /* setup usb */ g_type_init (); ctx = g_usb_context_new (&error); if (ctx == NULL) { g_warning ("Cannot connect to USB : %s", error->message); g_error_free (error); retval = 1; goto out; } list = g_usb_device_list_new (ctx); device_queue = ch_device_queue_new (); ret = connect_device (list, &device, &error); if (!ret) { g_warning ("Cannot connect to device : %s", error->message); g_error_free (error); retval = 1; goto out; } /* reset device so it boots back into bootloader mode */ g_warning ("Switching to bootloader mode\n"); ch_device_queue_reset (device_queue, device); ret = ch_device_queue_process (device_queue, CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE, NULL, &error); if (!ret) { g_warning ("Failed to reboot : %s", error->message); g_error_free (error); retval = 1; goto out; } /* wait for device to re-appear */ loop = g_main_loop_new (NULL, FALSE); g_timeout_add (5000, quit_loop_cb, loop); g_main_loop_run (loop); g_object_unref (device); ret = connect_device (list, &device, &error); if (!ret) { g_warning ("Cannot connect to device : %s", error->message); g_error_free (error); retval = 1; goto out; } /* boot into firmware mode */ g_warning ("Switching to firmware mode\n"); ch_device_queue_boot_flash (device_queue, device); ret = ch_device_queue_process (device_queue, CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE, NULL, &error); if (!ret) { g_warning ("Failed to boot into firmware mode : %s", error->message); g_error_free (error); retval = 1; goto out; } /* wait for device to re-appear */ g_timeout_add (5000, quit_loop_cb, loop); g_main_loop_run (loop); g_object_unref (device); ret = connect_device (list, &device, &error); if (!ret) { g_warning ("Cannot connect to device : %s", error->message); g_error_free (error); retval = 1; goto out; } /* turn on LEDs */ g_warning ("Turning on LEDs\n"); ch_device_queue_set_leds (device_queue, device, 3, 0, 0, 0); ret = ch_device_queue_process (device_queue, CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE, NULL, &error); if (!ret) { g_warning ("Failed to turn on LEDs : %s", error->message); g_error_free (error); retval = 1; goto out; } /* success */ g_warning ("ALL OKAY\n"); out: if (loop != NULL) g_main_loop_unref (loop); if (ctx != NULL) g_object_unref (ctx); if (device_queue != NULL) g_object_unref (device_queue); if (device != NULL) g_object_unref (device); if (list != NULL) g_object_unref (list); return retval; }
int main (int argc, char **argv) { ChAssemblePrivate *priv; gboolean ret; gboolean verbose = FALSE; GError *error = NULL; GOptionContext *context; int status = 0; const GOptionEntry options[] = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, /* TRANSLATORS: command line option */ _("Show extra debugging information"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init (&argc, &argv); /* TRANSLATORS: A program to assemble calibrate the hardware */ context = g_option_context_new (_("ColorHug assembly tester")); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (context, options, NULL); ret = g_option_context_parse (context, &argc, &argv, &error); if (!ret) { g_warning ("%s: %s", _("Failed to parse command line options"), error->message); g_error_free (error); } g_option_context_free (context); priv = g_new0 (ChAssemblePrivate, 1); priv->sample_widget = CD_SAMPLE_WIDGET (cd_sample_widget_new ()); priv->usb_ctx = g_usb_context_new (NULL); priv->device_queue = ch_device_queue_new (); g_signal_connect (priv->usb_ctx, "device-added", G_CALLBACK (ch_assemble_device_added_cb), priv); g_signal_connect (priv->usb_ctx, "device-removed", G_CALLBACK (ch_assemble_device_removed_cb), priv); /* ensure single instance */ priv->application = gtk_application_new ("com.hughski.ColorHug.Assemble", 0); g_signal_connect (priv->application, "startup", G_CALLBACK (ch_assemble_startup_cb), priv); g_signal_connect (priv->application, "activate", G_CALLBACK (ch_assemble_activate_cb), priv); /* set verbose? */ if (verbose) { g_setenv ("COLORHUG_VERBOSE", "1", FALSE); } else { g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, ch_assemble_ignore_cb, NULL); } /* wait */ status = g_application_run (G_APPLICATION (priv->application), argc, argv); g_object_unref (priv->application); if (priv->device_queue != NULL) g_object_unref (priv->device_queue); if (priv->usb_ctx != NULL) g_object_unref (priv->usb_ctx); if (priv->builder != NULL) g_object_unref (priv->builder); g_free (priv); return status; }