From f0e1d50bc12437487120fb82806b3cc5d5d1521d Mon Sep 17 00:00:00 2001 From: Dan Nechita Date: Mon, 29 Jul 2019 15:58:42 +0300 Subject: [PATCH] oscplot.c: Allow channels to be enabled by default and un-toggleable Signed-off-by: Dan Nechita --- datatypes.h | 6 ++++++ oscplot.c | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/datatypes.h b/datatypes.h index c25a64ed0..376eb09af 100644 --- a/datatypes.h +++ b/datatypes.h @@ -40,6 +40,11 @@ enum { TRANSFORMS_TYPES_COUNT }; +enum plot_channel_constraints { + CONSTR_CHN_INITIAL_ENABLED = 1 << 0, /* The channel initial state is owerwritten to ENABLE state */ + CONSTR_CHN_UNTOGGLEABLE = 1 << 1, /* The channel state cannot be changed and is displayed as grey-out */ +}; + typedef struct _transform Transform; typedef struct _tr_list TrList; @@ -50,6 +55,7 @@ struct extra_info { int shadow_of_enabled; bool may_be_enabled; double lo_freq; + unsigned int constraints; }; struct extra_dev_info { diff --git a/oscplot.c b/oscplot.c index 31828b1e0..c2d925484 100644 --- a/oscplot.c +++ b/oscplot.c @@ -3367,6 +3367,16 @@ static void iter_children_sensitivity_update(GtkTreeModel *model, GtkTreeIter *i next_iter = true; while (next_iter) { + struct iio_channel *chn; + gtk_tree_model_get(model, &child, ELEMENT_REFERENCE, &chn, -1); + struct extra_info *info = iio_channel_get_data(chn); + if (info) { + if (info->constraints & CONSTR_CHN_UNTOGGLEABLE) { + next_iter = gtk_tree_model_iter_next(model, &child); + continue; + } + } + gtk_tree_store_set(GTK_TREE_STORE(model), &child, SENSITIVE, state, -1); if (state == false) gtk_tree_store_set(GTK_TREE_STORE(model), &child, CHANNEL_ACTIVE, state, -1); @@ -3673,16 +3683,26 @@ static void plot_channels_add_channel(OscPlot *plot, PlotChn *pchn) if (ctx && (iio_dev = iio_context_find_device(ctx, pchn->parent_name))) iio_chn = iio_device_find_channel(iio_dev, pchn->name, false); + bool sensitive = true; + bool active = false; + + /* Check if there are any channel constraints */ + struct extra_info *ch_info = iio_channel_get_data(iio_chn); + if (ch_info) { + active = (ch_info->constraints & CONSTR_CHN_INITIAL_ENABLED); + sensitive = !(ch_info->constraints & CONSTR_CHN_UNTOGGLEABLE); + } + gtk_tree_store_append(treestore, &child_iter, &parent_iter); gtk_tree_store_set(treestore, &child_iter, ELEMENT_NAME, pchn->name, IS_CHANNEL, TRUE, CHANNEL_TYPE, pchn->type, - CHANNEL_ACTIVE, FALSE, + CHANNEL_ACTIVE, active, ELEMENT_REFERENCE, iio_chn, CHANNEL_SETTINGS, pchn, CHANNEL_COLOR_ICON, new_icon, - SENSITIVE, TRUE, + SENSITIVE, sensitive, PLOT_TYPE, TIME_PLOT, -1); }