/*
- * This file is part of the sigrok project.
+ * This file is part of the sigrok-gtk project.
*
* Copyright (C) 2011 Gareth McMullin <gareth@blacksphere.co.nz>
*
#include <stdlib.h>
-#include <sigrok.h>
+#include <libsigrok/libsigrok.h>
#include <gtk/gtk.h>
#include "sigrok-gtk.h"
enum {
- DEV_PROP_CAPABILITY,
+ DEV_PROP_HWCAP,
DEV_PROP_TYPE,
DEV_PROP_SHORTNAME,
DEV_PROP_DESCRIPTION,
{
(void)cel;
- struct sr_device *device = g_object_get_data(G_OBJECT(props), "device");
+ struct sr_dev_inst *sdi = g_object_get_data(G_OBJECT(props), "sdi");
GtkTreeIter iter;
int type, cap;
guint64 tmp_u64;
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(props), &iter, path);
gtk_tree_model_get(GTK_TREE_MODEL(props), &iter,
- DEV_PROP_CAPABILITY, &cap,
+ DEV_PROP_HWCAP, &cap,
DEV_PROP_TYPE, &type, -1);
switch (type) {
if (sr_parse_sizestring(text, &tmp_u64) != SR_OK)
return;
- ret = device->plugin->set_configuration(device->plugin_index,
- cap, &tmp_u64);
+ ret = sr_dev_config_set(sdi, cap, &tmp_u64);
break;
case SR_T_CHAR:
- ret = device->plugin-> set_configuration(device->plugin_index,
- cap, text);
+ ret = sr_dev_config_set(sdi, cap, text);
break;
/* SR_T_BOOL will be handled by prop_toggled */
}
static void prop_toggled(GtkCellRendererToggle *cel, gchar *path,
GtkListStore *props)
{
- struct sr_device *device = g_object_get_data(G_OBJECT(props), "device");
+ struct sr_dev_inst *sdi = g_object_get_data(G_OBJECT(props), "sdi");
GtkTreeIter iter;
int type, cap;
int ret;
gboolean val;
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(props), &iter, path);
gtk_tree_model_get(GTK_TREE_MODEL(props), &iter,
- DEV_PROP_CAPABILITY, &cap,
+ DEV_PROP_HWCAP, &cap,
DEV_PROP_TYPE, &type, -1);
val = !gtk_cell_renderer_toggle_get_active(cel);
- ret = device->plugin-> set_configuration(device->plugin_index, cap,
- GINT_TO_POINTER(val));
+ ret = sr_dev_config_set(sdi, cap, GINT_TO_POINTER(val));
if (!ret)
gtk_list_store_set(props, &iter, DEV_PROP_BOOLVALUE, val, -1);
{
(void)action;
- struct sr_device *device = g_object_get_data(G_OBJECT(parent), "device");
- if (!device)
+ struct sr_dev_inst *sdi = g_object_get_data(G_OBJECT(parent), "sdi");
+ if (!sdi)
return;
GtkWidget *dialog = gtk_dialog_new_with_buttons("Device Properties",
G_TYPE_BOOLEAN, G_TYPE_STRING,
G_TYPE_BOOLEAN);
gtk_tree_view_set_model(GTK_TREE_VIEW(tv), GTK_TREE_MODEL(props));
- int *capabilities = device->plugin->get_capabilities();
+ const int *hwcaps;
int cap;
+
+ /* TODO: Error handling. */
+ sr_info_get(sdi->driver, SR_DI_HWCAPS, (const void **)&hwcaps, sdi);
+
GtkTreeIter iter;
- for (cap = 0; capabilities[cap]; cap++) {
- struct sr_hwcap_option *hwo;
- if (!(hwo = sr_hwplugins_hwcap_get(capabilities[cap])))
+ for (cap = 0; hwcaps[cap]; cap++) {
+ const struct sr_hwcap_option *hwo;
+ if (!(hwo = sr_devopt_get(hwcaps[cap])))
continue;
gtk_list_store_append(props, &iter);
gtk_list_store_set(props, &iter,
- DEV_PROP_CAPABILITY, capabilities[cap],
+ DEV_PROP_HWCAP, hwcaps[cap],
DEV_PROP_TYPE, hwo->type,
DEV_PROP_SHORTNAME, hwo->shortname,
DEV_PROP_DESCRIPTION, hwo->description,
/* Save device with list so that property can be set by edited
* handler. */
- g_object_set_data(G_OBJECT(props), "device", device);
+ g_object_set_data(G_OBJECT(props), "sdi", sdi);
/* Add columns to the tree view */
GtkTreeViewColumn *col;
static void probe_toggled(GtkCellRenderer *cel, gchar *path,
GtkTreeModel *probes)
{
- struct sr_device *device = g_object_get_data(G_OBJECT(probes), "device");
+ struct sr_dev_inst *sdi = g_object_get_data(G_OBJECT(probes), "sdi");
GtkTreeIter iter;
struct sr_probe *probe;
gint i;
gtk_tree_model_get_iter_from_string(probes, &iter, path);
gtk_tree_model_get(probes, &iter, PROBE_NUMBER, &i,
PROBE_ENABLED, &en, -1);
- probe = sr_dev_probe_find(device, i);
- probe->enabled = !en;
+ sr_dev_probe_enable(sdi, i, FALSE);
gtk_list_store_set(GTK_LIST_STORE(probes), &iter,
PROBE_ENABLED, probe->enabled, -1);
}
static void probe_named(GtkCellRendererText *cel, gchar *path, gchar *text,
GtkTreeModel *probes)
{
- struct sr_device *device = g_object_get_data(G_OBJECT(probes), "device");
+ struct sr_dev_inst *sdi = g_object_get_data(G_OBJECT(probes), "sdi");
GtkTreeIter iter;
gint i;
gtk_tree_model_get_iter_from_string(probes, &iter, path);
gtk_tree_model_get(probes, &iter, PROBE_NUMBER, &i, -1);
- sr_dev_probe_name(device, i, text);
+ sr_dev_probe_name_set(sdi, i, text);
gtk_list_store_set(GTK_LIST_STORE(probes), &iter, PROBE_NAME, text, -1);
}
static void probe_trigger_set(GtkCellRendererText *cel, gchar *path,
gchar *text, GtkTreeModel *probes)
{
- struct sr_device *device = g_object_get_data(G_OBJECT(probes), "device");
+ struct sr_dev_inst *sdi = g_object_get_data(G_OBJECT(probes), "sdi");
GtkTreeIter iter;
gint i;
gtk_tree_model_get_iter_from_string(probes, &iter, path);
gtk_tree_model_get(probes, &iter, PROBE_NUMBER, &i, -1);
- sr_dev_trigger_set(device, i, text);
+ sr_dev_trigger_set(sdi, i, text);
gtk_list_store_set(GTK_LIST_STORE(probes), &iter,
PROBE_TRIGGER, text, -1);
}
{
(void)action;
- struct sr_device *device = g_object_get_data(G_OBJECT(parent), "device");
- if (!device)
+ struct sr_dev_inst *sdi = g_object_get_data(G_OBJECT(parent), "sdi");
+ if (!sdi)
return;
GtkWidget *dialog = gtk_dialog_new_with_buttons("Configure Probes",
GtkTreeIter iter;
GSList *p;
int i;
- for (p = device->probes, i = 1; p; p = g_slist_next(p), i++) {
+ for (p = sdi->probes, i = 1; p; p = g_slist_next(p), i++) {
struct sr_probe *probe = p->data;
gtk_list_store_append(probes, &iter);
gtk_list_store_set(probes, &iter, PROBE_NUMBER, i,
/* Save device with list so that property can be set by edited
* handler. */
- g_object_set_data(G_OBJECT(probes), "device", device);
+ g_object_set_data(G_OBJECT(probes), "sdi", sdi);
/* Add columns to the tree view */
GtkTreeViewColumn *col;
{
(void)action;
- struct sr_device *device = g_object_get_data(G_OBJECT(parent), "device");
+ struct sr_dev_inst *sdi = g_object_get_data(G_OBJECT(parent), "sdi");
GtkEntry *timesamples = g_object_get_data(parent, "timesamples");
GtkComboBox *timeunit = g_object_get_data(parent, "timeunit");
gint i = gtk_combo_box_get_active(timeunit);
}
if (time_msec) {
- if (sr_hwplugin_has_hwcap(device->plugin, SR_HWCAP_LIMIT_MSEC)) {
- if (device->plugin->set_configuration(device->plugin_index,
- SR_HWCAP_LIMIT_MSEC,
+ if (sr_driver_hwcap_exists(sdi->driver, SR_HWCAP_LIMIT_MSEC)) {
+ if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_MSEC,
&time_msec) != SR_OK) {
g_critical("Failed to configure time limit.");
sr_session_destroy();
* convert to samples based on the samplerate.
*/
limit_samples = 0;
- if (sr_dev_has_hwcap(device, SR_HWCAP_SAMPLERATE)) {
+ if (sr_dev_has_hwcap(sdi, SR_HWCAP_SAMPLERATE)) {
guint64 tmp_u64;
- tmp_u64 = *((uint64_t *) device->plugin->get_device_info(
- device->plugin_index,
- SR_DI_CUR_SAMPLERATE));
+ sr_info_get(sdi->driver, SR_DI_CUR_SAMPLERATE,
+ (const void **)&tmp_u64, sdi);
limit_samples = tmp_u64 * time_msec / (uint64_t) 1000;
}
if (limit_samples == 0) {
return;
}
- if (device->plugin->set_configuration(device->plugin_index,
- SR_HWCAP_LIMIT_SAMPLES,
+ if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES,
&limit_samples) != SR_OK) {
g_critical("Failed to configure time-based sample limit.");
return;
}
}
if (limit_samples) {
- if (device->plugin->set_configuration(device->plugin_index,
- SR_HWCAP_LIMIT_SAMPLES,
- &limit_samples) != SR_OK) {
+ if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES,
+ &limit_samples) != SR_OK) {
g_critical("Failed to configure sample limit.");
return;
}
}
- if (device->plugin->set_configuration(device->plugin_index,
- SR_HWCAP_PROBECONFIG, (char *)device->probes) != SR_OK) {
+#if 0
+ if (sr_dev_config_set(sdi,
+ SR_HWCAP_PROBECONFIG, (char *)sdi->probes) != SR_OK) {
printf("Failed to configure probes.\n");
sr_session_destroy();
return;
}
+#endif
if (sr_session_start() != SR_OK) {
g_critical("Failed to start session.");
"Exit the program", G_CALLBACK(gtk_main_quit) },
{"ViewMenu", NULL, "_View", NULL, NULL, NULL},
- {"ViewZoomIn", GTK_STOCK_ZOOM_IN, "Zoom _In", "<control>z", NULL,
+ {"ViewZoomIn", GTK_STOCK_ZOOM_IN, "Zoom _In", "plus", NULL,
G_CALLBACK(zoom_in)},
- {"ViewZoomOut", GTK_STOCK_ZOOM_OUT, "Zoom _Out", "<control><shift>Z",
+ {"ViewZoomOut", GTK_STOCK_ZOOM_OUT, "Zoom _Out", "minus",
NULL, G_CALLBACK(zoom_out)},
{"ViewZoomFit", GTK_STOCK_ZOOM_FIT, NULL, NULL,
NULL, G_CALLBACK(zoom_fit)},
{"HelpMenu", NULL, "_Help", NULL, NULL, NULL},
- {"HelpWiki", GTK_STOCK_ABOUT, "Sigrok _Wiki", NULL, NULL,
+ {"HelpWiki", GTK_STOCK_ABOUT, "sigrok _Wiki", NULL, NULL,
G_CALLBACK(help_wiki)},
{"HelpAbout", GTK_STOCK_ABOUT, "_About", NULL, NULL,
G_CALLBACK(help_about)},
toolbar = GTK_TOOLBAR(gtk_ui_manager_get_widget(ui, "/toolbar"));
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(toolbar), FALSE, TRUE, 0);
- /* Device selection GtkComboBox */
- GtkToolItem *toolitem = gtk_tool_item_new();
- GtkWidget *align = gtk_alignment_new(0.5, 0.5, 2, 0);
- GtkWidget *dev = dev_select_combo_box_new(parent);
-
- gtk_container_add(GTK_CONTAINER(align), dev);
- gtk_container_add(GTK_CONTAINER(toolitem), align);
- gtk_toolbar_insert(toolbar, toolitem, 0);
-
/* Time/Samples entry */
- toolitem = gtk_tool_item_new();
+ GtkToolItem *toolitem = gtk_tool_item_new();
GtkWidget *timesamples = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(timesamples), "100");
gtk_entry_set_alignment(GTK_ENTRY(timesamples), 1.0);
/* Time unit combo box */
toolitem = gtk_tool_item_new();
- align = gtk_alignment_new(0.5, 0.5, 2, 0);
+ GtkWidget *align = gtk_alignment_new(0.5, 0.5, 2, 0);
GtkWidget *timeunit = gtk_combo_box_new_text();
gtk_combo_box_append_text(GTK_COMBO_BOX(timeunit), "samples");
gtk_combo_box_append_text(GTK_COMBO_BOX(timeunit), "ms");
g_object_set_data(G_OBJECT(parent), "timesamples", timesamples);
g_object_set_data(G_OBJECT(parent), "timeunit", timeunit);
+ /* Device selection GtkComboBox */
+ toolitem = gtk_tool_item_new();
+ align = gtk_alignment_new(0.5, 0.5, 2, 0);
+ GtkWidget *dev = dev_select_combo_box_new(parent);
+
+ gtk_container_add(GTK_CONTAINER(align), dev);
+ gtk_container_add(GTK_CONTAINER(toolitem), align);
+ gtk_toolbar_insert(toolbar, toolitem, 0);
+
+
return GTK_WIDGET(vbox);
}