Skip to content

Commit 0ce16d2

Browse files
committed
osc: Identify iio_device by label 1st, name 2nd, id 3rd
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]>
1 parent a8f597a commit 0ce16d2

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

Diff for: osc.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static const char * device_name_check(const char *name)
451451
if (!dev)
452452
return NULL;
453453

454-
return iio_device_get_name(dev) ?: iio_device_get_id(dev);
454+
return get_iio_device_label_or_name(dev);
455455
}
456456

457457
/*
@@ -1513,7 +1513,7 @@ static int capture_setup(void)
15131513
min_timeout = timeout;
15141514
}
15151515

1516-
rx_update_device_sampling_freq(iio_device_get_id(dev), freq);
1516+
rx_update_device_sampling_freq(get_iio_device_label_or_name(dev), freq);
15171517
}
15181518

15191519
if (ctx) {
@@ -1824,8 +1824,8 @@ static void init_device_list(struct iio_context *_ctx)
18241824
iio_channel_set_data(ch, info);
18251825
}
18261826

1827-
rx_update_device_sampling_freq(iio_device_get_name(dev) ?:
1828-
iio_device_get_id(dev), USE_INTERN_SAMPLING_FREQ);
1827+
rx_update_device_sampling_freq(
1828+
get_iio_device_label_or_name(dev), USE_INTERN_SAMPLING_FREQ);
18291829
}
18301830
}
18311831

Diff for: oscplot.c

+9-16
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,7 @@ const char * osc_plot_get_active_device (OscPlot *plot)
646646
while (next_iter) {
647647
gtk_tree_model_get(model, &iter, ELEMENT_REFERENCE, &dev, DEVICE_ACTIVE, &active, -1);
648648
if (active)
649-
return iio_device_get_name(dev) ?:
650-
iio_device_get_id(dev);
649+
return get_iio_device_label_or_name(dev);
651650
next_iter = gtk_tree_model_iter_next(model, &iter);
652651
}
653652

@@ -2361,9 +2360,7 @@ static int plot_get_sample_count_for_transform(OscPlot *plot, Transform *transfo
23612360
if (!iio_dev)
23622361
iio_dev = priv->current_device;
23632362

2364-
return plot_get_sample_count_of_device(plot,
2365-
iio_device_get_name(iio_dev) ?:
2366-
iio_device_get_id(iio_dev));
2363+
return plot_get_sample_count_of_device(plot, get_iio_device_label_or_name(iio_dev));
23672364
}
23682365

23692366
static void notebook_info_set_page_visibility(GtkNotebook *nb, int page, bool visbl)
@@ -2750,7 +2747,7 @@ static void collect_parameters_from_plot(OscPlot *plot)
27502747
for (i = 0; i < iio_context_get_devices_count(ctx); i++) {
27512748
struct iio_device *dev = iio_context_get_device(ctx, i);
27522749
struct extra_dev_info *info = iio_device_get_data(dev);
2753-
const char *dev_name = iio_device_get_name(dev) ?: iio_device_get_id(dev);
2750+
const char *dev_name = get_iio_device_label_or_name(dev);
27542751

27552752
if (info->input_device == false)
27562753
continue;
@@ -2998,7 +2995,7 @@ static void device_rx_info_update(OscPlotPrivate *priv)
29982995

29992996
for (i = 0; i < num_devices; i++) {
30002997
struct iio_device *dev = iio_context_get_device(priv->ctx, i);
3001-
const char *name = iio_device_get_name(dev) ?: iio_device_get_id(dev);
2998+
const char *name = get_iio_device_label_or_name(dev);
30022999
struct extra_dev_info *dev_info = iio_device_get_data(dev);
30033000
double freq, percent, seconds;
30043001
char freq_prefix, sec_prefix;
@@ -3479,7 +3476,7 @@ static bool comboboxtext_input_devices_fill(struct iio_context *iio_ctx, GtkComb
34793476
if (dev_info->input_device == false)
34803477
continue;
34813478

3482-
name = iio_device_get_name(dev) ?: iio_device_get_id(dev);
3479+
name = get_iio_device_label_or_name(dev);
34833480
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(box), name);
34843481
}
34853482

@@ -3919,8 +3916,7 @@ static void device_list_treeview_init(OscPlot *plot)
39193916
for (i = 0; i < iio_context_get_devices_count(ctx); i++) {
39203917
struct iio_device *dev = iio_context_get_device(ctx, i);
39213918
struct extra_dev_info *dev_info = iio_device_get_data(dev);
3922-
const char *dev_name = iio_device_get_name(dev) ?:
3923-
iio_device_get_id(dev);
3919+
const char *dev_name = get_iio_device_label_or_name(dev);
39243920

39253921
if (dev_info->input_device == false)
39263922
continue;
@@ -4029,8 +4025,7 @@ static void saveas_channels_list_fill(OscPlot *plot)
40294025

40304026
for (i = 0; i < num_devices; i++) {
40314027
struct iio_device *dev = iio_context_get_device(priv->ctx, i);
4032-
const char *name = iio_device_get_name(dev) ?:
4033-
iio_device_get_id(dev);
4028+
const char *name = get_iio_device_label_or_name(dev);
40344029
struct extra_dev_info *dev_info = iio_device_get_data(dev);
40354030

40364031
if (dev_info->input_device == false)
@@ -4722,8 +4717,7 @@ static void save_as(OscPlot *plot, const char *filename, int type)
47224717

47234718
dev = iio_context_get_device(ctx, d);
47244719
dev_info = iio_device_get_data(dev);
4725-
dev_name = iio_device_get_name(dev) ?:
4726-
iio_device_get_id(dev);
4720+
dev_name = get_iio_device_label_or_name(dev);
47274721

47284722
/* Find which channel need to be saved */
47294723
save_channels_mask = get_user_saveas_channel_selection(plot, &nb_channels);
@@ -5228,8 +5222,7 @@ static int device_find_by_name(struct iio_context *ctx, const char *name)
52285222

52295223
for (i = 0; i < num_devices; i++) {
52305224
struct iio_device *dev = iio_context_get_device(ctx, i);
5231-
const char *id = iio_device_get_name(dev) ?:
5232-
iio_device_get_id(dev);
5225+
const char *id = get_iio_device_label_or_name(dev);
52335226
if (!strcmp(id, name))
52345227
return i;
52355228
}

0 commit comments

Comments
 (0)