Skip to content

Commit

Permalink
oscplot.c: Allow channels to be enabled by default and un-toggleable
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Nechita <[email protected]>
  • Loading branch information
dNechita authored and commodo committed Jul 29, 2019
1 parent 018b16c commit f0e1d50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down
24 changes: 22 additions & 2 deletions oscplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit f0e1d50

Please sign in to comment.