Example #1
0
static void generateWavePeriod(void)
{
	int waveType = 0;
	double waveFreq;
	int i;
	struct iio_device *trigger = iio_context_find_device(ctx, "hrtimer-1");
	unsigned long triggerFreq;
	long long triggerFreqLL = 0;

	iio_device_attr_read_longlong(trigger, "frequency", &triggerFreqLL);
	triggerFreq = triggerFreqLL;

	/* Set the maximum frequency that user can select to 10% of the input generator frequency. */
	if (triggerFreq >= 10)
		gtk_range_set_range(GTK_RANGE(scale_freq), 0.1, triggerFreq / 10);

	wave_ampl = gtk_range_get_value(GTK_RANGE(scale_ampl));
	wave_offset = gtk_range_get_value(GTK_RANGE(scale_offset));
	waveFreq = gtk_range_get_value(GTK_RANGE(scale_freq));
	buffer_size = (unsigned int)round(triggerFreq / waveFreq);
	if (buffer_size < 2)
		buffer_size = 2;
	else if (buffer_size > 10000)
		buffer_size = 10000;
	current_sample = 0;

	soft_buffer_ch0 = g_renew(uint8_t, soft_buffer_ch0, buffer_size);

	gtk_range_set_value(GTK_RANGE(scale_freq), (double)triggerFreq / buffer_size);
	gtk_widget_queue_draw(scale_freq);

	if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn_sine)))
		waveType = SINEWAVE;
	else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn_square)))
		waveType = SQUAREWAVE;
	else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn_triangle)))
		waveType = TRIANGLE;
	else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn_sawtooth)))
		waveType = SAWTOOTH;
	FillSoftBuffer(waveType, soft_buffer_ch0);

	/* Also generate a preview of the output signal. */
	float_soft_buff = g_renew(gfloat, float_soft_buff,  2 * buffer_size);
	X = g_renew(gfloat, X, 2 * buffer_size);
	for (i = 0; i < 2 * buffer_size; i++)
		X[i] = i;
	for (i = 0; i < 2 * buffer_size; i++)
		float_soft_buff[i] = soft_buffer_ch0[i % buffer_size] * 3.3 / 256;
	gtk_databox_graph_remove_all(GTK_DATABOX(databox));
	databox_graph = gtk_databox_lines_new((2 * buffer_size), X, float_soft_buff,
							&color_prev_graph, 2);
	databox_graph_dots = gtk_databox_points_new((2 * buffer_size), X, float_soft_buff,
							&color_prev_graph_dots, 5);
	gtk_databox_graph_add(GTK_DATABOX(databox), databox_graph_dots);
	gtk_databox_graph_add(GTK_DATABOX(databox), databox_graph);
	gtk_databox_set_total_limits(GTK_DATABOX(databox), -0.2, (i - 1), 3.5, -0.2);
}
Example #2
0
GtkWidget* sliding_plot_new(guint nb_plot) {
  GtkWidget* databox = gtk_databox_new ();
  g_object_set_data(G_OBJECT(databox), "nb_plot", (gpointer)nb_plot);
  gfloat *X = g_new0 (gfloat, NB_POINTS);
  g_object_set_data(G_OBJECT(databox), "X", X);
  gpointer *Y = g_new0 (gpointer, nb_plot);
  g_object_set_data(G_OBJECT(databox), "Y", Y);
  guint nb_data = 0;
  g_object_set_data(G_OBJECT(databox), "nb_data", (gpointer)nb_data);
  guint _time = 0;
  g_object_set_data(G_OBJECT(databox), "time", (gpointer)_time);
  guint i;
  for (i=0; i< nb_plot; i++) {
    Y[i] = g_new0 (gfloat, NB_POINTS);
    GtkDataboxGraph *graph = gtk_databox_lines_new (NB_POINTS, X, Y[i], (GdkColor*)&(colors[i%NB_COLORS]), 1);
    gtk_databox_graph_add (GTK_DATABOX (databox), graph);
  }

  //  GtkDataboxGraph *grid = gtk_databox_grid_new (10, 10, (GdkColor*)&(colors[3]), 2);
  //  gtk_databox_graph_add (GTK_DATABOX (databox), grid);
    g_timeout_add(REFRESH_RATE, timeout_callback, databox);

  return databox;
}
static void
create_basics (void)
{
   GtkWidget *window = NULL;
   GtkWidget *vbox;
   GtkWidget *close_button;
   GtkWidget *box;
   GtkWidget *label;
   GtkWidget *separator;
   GtkWidget *table;
   GtkWidget *scrollbar;
   GtkWidget *ruler;
   GtkDataboxGraph *graph;
   gfloat min_x, max_x;
   gfloat min_y, max_y;
   gfloat *X;
   gfloat *Y;
   gfloat buffer;
   GdkColor color;
   gint i;

   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_size_request (window, 500, 500);

   g_signal_connect (GTK_OBJECT (window), "destroy",
		     G_CALLBACK (gtk_main_quit), NULL);

   gtk_window_set_title (GTK_WINDOW (window), "GtkDatabox: Basics");
   gtk_container_set_border_width (GTK_CONTAINER (window), 0);

   vbox = gtk_vbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (window), vbox);

   label =
      gtk_label_new
      ("\nThe code for this example demonstrates\n the the basic use of elementary functions\nfor utilizing the GtkDatabox widget.\n\nUsage:\nDraw a selection with the left button pressed,\nThan click into the selection.\nUse the right mouse button to zoom out.\nShift+ right mouse button zooms to default.");
   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
   separator = gtk_hseparator_new ();
   gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);


   /* Instead of the following stuff, you could also call 
    * gtk_databox_create_box_with_scrollbars_and_rulers
    * as it is done in the other examples.
    * Of course, you are more flexible in using scrollbars and rulers 
    * by doing it yourself. */
   table = gtk_table_new (3, 3, FALSE);
   box = gtk_databox_new ();
   gtk_table_attach (GTK_TABLE (table), box, 1, 2, 1, 2,
		     GTK_FILL | GTK_EXPAND | GTK_SHRINK,
		     GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);

   /* You can associate a scrollbar with a GtkDatabox widget either 
    * this way ...*/
   scrollbar = gtk_hscrollbar_new (NULL);
   gtk_databox_set_adjustment_x (GTK_DATABOX (box),
				gtk_range_get_adjustment (GTK_RANGE
							  (scrollbar)));
   gtk_table_attach (GTK_TABLE (table), scrollbar, 1, 2, 2, 3,
		     GTK_FILL | GTK_EXPAND | GTK_SHRINK, GTK_FILL, 0, 0);
   /* or this way ... */
   scrollbar = gtk_vscrollbar_new
      (gtk_databox_get_adjustment_y (GTK_DATABOX (box)));
   gtk_table_attach (GTK_TABLE (table), scrollbar, 2, 3, 1, 2,
		     GTK_FILL, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);


   ruler = gtk_databox_ruler_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_widget_set_sensitive (ruler, FALSE);

   gtk_table_attach (GTK_TABLE (table), ruler, 1, 2, 0, 1,
		     GTK_FILL | GTK_EXPAND | GTK_SHRINK, GTK_FILL, 0, 0);
   gtk_databox_set_ruler_x (GTK_DATABOX (box), GTK_DATABOX_RULER (ruler));

   ruler = gtk_databox_ruler_new (GTK_ORIENTATION_VERTICAL);
   gtk_widget_set_sensitive (ruler, FALSE);
   gtk_table_attach (GTK_TABLE (table), ruler, 0, 1, 1, 2,
		     GTK_FILL, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
   gtk_databox_set_ruler_y (GTK_DATABOX (box), GTK_DATABOX_RULER (ruler));
   /* end of gtk_databox_create_box_with_scrollbars_and_rulers */

   gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);

   color.red = 16383;
   color.green = 16383;
   color.blue = 16383;
   gtk_widget_modify_bg (box, GTK_STATE_NORMAL, &color);


   X = g_new0 (gfloat, POINTS);
   Y = g_new0 (gfloat, POINTS);

   for (i = 0; i < POINTS; i++)
   {
      X[i] = i;
      Y[i] = 100. * sin (i * 2 * G_PI / POINTS);
   }
   color.red = 0;
   color.green = 65535;
   color.blue = 0;

   graph = gtk_databox_points_new (POINTS, X, Y, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   X = g_new0 (gfloat, STEPS);
   Y = g_new0 (gfloat, STEPS);

   for (i = 0; i < STEPS / 2; i++)
   {
      X[i * 2] = X[i * 2 + 1] = 2 * (i + .5) * POINTS / STEPS;

      if (i > 0)
	 Y[i * 2 - 1] = 100. * sin ((i * 2) * 2 * G_PI / STEPS);
      Y[i * 2] = 100. * sin ((i * 2) * 2 * G_PI / STEPS);
      if (i == STEPS / 2 - 1)
	 Y[i * 2 + 1] = 100. * sin (((i + 1) * 2) * 2 * G_PI / STEPS);
   }
   color.red = 65535;
   color.green = 0;
   color.blue = 0;

   graph = gtk_databox_lines_new (STEPS, X, Y, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   X = g_new0 (gfloat, BARS);
   Y = g_new0 (gfloat, BARS);

   for (i = 0; i < BARS; i++)
   {
      X[i] = i * POINTS / BARS;
      Y[i] = 80. * sin (i * 2 * G_PI / BARS);
   }
   color.red = 0;
   color.green = 65535;
   color.blue = 65535;

   graph = gtk_databox_bars_new (BARS, X, Y, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   color.red = 32768;
   color.green = 32768;
   color.blue = 32768;

   graph = gtk_databox_cross_simple_new (&color, 0);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   /* Instead of doing stuff what you see below, you could call 
    * gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
    * as is done in the other examples 
    * Of course, you are more flexible in adjusting the scaling by doing 
    * it yourself, though. */
   if (0 >
       gtk_databox_calculate_extrema (GTK_DATABOX (box), &min_x, &max_x,
				      &min_y, &max_y))
   {
      g_warning ("Calculating extrema failed. Resorting to default values");
      min_x = -100.;
      min_y = -100.;
      max_x = +100.;
      max_y = +100.;
   }
   else
   {
      gfloat width = max_x - min_x;
      gfloat height = max_y - min_y;
      gfloat border = 0.05;

      min_x -= border * width;
      min_y -= border * height;
      max_x += border * width;
      max_y += border * height;
   }

   /* We want larger y values to be higher on the screen */
   buffer = min_y;
   min_y = max_y;
   max_y = buffer;

   gtk_databox_set_total_limits (GTK_DATABOX (box), min_x, max_x, min_y,
				 max_y);
   /* end of gtk_databox_auto_rescale */

   separator = gtk_hseparator_new ();
   gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 0);

   close_button = gtk_button_new_with_label ("close");
   g_signal_connect_swapped (GTK_OBJECT (close_button), "clicked",
			     G_CALLBACK (gtk_main_quit), GTK_OBJECT (box));
   gtk_box_pack_start (GTK_BOX (vbox), close_button, FALSE, FALSE, 0);
   gtk_widget_set_can_default(close_button, GTK_CAN_DEFAULT);
   gtk_widget_grab_default (close_button);
   gtk_widget_grab_focus (close_button);

   gtk_widget_show_all (window);
   gdk_window_set_cursor (box->window, gdk_cursor_new (GDK_CROSS));
}
Example #4
0
GtkWidget* tilt_display(struct tilt_data* td) {
  GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request (window, 1280, 800);

  GtkWidget* vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox1);

  GtkWidget *frame = gtk_frame_new ("rate");
  gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  gtk_box_pack_start (GTK_BOX (vbox1), frame, TRUE, TRUE, 0);

  GtkWidget* databox = gtk_databox_new();
  gfloat* prate = g_new0 (gfloat, td->nb_samples);
  gfloat* p_m_rate = g_new0 (gfloat, td->nb_samples);
  gfloat* pt = g_new0 (gfloat, td->nb_samples);
  int idx;
  for (idx=0; idx<td->nb_samples; idx++) {
    prate[idx] = td->rate[idx];
    p_m_rate[idx] = td->gyro[idx];
    pt[idx] = td->t[idx];
  }
  GdkColor red = {0, 65535, 0, 0};
  GdkColor green = {0, 0, 65535, 0};
  GdkColor blue = {0, 0, 0, 65535};
  GdkColor pink = {0, 65535, 0, 65535};
  GdkColor black = {0, 0, 0, 0};

  GtkDataboxGraph *grate = gtk_databox_lines_new (td->nb_samples, pt, prate, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), grate);

  GtkDataboxGraph *g_m_rate = gtk_databox_lines_new (td->nb_samples, pt, p_m_rate, &green, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_m_rate);

  GtkDataboxGraph *grid = gtk_databox_grid_new (10, 10, &black, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), grid);

  gtk_container_add (GTK_CONTAINER (frame), databox );
  gtk_databox_auto_rescale (GTK_DATABOX(databox), 0.);



  frame = gtk_frame_new ("angle");
  gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  gtk_box_pack_start (GTK_BOX (vbox1), frame, TRUE, TRUE, 0);

  databox = gtk_databox_new();
  gfloat* pangle = g_new0 (gfloat, td->nb_samples);
  gfloat* pm_angle = g_new0 (gfloat, td->nb_samples);
  gfloat* pe_angle = g_new0 (gfloat, td->nb_samples);
  for (idx=0; idx<td->nb_samples; idx++) {
    pangle[idx] = td->angle[idx];
    pm_angle[idx] = td->m_angle[idx];
    pe_angle[idx] = td->est_angle[idx];
  }

  GtkDataboxGraph *gangle = gtk_databox_lines_new (td->nb_samples, pt, pangle, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), gangle);

  GtkDataboxGraph *ge_angle = gtk_databox_lines_new (td->nb_samples, pt, pe_angle, &blue, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), ge_angle);

  GtkDataboxGraph *gm_angle = gtk_databox_lines_new (td->nb_samples, pt, pm_angle, &green, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), gm_angle);

  grid = gtk_databox_grid_new (10, 10, &black, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), grid);

  gtk_container_add (GTK_CONTAINER (frame), databox );
  gtk_databox_auto_rescale (GTK_DATABOX(databox), 0.);


  frame = gtk_frame_new ("bias");
  gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  gtk_box_pack_start (GTK_BOX (vbox1), frame, TRUE, TRUE, 0);

  databox = gtk_databox_new();
  gfloat* pbias = g_new0 (gfloat, td->nb_samples);
  gfloat* pest_bias = g_new0 (gfloat, td->nb_samples);
  for (idx=0; idx<td->nb_samples; idx++) {
    pbias[idx] = td->bias[idx];
    pest_bias[idx] = td->est_bias[idx];
  }
  GtkDataboxGraph *gest_bias = gtk_databox_lines_new (td->nb_samples, pt, pest_bias, &blue, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), gest_bias);

  GtkDataboxGraph *gbias = gtk_databox_lines_new (td->nb_samples, pt, pbias, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), gbias);

  grid = gtk_databox_grid_new (10, 10, &black, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), grid);

  gtk_container_add (GTK_CONTAINER (frame), databox );
  gtk_databox_auto_rescale (GTK_DATABOX(databox), 0.);


  frame = gtk_frame_new ("covariance");
  gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  gtk_box_pack_start (GTK_BOX (vbox1), frame, TRUE, TRUE, 0);

  databox = gtk_databox_new();
  gfloat* pP00 = g_new0 (gfloat, td->nb_samples);
  gfloat* pP01 = g_new0 (gfloat, td->nb_samples);
  gfloat* pP10 = g_new0 (gfloat, td->nb_samples);
  gfloat* pP11 = g_new0 (gfloat, td->nb_samples);
  for (idx=0; idx<td->nb_samples; idx++) {
    pP00[idx] = td->P00[idx];
    pP01[idx] = td->P01[idx];
    pP10[idx] = td->P10[idx];
    pP11[idx] = td->P11[idx];
  }
  GtkDataboxGraph *gP00 = gtk_databox_lines_new (td->nb_samples, pt, pP00, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), gP00);

  GtkDataboxGraph *gP01 = gtk_databox_lines_new (td->nb_samples, pt, pP01, &green, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), gP01);

  GtkDataboxGraph *gP10 = gtk_databox_lines_new (td->nb_samples, pt, pP10, &blue, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), gP10);

  GtkDataboxGraph *gP11 = gtk_databox_lines_new (td->nb_samples, pt, pP11, &pink, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), gP11);

  grid = gtk_databox_grid_new (10, 10, &black, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), grid);

  gtk_container_add (GTK_CONTAINER (frame), databox );
  gtk_databox_auto_rescale (GTK_DATABOX(databox), 0.);


  gtk_widget_show_all(window);
  return window;
}
static void
create_basics ()
{
   GtkWidget *window = NULL;
   GtkWidget *box;
   GtkWidget *scrollbar;
   GtkWidget *ruler;
   GtkDataboxGraph *graph;
   gfloat min_x, max_x;
   gfloat min_y, max_y;
   gfloat *X;
   gfloat *Y;
   gfloat buffer;
   GdkRGBA color;
   gint i;
   GladeXML *gxml;

   gxml = glade_xml_new (GLADE_FILE, NULL, NULL);

   /* This is important */
   glade_xml_signal_autoconnect (gxml);
   window = glade_xml_get_widget (gxml, "window");


   /* You could associate a scrollbar with a GtkDatabox widget either
    * this way ...*/
   scrollbar = glade_xml_get_widget (gxml, "scrollbar_x");
   box = glade_xml_get_widget (gxml, "box");
   gtk_databox_set_adjustment_x (GTK_DATABOX (box),
				gtk_range_get_adjustment (GTK_RANGE
							  (scrollbar)));

   /* or this way ... */
   scrollbar = glade_xml_get_widget (gxml, "scrollbar_y");
   gtk_databox_set_adjustment_y (GTK_DATABOX (box),
				gtk_range_get_adjustment (GTK_RANGE
							  (scrollbar)));
   ruler = glade_xml_get_widget (gxml, "ruler_x");
   gtk_databox_set_ruler_x (GTK_DATABOX (box), GTK_DATABOX_RULER (ruler));
   ruler = glade_xml_get_widget (gxml, "ruler_y");
   gtk_databox_set_ruler_y (GTK_DATABOX (box), GTK_DATABOX_RULER (ruler));
   /* end of gtk_databox_create_box_with_scrollbars_and_rulers */


   color.red = 0.33;
   color.green = 0.33;
   color.blue = 0.33;
   gtk_widget_override_background_color (box, GTK_STATE_FLAG_NORMAL, &color);


   X = g_new0 (gfloat, POINTS);
   Y = g_new0 (gfloat, POINTS);

   for (i = 0; i < POINTS; i++)
   {
      X[i] = i;
      Y[i] = 100. * sin (i * 2 * G_PI / POINTS);
   }
   color.red = 0;
   color.green = 1;
   color.blue = 0;
   color.alpha = 1;

   graph = gtk_databox_points_new (POINTS, X, Y, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   X = g_new0 (gfloat, STEPS);
   Y = g_new0 (gfloat, STEPS);

   for (i = 0; i < STEPS / 2; i++)
   {
      X[i * 2] = X[i * 2 + 1] = 2 * (i + .5) * POINTS / STEPS;

      if (i > 0)
	 Y[i * 2 - 1] = 100. * sin ((i * 2) * 2 * G_PI / STEPS);
      Y[i * 2] = 100. * sin ((i * 2) * 2 * G_PI / STEPS);
      if (i == STEPS / 2 - 1)
	 Y[i * 2 + 1] = 100. * sin (((i + 1) * 2) * 2 * G_PI / STEPS);
   }
   color.red = 1;
   color.green = 0;
   color.blue = 0;
   color.alpha = 1;

   graph = gtk_databox_lines_new (STEPS, X, Y, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   X = g_new0 (gfloat, BARS);
   Y = g_new0 (gfloat, BARS);

   for (i = 0; i < BARS; i++)
   {
      X[i] = i * POINTS / BARS;
      Y[i] = 80. * sin (i * 2 * G_PI / BARS);
   }
   color.red = 0;
   color.green = 1;
   color.blue = 1;
   color.alpha = 1;

   graph = gtk_databox_bars_new (BARS, X, Y, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   color.red = 0.5;
   color.green = 0.5;
   color.blue = 0.5;

   graph = gtk_databox_cross_simple_new (&color, 0);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   /* Instead of doing stuff what you see below, you could call
    * gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
    * as is done in the other examples
    * Of course, you are more flexible in adjusting the scaling by doing
    * it yourself, though. */
   if (0 >
       gtk_databox_calculate_extrema (GTK_DATABOX (box), &min_x, &max_x,
				      &min_y, &max_y))
   {
      g_warning ("Calculating extrema failed. Resorting to default values");
      min_x = -100.;
      min_y = -100.;
      max_x = +100.;
      max_y = +100.;
   }
   else
   {
      gfloat width = max_x - min_x;
      gfloat height = max_y - min_y;
      gfloat border = 0.05;

      min_x -= border * width;
      min_y -= border * height;
      max_x += border * width;
      max_y += border * height;
   }

   /* We want larger y values to be higher on the screen */
   buffer = min_y;
   min_y = max_y;
   max_y = buffer;

   gtk_databox_set_total_limits (GTK_DATABOX (box), min_x, max_x, min_y,
				 max_y);
   /* end of gtk_databox_auto_rescale */

   gtk_widget_show (window);
   gdk_window_set_cursor (box->window, gdk_cursor_new (GDK_CROSS));
}
Example #6
0
/**
 * facq_baf_view_plot_draw_page:
 * @plot: A #FacqBAFViewPlot object.
 * @n_page: the number of page that we want to plot, it should be >= 1. This
 * will be used to calculate the values of the times vector.
 *
 * You must call this function to update the plot with a new graph,
 * created from the slices stored in the temporal buffer, that will
 * be moved to the final buffer.
 *
 * Calculates the time array, calculating the time of each slice,
 * erases any previous graph in the plot, copies the slices pushed
 * to the temporal buffer to the final buffer, and creates new graphs
 * for the new slices pushed in the buffer. Finally the new graphs
 * are plotted, the temporal limits and amplitude limits are set and the
 * chunk counter is reset.
 *
 */
void facq_baf_view_plot_draw_page(FacqBAFViewPlot *plot,gdouble n_page)
{
	guint i = 0;
	gfloat initial_time = 0, period = 0;
	GdkColor color;
	GtkDataboxGraph *graph = NULL;

	g_return_if_fail(FACQ_IS_BAF_VIEW_PLOT(plot));
	g_return_if_fail(n_page >= 1);

	/* set the time array in the temporal array */
	initial_time = ((n_page-1)*plot->priv->samples_per_page*plot->priv->period);
	period = (gfloat)plot->priv->period;
	for(i = 0;i < plot->priv->samples_per_page;i++){
		plot->priv->time[i] = initial_time + i*period;
	}

	/* erase any previous existing graph */
	if(plot->priv->signal){
		for(i = 0;i < plot->priv->signal->len;i++){
			if(GTK_DATABOX_IS_GRAPH(g_ptr_array_index(plot->priv->signal,i))){
				gtk_databox_graph_remove(GTK_DATABOX(plot->priv->databox),
						g_ptr_array_index(plot->priv->signal,i));
			}
		}
		g_ptr_array_free(plot->priv->signal,TRUE);
		plot->priv->signal = NULL;
	}

	/* copy the temporal buffers copy_samples and copy_time to the final buffers */
	facq_baf_view_plot_copy_buffers(plot);

	/* create the new graphs for the final buffer */
	plot->priv->signal = g_ptr_array_new_with_free_func(
                                (GDestroyNotify)facq_baf_view_plot_signal_destroy);
	for(i = 0;i < plot->priv->n_channels;i++){
		facq_gdk_color_from_index(i,&color);
#ifdef G_OS_WIN32
		/* Performance fix for windows, gdk_draw_lines() is too slow
		 * when plotting with a large number of samples so we plot
		 * points instead, note that this is a windows only problem. */
		if(plot->priv->samples_per_page <= (2000.0/plot->priv->n_channels)){
			graph = gtk_databox_lines_new(plot->priv->next_chunk,
							plot->priv->copy_time,
								plot->priv->copy_samples[i],
									&color,1);
		}
		else {
			graph = gtk_databox_points_new(plot->priv->next_chunk,
							plot->priv->copy_time,
								plot->priv->copy_samples[i],
									&color,1);
		}
#else
		graph = gtk_databox_lines_new(plot->priv->next_chunk,
							plot->priv->copy_time,
								plot->priv->copy_samples[i],
									&color,1);
#endif
		g_ptr_array_add(plot->priv->signal,(gpointer) graph);
		/* add the graphs to the box */
		gtk_databox_graph_add(GTK_DATABOX(plot->priv->databox),graph);
	}

	/* set the limits */
	gtk_databox_set_total_limits(GTK_DATABOX(plot->priv->databox),
					plot->priv->time[0],
						plot->priv->time[plot->priv->samples_per_page-1],
							plot->priv->max+0.5,plot->priv->min-0.5);

	/* plot it! */
	gtk_widget_queue_draw(plot->priv->databox);

	/* set current_chunk to 0 so we can push more samples later */
	plot->priv->next_chunk = 0;
}
Example #7
0
GtkWidget* ahrs_display(struct ahrs_data* ad) {
  GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request (window, 1280, 800);

  GtkWidget* vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox1);

  GdkColor red = {0, 65535, 0, 0};
  GdkColor light_red = {0, 65535, 31875, 31875};
  GdkColor green = {0, 0, 65535, 0};
  GdkColor light_green = {0, 31875, 65535, 31875};
  GdkColor blue = {0, 0, 0, 65535};
  GdkColor light_blue = {0, 14025, 39525, 65535};
  //  GdkColor pink = {0, 65535, 0, 65535};
  //  GdkColor black = {0, 0, 0, 0};

  GtkWidget *frame = gtk_frame_new ("rate");
  gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  gtk_box_pack_start (GTK_BOX (vbox1), frame, TRUE, TRUE, 0);

  GtkWidget* databox = gtk_databox_new();
  gfloat* ft = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_mrate_p = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_mrate_q = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_mrate_r = g_new0 (gfloat, ad->nb_samples);
  int idx;
  for (idx=0; idx<ad->nb_samples; idx++) {
    ft[idx] = ad->t[idx];
    f_mrate_p[idx] = ad->gyro_p[idx];
    f_mrate_q[idx] = ad->gyro_q[idx];
    f_mrate_r[idx] = ad->gyro_r[idx];
  }
  GtkDataboxGraph *g_mrate_p = gtk_databox_lines_new (ad->nb_samples, ft, f_mrate_p, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_mrate_p);
  GtkDataboxGraph *g_mrate_q = gtk_databox_lines_new (ad->nb_samples, ft, f_mrate_q, &green, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_mrate_q);
  GtkDataboxGraph *g_mrate_r = gtk_databox_lines_new (ad->nb_samples, ft, f_mrate_r, &blue, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_mrate_r);

  gtk_container_add (GTK_CONTAINER (frame), databox );
  gtk_databox_auto_rescale (GTK_DATABOX(databox), 0.);



  frame = gtk_frame_new ("angle");
  gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  gtk_box_pack_start (GTK_BOX (vbox1), frame, TRUE, TRUE, 0);

  databox = gtk_databox_new();
  //  databox = gtk_databox_create_box_with_scrollbars_and_rulers();
  gfloat* f_ephi = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_etheta = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_epsi = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_mphi = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_mtheta = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_mpsi = g_new0 (gfloat, ad->nb_samples);
  for (idx=0; idx<ad->nb_samples; idx++) {
    f_ephi[idx] = ad->est_phi[idx];
    f_etheta[idx] = ad->est_theta[idx];
    f_epsi[idx] = ad->est_psi[idx];
    f_mphi[idx] = ad->m_phi[idx];
    f_mtheta[idx] = ad->m_theta[idx];
    f_mpsi[idx] = ad->m_psi[idx];
  }
  GtkDataboxGraph *g_ephi = gtk_databox_lines_new (ad->nb_samples, ft, f_ephi, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_ephi);
  GtkDataboxGraph *g_etheta = gtk_databox_lines_new (ad->nb_samples, ft, f_etheta, &green, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_etheta);
  GtkDataboxGraph *g_epsi = gtk_databox_lines_new (ad->nb_samples, ft, f_epsi, &blue, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_epsi);
  GtkDataboxGraph *g_mphi = gtk_databox_lines_new (ad->nb_samples, ft, f_mphi, &light_red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_mphi);
  GtkDataboxGraph *g_mtheta = gtk_databox_lines_new (ad->nb_samples, ft, f_mtheta, &light_green, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_mtheta);
  GtkDataboxGraph *g_mpsi = gtk_databox_lines_new (ad->nb_samples, ft, f_mpsi, &light_blue, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_mpsi);

  gtk_container_add (GTK_CONTAINER (frame), databox );
  gtk_databox_auto_rescale (GTK_DATABOX(databox), 0.);



  frame = gtk_frame_new ("biase");
  gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  gtk_box_pack_start (GTK_BOX (vbox1), frame, TRUE, TRUE, 0);

  databox = gtk_databox_new();
  gfloat* f_ebias_p = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_ebias_q = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_ebias_r = g_new0 (gfloat, ad->nb_samples);
  for (idx=0; idx<ad->nb_samples; idx++) {
    f_ebias_p[idx] = ad->est_bias_p[idx];
    f_ebias_q[idx] = ad->est_bias_q[idx];
    f_ebias_r[idx] = ad->est_bias_r[idx];
  }
  GtkDataboxGraph *ge_bias_p = gtk_databox_lines_new (ad->nb_samples, ft, f_ebias_p, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), ge_bias_p);
  GtkDataboxGraph *ge_bias_q = gtk_databox_lines_new (ad->nb_samples, ft, f_ebias_q, &green, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), ge_bias_q);
  GtkDataboxGraph *ge_bias_r = gtk_databox_lines_new (ad->nb_samples, ft, f_ebias_r, &blue, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), ge_bias_r);

  gtk_container_add (GTK_CONTAINER (frame), databox );
  gtk_databox_auto_rescale (GTK_DATABOX(databox), 0.);



  frame = gtk_frame_new ("covariance");
  gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  gtk_box_pack_start (GTK_BOX (vbox1), frame, TRUE, TRUE, 0);

  databox = gtk_databox_new();
  gfloat* f_p11 = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_p22 = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_p33 = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_p44 = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_p55 = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_p66 = g_new0 (gfloat, ad->nb_samples);
  gfloat* f_p77 = g_new0 (gfloat, ad->nb_samples);
  for (idx=0; idx<ad->nb_samples; idx++) {
    f_p11[idx] = ad->P11[idx];
    f_p22[idx] = ad->P22[idx];
    f_p33[idx] = ad->P33[idx];
    f_p44[idx] = ad->P44[idx];
    f_p55[idx] = ad->P55[idx];
    f_p66[idx] = ad->P66[idx];
    f_p77[idx] = ad->P77[idx];
  }
  GtkDataboxGraph *g_p11 = gtk_databox_lines_new (ad->nb_samples, ft, f_p11, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_p11);
  GtkDataboxGraph *g_p22 = gtk_databox_lines_new (ad->nb_samples, ft, f_p22, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_p22);
  GtkDataboxGraph *g_p33 = gtk_databox_lines_new (ad->nb_samples, ft, f_p33, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_p33);
  GtkDataboxGraph *g_p44 = gtk_databox_lines_new (ad->nb_samples, ft, f_p44, &red, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_p44);
  GtkDataboxGraph *g_p55 = gtk_databox_lines_new (ad->nb_samples, ft, f_p55, &blue, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_p55);
  GtkDataboxGraph *g_p66 = gtk_databox_lines_new (ad->nb_samples, ft, f_p66, &blue, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_p66);
  GtkDataboxGraph *g_p77 = gtk_databox_lines_new (ad->nb_samples, ft, f_p77, &blue, 1);
  gtk_databox_graph_add (GTK_DATABOX(databox), g_p77);

  gtk_container_add (GTK_CONTAINER (frame), databox );
  gtk_databox_auto_rescale (GTK_DATABOX(databox), 0.);


  gtk_widget_show_all(window);
  return window;
}
static void
create_lissajous (void)
{
   GtkWidget *window = NULL;
   GtkWidget *box1;
   GtkWidget *box2;
   GtkWidget *close_button;
   GtkWidget *box;
   GtkWidget *label;
   GtkWidget *table;
   GtkWidget *separator;
   GtkDataboxGraph *graph;
   GdkRGBA color;
   gint i;

   lissajous_frequency = 0;
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_size_request (window, 500, 500);

   g_signal_connect (G_OBJECT (window), "destroy",
		     G_CALLBACK (gtk_main_quit), NULL);

   gtk_window_set_title (GTK_WINDOW (window),
			 "GtkDatabox: Lissajous Example");
   gtk_container_set_border_width (GTK_CONTAINER (window), 0);

   box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_container_add (GTK_CONTAINER (window), box1);

   label =
      gtk_label_new
      ("This example resembles an oszilloscope\nreceiving two signals, one is a sine (horizontal),\nthe other is a cosine with ever changing frequency (vertical).\nThe counter is synchron with the updates.");
   gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
   separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 0);
   lissajous_label = gtk_entry_new ();
   gtk_entry_set_text (GTK_ENTRY (lissajous_label), "0");
   gtk_box_pack_start (GTK_BOX (box1), lissajous_label, FALSE, FALSE, 0);
   separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 0);

   lissajous_idle = 0;
   lissajous_frequency = 3. * G_PI / 2.;
   lissajous_counter = 0;

   /* Create a GtkDatabox widget along with scrollbars and rulers */
   gtk_databox_create_box_with_scrollbars_and_rulers (&box, &table,
						      TRUE, TRUE, TRUE, TRUE);

   g_object_set(G_OBJECT(box), "expand", TRUE, NULL);

   gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);

   color.red = 0;
   color.green = 0;
   color.blue = 0.5;
   color.alpha = 1;

   gtk_widget_override_background_color (box, GTK_STATE_FLAG_NORMAL, &color);

   lissajousX = g_new0 (gfloat, POINTS);
   lissajousY = g_new0 (gfloat, POINTS);

   for (i = 0; i < POINTS; i++)
   {
      lissajousX[i] = 100. * sin (i * 4 * G_PI / POINTS);
      lissajousY[i] = 100. * cos (i * 4 * G_PI / POINTS);
   }
   color.red = 1;
   color.green = 1;
   color.blue = 0;
   color.alpha = 1;

   graph = gtk_databox_lines_new (POINTS, lissajousX, lissajousY, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);

   separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

   box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
   gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
   gtk_box_pack_end (GTK_BOX (box1), box2, FALSE, TRUE, 0);
   close_button = gtk_button_new_with_label ("close");

   g_signal_connect_swapped (G_OBJECT (close_button), "clicked",
			     G_CALLBACK (gtk_main_quit), G_OBJECT (box));

   gtk_box_pack_start (GTK_BOX (box2), close_button, TRUE, TRUE, 0);
   gtk_widget_set_can_default(close_button, TRUE);
   gtk_widget_grab_default (close_button);
   lissajous_idle = g_idle_add ((GSourceFunc) lissajous_idle_func, box);

   gtk_widget_show_all (window);
}