Skip to content

Commit

Permalink
osc: Identify iio_device by label 1st, name 2nd, id 3rd
Browse files Browse the repository at this point in the history
These changes help when multiple instances of the same type of driver exist. Otherwise we end up with mutiple iio_device with the same name.

Signed-off-by: Dan <dan.nechita@analog.com>
  • Loading branch information
dNechita committed Mar 25, 2024
1 parent 8ec10df commit 5a8b71f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
14 changes: 10 additions & 4 deletions osc.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ static const char * device_name_check(const char *name)
if (!dev)
return NULL;

return iio_device_get_name(dev) ?: iio_device_get_id(dev);
return iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev));
}

/*
Expand Down Expand Up @@ -1511,7 +1512,10 @@ static int capture_setup(void)
min_timeout = timeout;
}

rx_update_device_sampling_freq(iio_device_get_id(dev), freq);
rx_update_device_sampling_freq(
iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev)),
freq);
}

if (ctx)
Expand Down Expand Up @@ -1818,8 +1822,10 @@ static void init_device_list(struct iio_context *_ctx)
iio_channel_set_data(ch, info);
}

rx_update_device_sampling_freq(iio_device_get_name(dev) ?:
iio_device_get_id(dev), USE_INTERN_SAMPLING_FREQ);
rx_update_device_sampling_freq(
iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev)),
USE_INTERN_SAMPLING_FREQ);
}
}

Expand Down
33 changes: 18 additions & 15 deletions oscplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ const char * osc_plot_get_active_device (OscPlot *plot)
while (next_iter) {
gtk_tree_model_get(model, &iter, ELEMENT_REFERENCE, &dev, DEVICE_ACTIVE, &active, -1);
if (active)
return iio_device_get_name(dev) ?:
iio_device_get_id(dev);
return iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev));
next_iter = gtk_tree_model_iter_next(model, &iter);
}

Expand Down Expand Up @@ -2362,8 +2362,8 @@ static int plot_get_sample_count_for_transform(OscPlot *plot, Transform *transfo
iio_dev = priv->current_device;

return plot_get_sample_count_of_device(plot,
iio_device_get_name(iio_dev) ?:
iio_device_get_id(iio_dev));
iio_device_get_label(iio_dev) ?:
(iio_device_get_name(iio_dev) ?: iio_device_get_id(iio_dev)));
}

static void notebook_info_set_page_visibility(GtkNotebook *nb, int page, bool visbl)
Expand Down Expand Up @@ -2750,7 +2750,8 @@ static void collect_parameters_from_plot(OscPlot *plot)
for (i = 0; i < iio_context_get_devices_count(ctx); i++) {
struct iio_device *dev = iio_context_get_device(ctx, i);
struct extra_dev_info *info = iio_device_get_data(dev);
const char *dev_name = iio_device_get_name(dev) ?: iio_device_get_id(dev);
const char *dev_name = iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev));

if (info->input_device == false)
continue;
Expand Down Expand Up @@ -2998,7 +2999,8 @@ static void device_rx_info_update(OscPlotPrivate *priv)

for (i = 0; i < num_devices; i++) {
struct iio_device *dev = iio_context_get_device(priv->ctx, i);
const char *name = iio_device_get_name(dev) ?: iio_device_get_id(dev);
const char *name = iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev));
struct extra_dev_info *dev_info = iio_device_get_data(dev);
double freq, percent, seconds;
char freq_prefix, sec_prefix;
Expand Down Expand Up @@ -3479,7 +3481,8 @@ static bool comboboxtext_input_devices_fill(struct iio_context *iio_ctx, GtkComb
if (dev_info->input_device == false)
continue;

name = iio_device_get_name(dev) ?: iio_device_get_id(dev);
name = iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev));
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(box), name);
}

Expand Down Expand Up @@ -3919,8 +3922,8 @@ static void device_list_treeview_init(OscPlot *plot)
for (i = 0; i < iio_context_get_devices_count(ctx); i++) {
struct iio_device *dev = iio_context_get_device(ctx, i);
struct extra_dev_info *dev_info = iio_device_get_data(dev);
const char *dev_name = iio_device_get_name(dev) ?:
iio_device_get_id(dev);
const char *dev_name = iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev));

if (dev_info->input_device == false)
continue;
Expand Down Expand Up @@ -4029,8 +4032,8 @@ static void saveas_channels_list_fill(OscPlot *plot)

for (i = 0; i < num_devices; i++) {
struct iio_device *dev = iio_context_get_device(priv->ctx, i);
const char *name = iio_device_get_name(dev) ?:
iio_device_get_id(dev);
const char *name = iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev));
struct extra_dev_info *dev_info = iio_device_get_data(dev);

if (dev_info->input_device == false)
Expand Down Expand Up @@ -4722,8 +4725,8 @@ static void save_as(OscPlot *plot, const char *filename, int type)

dev = iio_context_get_device(ctx, d);
dev_info = iio_device_get_data(dev);
dev_name = iio_device_get_name(dev) ?:
iio_device_get_id(dev);
dev_name = iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev));

/* Find which channel need to be saved */
save_channels_mask = get_user_saveas_channel_selection(plot, &nb_channels);
Expand Down Expand Up @@ -5228,8 +5231,8 @@ static int device_find_by_name(struct iio_context *ctx, const char *name)

for (i = 0; i < num_devices; i++) {
struct iio_device *dev = iio_context_get_device(ctx, i);
const char *id = iio_device_get_name(dev) ?:
iio_device_get_id(dev);
const char *id = iio_device_get_label(dev) ?:
(iio_device_get_name(dev) ?: iio_device_get_id(dev));
if (!strcmp(id, name))
return i;
}
Expand Down

0 comments on commit 5a8b71f

Please sign in to comment.