Skip to content

Commit

Permalink
Osc: In a capture window display only input devices that have buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
dNechita committed Apr 28, 2014
1 parent 72d1605 commit b257393
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct extra_info {
};

struct extra_dev_info {
bool input_device;
struct iio_buffer *buffer;
unsigned int sample_count;
double adc_freq, lo_freq;
Expand Down
22 changes: 22 additions & 0 deletions osc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,9 @@ static gboolean capture_process(void)
unsigned int nb_channels = iio_device_get_channels_count(dev);
unsigned int sample_count = dev_info->sample_count;

if (dev_info->input_device == false)
continue;

if (sample_size == 0)
continue;

Expand Down Expand Up @@ -1541,6 +1544,24 @@ void sigterm (int signum)
application_quit();
}

bool is_input_device(const struct iio_device *dev)
{
struct iio_channel *ch;
int nb_channels, i;

if (!dev)
return false;

nb_channels = iio_device_get_channels_count(dev);
for (i = 0; i < nb_channels; i++) {
ch = iio_device_get_channel(dev, i);
if (iio_channel_is_scan_element(ch) && !iio_channel_is_output(ch))
return true;
}

return false;
}

static void init_device_list(void)
{
unsigned int i, j;
Expand All @@ -1556,6 +1577,7 @@ static void init_device_list(void)
unsigned int nb_channels = iio_device_get_channels_count(dev);
struct extra_dev_info *dev_info = calloc(1, sizeof(*dev_info));
iio_device_set_data(dev, dev_info);
dev_info->input_device = is_input_device(dev);

for (j = 0; j < nb_channels; j++) {
struct iio_channel *ch = iio_device_get_channel(dev, j);
Expand Down
1 change: 0 additions & 1 deletion osc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
extern GtkWidget *capture_graph;
extern gint capture_function;
extern bool str_endswith(const char *str, const char *needle);
extern bool is_input_device(const char *device);

#define TMP_INI_FILE "/tmp/.%s.tmp"
#ifndef MAX_MARKERS
Expand Down
35 changes: 32 additions & 3 deletions oscplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ struct _OscPlotPrivate

GtkTextBuffer* tbuf;

unsigned int nb_input_devices;

struct plot_geometry size;

int frame_counter;
Expand Down Expand Up @@ -636,6 +638,11 @@ static gboolean check_valid_setup(OscPlot *plot)

for (i = 0; i < num_devices; i++) {
struct iio_device *dev = iio_context_get_device(ctx, i);
struct extra_dev_info *dev_info = iio_device_get_data(dev);

if (dev_info->input_device == false)
continue;

is_valid = check_valid_setup_of_device(plot, dev);
if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->plot_domain)) == TIME_PLOT) {
if (!is_valid)
Expand Down Expand Up @@ -880,6 +887,9 @@ static void collect_parameters_from_plot(OscPlot *plot)
struct iio_device *dev = iio_context_get_device(ctx, i);
struct extra_dev_info *info = iio_device_get_data(dev);

if (info->input_device == false)
continue;

prms = malloc(sizeof(struct plot_params));
prms->plot_id = priv->object_id;
prms->sample_count = plot_sample_count_get(plot);
Expand All @@ -902,6 +912,9 @@ static void dispose_parameters_from_plot(OscPlot *plot)
struct extra_dev_info *info = iio_device_get_data(dev);
GSList *list = info->plots_sample_counts;

if (info->input_device == false)
continue;

for (node = list; node; node = g_slist_next(node)) {
prms = node->data;
if (prms->plot_id == priv->object_id) {
Expand Down Expand Up @@ -1099,6 +1112,11 @@ static void devices_transform_assignment(OscPlot *plot)
for (i = 0; i < num_devices; i++) {
struct iio_device *dev = iio_context_get_device(ctx, i);
const char *name = iio_device_get_name(dev) ?: iio_device_get_id(dev);
struct extra_dev_info *dev_info = iio_device_get_data(dev);

if (dev_info->input_device == false)
continue;

prm.enabled_channels = enabled_channels_of_device(treeview, name);
foreach_channel_iter_of_device(GTK_TREE_VIEW(priv->channel_list_view),
name, *channels_transform_assignment, &prm);
Expand Down Expand Up @@ -1532,16 +1550,22 @@ static void device_list_treeview_init(OscPlot *plot)

treestore = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));

priv->nb_input_devices = 0;
for (i = 0; i < num_devices; i++) {
struct iio_device *dev = iio_context_get_device(ctx, i);
unsigned int nb_channels = iio_device_get_channels_count(dev);
struct extra_dev_info *dev_info = iio_device_get_data(dev);
const char *name = iio_device_get_name(dev) ?:
iio_device_get_id(dev);

if (dev_info->input_device == false)
continue;

gtk_tree_store_append(treestore, &iter, NULL);
gtk_tree_store_set(treestore, &iter, ELEMENT_NAME, name,
IS_DEVICE, TRUE, DEVICE_ACTIVE, !i, ELEMENT_REFERENCE,
dev, SENSITIVE, true, -1);
IS_DEVICE, TRUE, DEVICE_ACTIVE, !priv->nb_input_devices,
ELEMENT_REFERENCE, dev, SENSITIVE, true, -1);
priv->nb_input_devices++;

for (j = 0; j < nb_channels; j++) {
struct iio_channel *ch = iio_device_get_channel(dev, j);
Expand Down Expand Up @@ -1624,6 +1648,11 @@ static void saveas_channels_list_fill(OscPlot *plot)
struct iio_device *dev = iio_context_get_device(ctx, i);
const char *name = iio_device_get_name(dev) ?:
iio_device_get_id(dev);
struct extra_dev_info *dev_info = iio_device_get_data(dev);

if (dev_info->input_device == false)
continue;

gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->device_combobox), name);
}

Expand Down Expand Up @@ -3196,7 +3225,7 @@ static void plot_domain_changed_cb(GtkComboBox *box, OscPlot *plot)
foreach_device_iter(GTK_TREE_VIEW(plot->priv->channel_list_view),
*iter_children_plot_type_update, plot);

if (num_devices < 2)
if (plot->priv->nb_input_devices < 2)
return;

if (gtk_combo_box_get_active(box) != TIME_PLOT) {
Expand Down

0 comments on commit b257393

Please sign in to comment.