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 <[email protected]>
  • Loading branch information
dNechita committed Mar 26, 2024
1 parent 8ec10df commit f3e8d17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
8 changes: 4 additions & 4 deletions osc.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ 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 get_iio_device_label_or_name(dev);
}

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

rx_update_device_sampling_freq(iio_device_get_id(dev), freq);
rx_update_device_sampling_freq(get_iio_device_label_or_name(dev), freq);
}

if (ctx)
Expand Down Expand Up @@ -1818,8 +1818,8 @@ 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(
get_iio_device_label_or_name(dev), USE_INTERN_SAMPLING_FREQ);
}
}

Expand Down
25 changes: 9 additions & 16 deletions oscplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,7 @@ 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 get_iio_device_label_or_name(dev);
next_iter = gtk_tree_model_iter_next(model, &iter);
}

Expand Down Expand Up @@ -2361,9 +2360,7 @@ static int plot_get_sample_count_for_transform(OscPlot *plot, Transform *transfo
if (!iio_dev)
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));
return plot_get_sample_count_of_device(plot, get_iio_device_label_or_name(iio_dev));
}

static void notebook_info_set_page_visibility(GtkNotebook *nb, int page, bool visbl)
Expand Down Expand Up @@ -2750,7 +2747,7 @@ 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 = get_iio_device_label_or_name(dev);

if (info->input_device == false)
continue;
Expand Down Expand Up @@ -2998,7 +2995,7 @@ 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 = get_iio_device_label_or_name(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 +3476,7 @@ 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 = get_iio_device_label_or_name(dev);
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(box), name);
}

Expand Down Expand Up @@ -3919,8 +3916,7 @@ 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 = get_iio_device_label_or_name(dev);

if (dev_info->input_device == false)
continue;
Expand Down Expand Up @@ -4029,8 +4025,7 @@ 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 = get_iio_device_label_or_name(dev);
struct extra_dev_info *dev_info = iio_device_get_data(dev);

if (dev_info->input_device == false)
Expand Down Expand Up @@ -4722,8 +4717,7 @@ 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 = get_iio_device_label_or_name(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 +5222,7 @@ 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 = get_iio_device_label_or_name(dev);
if (!strcmp(id, name))
return i;
}
Expand Down

0 comments on commit f3e8d17

Please sign in to comment.