Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plot not using device labels #488

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
83 changes: 23 additions & 60 deletions oscplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ struct channel_settings {
unsigned type;
char *name;
char *parent_name;
struct iio_device *dev;
struct iio_context *ctx;
GdkRGBA graph_color;

struct iio_device * (*get_iio_parent)(PlotChn *);
gfloat * (*get_data_ref)(PlotChn *);
void (*assert_used_iio_channels)(PlotChn *, bool);
void (*destroy)(PlotChn *);
Expand Down 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 @@ -1883,12 +1882,11 @@ bool constellation_transform_function(Transform *tr, gboolean init_transform)

/* Plot iio channel definitions */

static struct iio_device * plot_iio_channel_get_iio_parent(PlotChn *obj);
static gfloat* plot_iio_channel_get_data_ref(PlotChn *obj);
static void plot_iio_channel_assert_channels(PlotChn *obj, bool assert);
static void plot_iio_channel_destroy(PlotChn *obj);

static PlotIioChn * plot_iio_channel_new(struct iio_context *ctx)
static PlotIioChn * plot_iio_channel_new(struct iio_context *ctx, struct iio_device *dev)
{
PlotIioChn *obj;

Expand All @@ -1899,30 +1897,15 @@ static PlotIioChn * plot_iio_channel_new(struct iio_context *ctx)
}

obj->base.type = PLOT_IIO_CHANNEL;
obj->base.dev = dev;
obj->base.ctx = ctx;
obj->base.get_iio_parent = *plot_iio_channel_get_iio_parent;
obj->base.get_data_ref = *plot_iio_channel_get_data_ref;
obj->base.assert_used_iio_channels = *plot_iio_channel_assert_channels;
obj->base.destroy = *plot_iio_channel_destroy;

return obj;
}

static struct iio_device *plot_iio_channel_get_iio_parent(PlotChn *obj)
{
PlotIioChn *this = (PlotIioChn *)obj;
struct iio_device *iio_dev = NULL;
struct extra_info *ch_info;

if (this && this->iio_chn) {
ch_info = iio_channel_get_data(this->iio_chn);
if (ch_info)
iio_dev = ch_info->dev;
}

return iio_dev;
}

static gfloat* plot_iio_channel_get_data_ref(PlotChn *obj)
{
PlotIioChn *this = (PlotIioChn *)obj;
Expand Down Expand Up @@ -1966,7 +1949,6 @@ static void plot_iio_channel_destroy(PlotChn *obj)

/* Plot math channel definitions */

static struct iio_device * plot_math_channel_get_iio_parent(PlotChn *obj);
static gfloat * plot_math_channel_get_data_ref(PlotChn *obj);
static void plot_math_channel_assert_channels(PlotChn *obj, bool assert);
static void plot_math_channel_destroy(PlotChn *obj);
Expand All @@ -1983,27 +1965,13 @@ static PlotMathChn * plot_math_channel_new(struct iio_context *ctx)

obj->base.type = PLOT_MATH_CHANNEL;
obj->base.ctx = ctx;
obj->base.get_iio_parent = *plot_math_channel_get_iio_parent;
obj->base.get_data_ref = *plot_math_channel_get_data_ref;
obj->base.assert_used_iio_channels = *plot_math_channel_assert_channels;
obj->base.destroy = *plot_math_channel_destroy;

return obj;
}

static struct iio_device *plot_math_channel_get_iio_parent(PlotChn *obj)
{
PlotMathChn *this = (PlotMathChn *)obj;
struct iio_device *iio_dev = NULL;

if (this && this->iio_device_name) {
iio_dev = iio_context_find_device(this->base.ctx,
this->iio_device_name);
}

return iio_dev;
}

static gfloat * plot_math_channel_get_data_ref(PlotChn *obj)
{
PlotMathChn *this = (PlotMathChn *)obj;
Expand Down Expand Up @@ -2392,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 All @@ -2405,17 +2371,10 @@ static void notebook_info_set_page_visibility(GtkNotebook *nb, int page, bool vi

static struct iio_device * transform_get_device_parent(Transform *transform)
{
struct iio_device *iio_dev = NULL;
PlotChn *plot_ch;

if (!transform || !transform->plot_channels)
if (!transform || !transform->plot_channels || !transform->plot_channels->data)
return NULL;

plot_ch = transform->plot_channels->data;
if (plot_ch)
iio_dev = plot_ch->get_iio_parent(plot_ch);

return iio_dev;
return ((PlotChn *)transform->plot_channels->data)->dev;
}

static void update_transform_settings(OscPlot *plot, Transform *transform)
Expand Down Expand Up @@ -2788,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 @@ -3036,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 @@ -3517,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 @@ -3957,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 All @@ -3981,7 +3939,7 @@ static void device_list_treeview_init(OscPlot *plot)
iio_channel_get_id(ch);
PlotIioChn *pic;

pic = plot_iio_channel_new(priv->ctx);
pic = plot_iio_channel_new(priv->ctx, dev);
if (!pic) {
fprintf(stderr, "Could not create an iio plot"
"channel with name %s in function %s\n",
Expand Down Expand Up @@ -4067,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 @@ -4760,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 @@ -5266,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 Expand Up @@ -6340,6 +6295,7 @@ static int math_expression_get_settings(OscPlot *plot, PlotMathChn *pmc)
bool invalid_channels;
const char *channel_name;
char *expression_name;
struct iio_device *dev;

math_device_cmb_changed_cb(GTK_COMBO_BOX_TEXT(priv->math_device_select), plot);

Expand All @@ -6349,6 +6305,13 @@ static int math_expression_get_settings(OscPlot *plot, PlotMathChn *pmc)
return -1;
}

dev = iio_context_find_device(priv->ctx, active_device);
if (dev) {
pmc->base.dev = dev;
} else {
fprintf(stderr, "Error: Failed to get 'iio_device *' for %s\n", active_device);
}

if (pmc->txt_math_expression)
gtk_text_buffer_set_text(priv->math_expression,
pmc->txt_math_expression, -1);
Expand Down
Loading