Exemplo n.º 1
0
static void dev_set_options(GtkAction *action, GtkWindow *parent)
{
	(void)action;

	struct sr_dev *dev = g_object_get_data(G_OBJECT(parent), "dev");
	if (!dev)
		return;

	GtkWidget *dialog = gtk_dialog_new_with_buttons("Device Properties",
					parent, GTK_DIALOG_MODAL,
					GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
					NULL);
	GtkWidget *sw = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
				GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_widget_set_size_request(sw, 300, 200);
	GtkWidget *tv = gtk_tree_view_new();
	gtk_container_add(GTK_CONTAINER(sw), tv);
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), sw,
				TRUE, TRUE, 0);

	/* Populate list store with config options */
	GtkListStore *props = gtk_list_store_new(MAX_DEV_PROP, 
					G_TYPE_INT, G_TYPE_INT,
					G_TYPE_STRING, G_TYPE_STRING,
					G_TYPE_BOOLEAN, G_TYPE_STRING,
					G_TYPE_BOOLEAN);
	gtk_tree_view_set_model(GTK_TREE_VIEW(tv), GTK_TREE_MODEL(props));
	int *hwcaps = dev->driver->hwcap_get_all();
	int cap;
	GtkTreeIter iter;
	for (cap = 0; hwcaps[cap]; cap++) {
		struct sr_hwcap_option *hwo;
		if (!(hwo = sr_hw_hwcap_get(hwcaps[cap])))
			continue;
		gtk_list_store_append(props, &iter);
		gtk_list_store_set(props, &iter, 
					DEV_PROP_HWCAP, hwcaps[cap],
					DEV_PROP_TYPE, hwo->type,
					DEV_PROP_SHORTNAME, hwo->shortname,
					DEV_PROP_DESCRIPTION, hwo->description,
					DEV_PROP_IS_TEXT, hwo->type != SR_T_BOOL,
					-1);
	}

	/* Popup tooltop containing description if mouse hovers */
	gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(tv), 
					DEV_PROP_DESCRIPTION);

	/* Save device with list so that property can be set by edited
	 * handler. */
	g_object_set_data(G_OBJECT(props), "dev", dev);

	/* Add columns to the tree view */
	GtkTreeViewColumn *col;
	col = gtk_tree_view_column_new_with_attributes("Property",
				gtk_cell_renderer_text_new(),
				"text", DEV_PROP_SHORTNAME, NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW(tv), col);
	/* We pack both a text and toggle renderer.  Only one will be visible.
	 * depending on type.
	 */
	GtkCellRenderer *cel = gtk_cell_renderer_text_new();
	g_object_set(cel, "editable", TRUE, NULL);
	g_signal_connect(cel, "edited", G_CALLBACK(prop_edited), props);
	col = gtk_tree_view_column_new_with_attributes("Value",
				cel, "text", DEV_PROP_TEXTVALUE, 
				"visible", DEV_PROP_IS_TEXT, NULL);
	cel = gtk_cell_renderer_toggle_new();
	g_signal_connect(cel, "toggled", G_CALLBACK(prop_toggled), props);
	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(col), cel, TRUE);
	gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(col), cel, 
				dev_prop_bool_data_func, NULL, NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW(tv), col);


	gtk_widget_show_all(dialog);
	gtk_dialog_run(GTK_DIALOG(dialog));

	gtk_widget_destroy(dialog);
}
Exemplo n.º 2
0
static void show_dev_detail(void)
{
	struct sr_dev *dev;
	const struct sr_hwcap_option *hwo;
	const struct sr_samplerates *samplerates;
	struct sr_rational *rationals;
	uint64_t *integers;
	const int *hwcaps;
	int cap, i;
	char *s, *title;
	const char *charopts, **stropts;

	dev = parse_devstring(opt_dev);
	if (!dev) {
		printf("No such device. Use -D to list all devices.\n");
		return;
	}

	print_dev_line(dev);

	if (sr_dev_info_get(dev, SR_DI_TRIGGER_TYPES,
					(const void **)&charopts) == SR_OK) {
		printf("Supported triggers: ");
		while (*charopts) {
			printf("%c ", *charopts);
			charopts++;
		}
		printf("\n");
	}

	title = "Supported options:\n";
	hwcaps = dev->driver->hwcap_get_all();
	for (cap = 0; hwcaps[cap]; cap++) {
		if (!(hwo = sr_hw_hwcap_get(hwcaps[cap])))
			continue;

		if (title) {
			printf("%s", title);
			title = NULL;
		}

		if (hwo->hwcap == SR_HWCAP_PATTERN_MODE) {
			/* Pattern generator modes */
			printf("    %s", hwo->shortname);
			if (sr_dev_info_get(dev, SR_DI_PATTERNS,
					(const void **)&stropts) == SR_OK) {
				printf(" - supported patterns:\n");
				for (i = 0; stropts[i]; i++)
					printf("      %s\n", stropts[i]);
			} else {
				printf("\n");
			}

		} else if (hwo->hwcap == SR_HWCAP_SAMPLERATE) {
			/* Supported samplerates */
			printf("    %s", hwo->shortname);
			if (sr_dev_info_get(dev, SR_DI_SAMPLERATES,
					(const void **)&samplerates) != SR_OK) {
				printf("\n");
				continue;
			}
			if (samplerates->step) {
				/* low */
				if (!(s = sr_samplerate_string(samplerates->low)))
					continue;
				printf(" (%s", s);
				g_free(s);
				/* high */
				if (!(s = sr_samplerate_string(samplerates->high)))
					continue;
				printf(" - %s", s);
				g_free(s);
				/* step */
				if (!(s = sr_samplerate_string(samplerates->step)))
					continue;
				printf(" in steps of %s)\n", s);
				g_free(s);
			} else {
				printf(" - supported samplerates:\n");
				for (i = 0; samplerates->list[i]; i++)
					printf("      %s\n", sr_samplerate_string(samplerates->list[i]));
			}

		} else if (hwo->hwcap == SR_HWCAP_BUFFERSIZE) {
			/* Supported buffer sizes */
			printf("    %s", hwo->shortname);
			if (sr_dev_info_get(dev, SR_DI_BUFFERSIZES,
					(const void **)&integers) != SR_OK) {
				printf("\n");
				continue;
			}
			printf(" - supported buffer sizes:\n");
			for (i = 0; integers[i]; i++)
				printf("      %"PRIu64"\n", integers[i]);

		} else if (hwo->hwcap == SR_HWCAP_TIMEBASE) {
			/* Supported time bases */
			printf("    %s", hwo->shortname);
			if (sr_dev_info_get(dev, SR_DI_TIMEBASES,
					(const void **)&rationals) != SR_OK) {
				printf("\n");
				continue;
			}
			printf(" - supported time bases:\n");
			for (i = 0; rationals[i].p && rationals[i].q; i++)
				printf("      %s\n", sr_period_string(
						rationals[i].p * rationals[i].q));

		} else if (hwo->hwcap == SR_HWCAP_TRIGGER_SOURCE) {
			/* Supported trigger sources */
			printf("    %s", hwo->shortname);
			if (sr_dev_info_get(dev, SR_DI_TRIGGER_SOURCES,
					(const void **)&stropts) != SR_OK) {
				printf("\n");
				continue;
			}
			printf(" - supported trigger sources:\n");
			for (i = 0; stropts[i]; i++)
				printf("      %s\n", stropts[i]);

		} else if (hwo->hwcap == SR_HWCAP_FILTER) {
			/* Supported trigger sources */
			printf("    %s", hwo->shortname);
			if (sr_dev_info_get(dev, SR_DI_FILTERS,
					(const void **)&stropts) != SR_OK) {
				printf("\n");
				continue;
			}
			printf(" - supported filter targets:\n");
			for (i = 0; stropts[i]; i++)
				printf("      %s\n", stropts[i]);

		} else if (hwo->hwcap == SR_HWCAP_VDIV) {
			/* Supported volts/div values */
			printf("    %s", hwo->shortname);
			if (sr_dev_info_get(dev, SR_DI_VDIVS,
					(const void **)&rationals) != SR_OK) {
				printf("\n");
				continue;
			}
			printf(" - supported volts/div:\n");
			for (i = 0; rationals[i].p && rationals[i].q; i++)
				printf("      %s\n", sr_voltage_string(	&rationals[i]));

		} else if (hwo->hwcap == SR_HWCAP_COUPLING) {
			/* Supported coupling settings */
			printf("    %s", hwo->shortname);
			if (sr_dev_info_get(dev, SR_DI_COUPLING,
					(const void **)&stropts) != SR_OK) {
				printf("\n");
				continue;
			}
			printf(" - supported coupling options:\n");
			for (i = 0; stropts[i]; i++)
				printf("      %s\n", stropts[i]);

		} else {
			/* Everything else */
			printf("    %s\n", hwo->shortname);
		}
	}
}