Browse Source

Upped support of channels to 16

Dmitry Yu Okunev 4 years ago
parent
commit
b96a1fcea6
2 changed files with 479 additions and 42 deletions
  1. 60 29
      main.c
  2. 419 13
      oscilloscope.glade

+ 60 - 29
main.c

@@ -37,7 +37,7 @@ FILE *sensor;
 FILE *dump;
 
 #define HISTORY_SIZE (1 << 20)
-#define MAX_REAL_CHANNELS 7
+#define MAX_REAL_CHANNELS 17
 #define MAX_MATH_CHANNELS 3
 #define Y_BITS 12
 
@@ -76,7 +76,7 @@ int trigger_start_y	= 675;
 int trigger_end_mode	= TG_RISE;
 int trigger_end_y	= 675;
 
-int channelsNum		= 1;
+int channelsNum		= 15;
 int mathChannelsNum	= 0;
 
 double line_colors[MAX_REAL_CHANNELS + MAX_MATH_CHANNELS][3] = {{1}};
@@ -223,13 +223,23 @@ history_fetcher(void *arg)
 void
 arrange_widgets()
 {
-	char offsetwidgetname[] = "offset_chanX";
-	char scalewidgetname[]  = "scale_chanX";
+	char offsetwidgetname[] = "offset_chanXX";
+	char scalewidgetname[]  = "scale_chanXX";
 	int chan = 0;
 	while (chan < MAX_REAL_CHANNELS + MAX_MATH_CHANNELS) {
-		offsetwidgetname[11] = chan + '0';
+		if (chan < 10) {
+			offsetwidgetname[11] = chan + '0';
+			offsetwidgetname[12] = 0;
+			scalewidgetname [10] = chan + '0';
+			scalewidgetname [11] = 0;
+		} else {
+			offsetwidgetname[11] = chan/10 + '0';
+			offsetwidgetname[12] = chan%10 + '0';
+			scalewidgetname [10] = chan/10 + '0';
+			scalewidgetname [11] = chan%10 + '0';
+		}
+
 		GtkWidget *offset = GTK_WIDGET ( gtk_builder_get_object(builder, offsetwidgetname) );
-		scalewidgetname [10] = chan + '0';
 		GtkWidget *scale  = GTK_WIDGET ( gtk_builder_get_object(builder, scalewidgetname) );
 
 		if (offset != NULL) {
@@ -292,7 +302,7 @@ cb_resize (
 		gpointer data)
 {
 	int width, height;
-	char offsetwidgetname[] = "offset_chanX";
+	char offsetwidgetname[] = "offset_chanXX";
 
 	width  = event->configure.width;
 	height = event->configure.height;
@@ -301,13 +311,21 @@ cb_resize (
 
 	int chan = 0;
 	while (chan < MAX_REAL_CHANNELS + MAX_MATH_CHANNELS) {
-		offsetwidgetname[11] = chan++ + '0';
+		if (chan >= 10) {
+			offsetwidgetname[11] = chan/10 + '0';
+			offsetwidgetname[12] = chan%10 + '0';
+		} else {
+			offsetwidgetname[11] = chan + '0';
+			offsetwidgetname[12] = 0;
+		}
+
+		chan++;
 
 		offset = GTK_WIDGET ( gtk_builder_get_object(builder, offsetwidgetname) );
 		if (offset == NULL)
 			continue;
 
-		gtk_widget_set_size_request (offset, 10, height);
+		gtk_widget_set_size_request (offset, 10, 200);
 	}
 
 	printf("%d, %d\n", width, height);
@@ -439,7 +457,8 @@ cb_draw (GtkWidget	*area,
 				x = (double)x_useroffset*width              + (double)x_scale               * (double)(p->timestamp - timestamp_start);
 				y = (double)height/2 + (double)y_useroffset[chan]*y_userscale[chan]*height - (double)y_scale * y_userscale[chan] * (double) p->value[chan];
 				cairo_line_to(cr, x, y);
-				//printf("xy: %u (%lu %e) %u (%u %e %e)\n", x, p->timestamp - timestamp_start, x_scale, y, p->value, y_scale, y_userscale);
+				if (x == 0)
+					printf("xy: %u (%lu %e) %u (%u %e %e)\n", x, p->timestamp - timestamp_start, x_scale, y, p->value, y_scale, y_userscale);
 			}
 			cairo_stroke(cr);
 
@@ -608,37 +627,49 @@ main (int    argc,
 	line_colors[6][1] = 0.5;
 	line_colors[6][2] = 0.5;
 
-	line_colors[7][0] = 1;
-	line_colors[7][1] = 1;
-	line_colors[7][2] = 1;
-
-	line_colors[8][0] = 1;
-	line_colors[8][1] = 1;
-	line_colors[9][2] = 1;
-
-	line_colors[9][0] = 1;
-	line_colors[9][1] = 1;
-	line_colors[9][2] = 1;
+	{
+		int i = 7;
+		while (i < MAX_REAL_CHANNELS + MAX_MATH_CHANNELS) {
+			line_colors[i][0] = 1;
+			line_colors[i][1] = 1;
+			line_colors[i][2] = 1;
+			i++;
+		}
+	}
 
-#if MAX_REAL_CHANNELS + MAX_MATH_CHANNELS < 10
-	#error MAX_REAL_CHANNELS + MAX_MATH_CHANNELS < 10
+#if MAX_REAL_CHANNELS + MAX_MATH_CHANNELS < 7
+	#error MAX_REAL_CHANNELS + MAX_MATH_CHANNELS < 7
 #endif
 
 	{
-		char offsetwidgetname[] = "offset_chanX";
-		char scalewidgetname[]  = "scale_chanX";
-		char enablewidgetname[] = "enable_chanX";
+		char offsetwidgetname[] = "offset_chanXX";
+		char scalewidgetname[]  = "scale_chanXX";
+		char enablewidgetname[] = "enable_chanXX";
 		int chan = 0;
 		while (chan < MAX_REAL_CHANNELS + MAX_MATH_CHANNELS) {
 
 			y_userscale[chan]  = 2;
 			y_useroffset[chan] = 0.14;
 
-			offsetwidgetname[11] = chan + '0';
+			if (chan < 10) {
+				offsetwidgetname[11] = chan + '0';
+				offsetwidgetname[12] = 0;
+				scalewidgetname [10] = chan + '0';
+				scalewidgetname [11] = 0;
+				enablewidgetname[11] = chan + '0';
+				enablewidgetname[12] = 0;
+			} else {
+				offsetwidgetname[11] = chan/10 + '0';
+				offsetwidgetname[12] = chan%10 + '0';
+				scalewidgetname [10] = chan/10 + '0';
+				scalewidgetname [11] = chan%10 + '0';
+				enablewidgetname[11] = chan/10 + '0';
+				enablewidgetname[12] = chan%10 + '0';
+
+			}
+
 			GtkRange *offset = GTK_RANGE ( gtk_builder_get_object(builder, offsetwidgetname) );
-			scalewidgetname [10] = chan + '0';
 			GtkRange *scale  = GTK_RANGE ( gtk_builder_get_object(builder, scalewidgetname) );
-			enablewidgetname[11] = chan + '0';
 			GtkToggleButton *enable = GTK_TOGGLE_BUTTON ( gtk_builder_get_object(builder, enablewidgetname) );
 
 			if (offset != NULL) {

+ 419 - 13
oscilloscope.glade

@@ -34,7 +34,7 @@
         </child>
         <child>
           <object class="GtkLayout" id="left">
-            <property name="width_request">180</property>
+            <property name="width_request">208</property>
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <child>
@@ -113,6 +113,144 @@
                 <property name="y">100</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkCheckButton" id="enable_chan6">
+                <property name="label" translatable="yes">channel 6</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="y">120</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="enable_chan7">
+                <property name="label" translatable="yes">channel 7</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="y">140</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="enable_chan8">
+                <property name="label" translatable="yes">channel 8</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="resize_mode">queue</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="x">100</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="enable_chan9">
+                <property name="label" translatable="yes">channel 9</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="x">100</property>
+                <property name="y">20</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="enable_chan10">
+                <property name="label" translatable="yes">channel 10</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="x">100</property>
+                <property name="y">40</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="enable_chan11">
+                <property name="label" translatable="yes">channel 11</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="x">100</property>
+                <property name="y">60</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="enable_chan12">
+                <property name="label" translatable="yes">channel 12</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="x">100</property>
+                <property name="y">80</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="enable_chan13">
+                <property name="label" translatable="yes">channel 13</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="x">100</property>
+                <property name="y">100</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="enable_chan14">
+                <property name="label" translatable="yes">channel 14</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="x">100</property>
+                <property name="y">120</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="enable_chan15">
+                <property name="label" translatable="yes">channel 15</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="x">100</property>
+                <property name="y">140</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="left_attach">0</property>
@@ -201,7 +339,7 @@
             <child>
               <object class="GtkScale" id="scale_chan0">
                 <property name="width_request">24</property>
-                <property name="height_request">120</property>
+                <property name="height_request">100</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="orientation">vertical</property>
@@ -209,13 +347,13 @@
                 <property name="digits">0</property>
               </object>
               <packing>
-                <property name="x">60</property>
+                <property name="x">100</property>
               </packing>
             </child>
             <child>
               <object class="GtkScale" id="scale_chan1">
                 <property name="width_request">24</property>
-                <property name="height_request">120</property>
+                <property name="height_request">100</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="orientation">vertical</property>
@@ -223,13 +361,13 @@
                 <property name="digits">0</property>
               </object>
               <packing>
-                <property name="x">80</property>
+                <property name="x">120</property>
               </packing>
             </child>
             <child>
               <object class="GtkScale" id="scale_chan2">
                 <property name="width_request">24</property>
-                <property name="height_request">120</property>
+                <property name="height_request">100</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="orientation">vertical</property>
@@ -237,13 +375,13 @@
                 <property name="digits">0</property>
               </object>
               <packing>
-                <property name="x">100</property>
+                <property name="x">140</property>
               </packing>
             </child>
             <child>
               <object class="GtkScale" id="scale_chan3">
                 <property name="width_request">24</property>
-                <property name="height_request">120</property>
+                <property name="height_request">100</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="orientation">vertical</property>
@@ -251,13 +389,13 @@
                 <property name="digits">0</property>
               </object>
               <packing>
-                <property name="x">120</property>
+                <property name="x">160</property>
               </packing>
             </child>
             <child>
               <object class="GtkScale" id="scale_chan4">
                 <property name="width_request">24</property>
-                <property name="height_request">120</property>
+                <property name="height_request">100</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="opacity">0.98999999999999999</property>
@@ -266,13 +404,14 @@
                 <property name="digits">0</property>
               </object>
               <packing>
-                <property name="x">140</property>
+                <property name="x">100</property>
+                <property name="y">100</property>
               </packing>
             </child>
             <child>
               <object class="GtkScale" id="scale_chan5">
                 <property name="width_request">24</property>
-                <property name="height_request">120</property>
+                <property name="height_request">100</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="opacity">0.9882352941176471</property>
@@ -281,7 +420,8 @@
                 <property name="digits">0</property>
               </object>
               <packing>
-                <property name="x">160</property>
+                <property name="x">120</property>
+                <property name="y">100</property>
               </packing>
             </child>
             <child>
@@ -342,6 +482,272 @@
                 <property name="x">50</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkScale" id="scale_chan6">
+                <property name="width_request">24</property>
+                <property name="height_request">100</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="opacity">0.9882352941176471</property>
+                <property name="orientation">vertical</property>
+                <property name="round_digits">0</property>
+                <property name="digits">0</property>
+              </object>
+              <packing>
+                <property name="x">140</property>
+                <property name="y">100</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="scale_chan7">
+                <property name="width_request">24</property>
+                <property name="height_request">100</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="opacity">0.9882352941176471</property>
+                <property name="orientation">vertical</property>
+                <property name="round_digits">0</property>
+                <property name="digits">0</property>
+              </object>
+              <packing>
+                <property name="x">160</property>
+                <property name="y">100</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="scale_chan8">
+                <property name="width_request">24</property>
+                <property name="height_request">100</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="orientation">vertical</property>
+                <property name="round_digits">0</property>
+                <property name="digits">0</property>
+              </object>
+              <packing>
+                <property name="x">100</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="scale_chan9">
+                <property name="width_request">24</property>
+                <property name="height_request">100</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="orientation">vertical</property>
+                <property name="round_digits">0</property>
+                <property name="digits">0</property>
+              </object>
+              <packing>
+                <property name="x">120</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="scale_chan10">
+                <property name="width_request">24</property>
+                <property name="height_request">100</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="orientation">vertical</property>
+                <property name="round_digits">0</property>
+                <property name="digits">0</property>
+              </object>
+              <packing>
+                <property name="x">140</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="scale_chan11">
+                <property name="width_request">24</property>
+                <property name="height_request">100</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="orientation">vertical</property>
+                <property name="round_digits">0</property>
+                <property name="digits">0</property>
+              </object>
+              <packing>
+                <property name="x">160</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="scale_chan12">
+                <property name="width_request">24</property>
+                <property name="height_request">100</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="orientation">vertical</property>
+                <property name="round_digits">0</property>
+                <property name="digits">0</property>
+              </object>
+              <packing>
+                <property name="x">100</property>
+                <property name="y">300</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="scale_chan13">
+                <property name="width_request">24</property>
+                <property name="height_request">100</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="orientation">vertical</property>
+                <property name="round_digits">0</property>
+                <property name="digits">0</property>
+              </object>
+              <packing>
+                <property name="x">120</property>
+                <property name="y">300</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="scale_chan14">
+                <property name="width_request">24</property>
+                <property name="height_request">100</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="orientation">vertical</property>
+                <property name="round_digits">0</property>
+                <property name="digits">0</property>
+              </object>
+              <packing>
+                <property name="x">140</property>
+                <property name="y">300</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="scale_chan15">
+                <property name="width_request">24</property>
+                <property name="height_request">100</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="orientation">vertical</property>
+                <property name="round_digits">0</property>
+                <property name="digits">0</property>
+              </object>
+              <packing>
+                <property name="x">160</property>
+                <property name="y">300</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrollbar" id="offset_chan6">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="x">60</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrollbar" id="offset_chan7">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="x">70</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrollbar" id="offset_chan8">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrollbar" id="offset_chan9">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="valign">start</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="x">10</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrollbar" id="offset_chan10">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="valign">start</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="x">20</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrollbar" id="offset_chan11">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="valign">start</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="x">30</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrollbar" id="offset_chan12">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="valign">start</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="x">40</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrollbar" id="offset_chan13">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="valign">start</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="x">50</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrollbar" id="offset_chan14">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="valign">start</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="x">60</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrollbar" id="offset_chan15">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="valign">start</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="x">70</property>
+                <property name="y">200</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="left_attach">2</property>