diff options
author | Xiao Pan <xyz@flylightning.xyz> | 2025-04-25 01:15:58 -0700 |
---|---|---|
committer | Xiao Pan <xyz@flylightning.xyz> | 2025-04-25 01:15:58 -0700 |
commit | 6b3369106d9fe06300bc7d2a032230a21bc2a497 (patch) | |
tree | 84b8934ce51d70d0d167fccbc8da73c21261fe53 | |
parent | cefa2377548300140e54422d9f0fb88586fb9629 (diff) |
checkbutton now can add remove plots
-rw-r--r-- | remote_plot.c | 70 |
1 files changed, 51 insertions, 19 deletions
diff --git a/remote_plot.c b/remote_plot.c index 54338aa..e0b7e16 100644 --- a/remote_plot.c +++ b/remote_plot.c @@ -178,6 +178,7 @@ typedef struct { PLFLT volt[LEN][VOLTLEN]; PLFLT temp[LEN][TEMPLEN]; GtkWidget *area; + GtkWidget *checkbutton[VOLTLEN+TEMPLEN]; }DATA; static gboolean sftp_read_sync(gpointer user_data) @@ -230,10 +231,18 @@ static gboolean sftp_read_sync(gpointer user_data) //data->buffer[LEN-1]=atof(buffer); // would be better if check strtok return NULL or not strtok(buffer,","); + //printf("start print receive\n"); for(int i=0;i<VOLTLEN;i++) + { data->volt[LEN-1][i]=atof(strtok(NULL,",")); + //printf("volt[%d][%d]: %g\n",LEN-1,i,data->volt[LEN-1][i]); + } for(int i=0;i<TEMPLEN;i++) + { data->temp[LEN-1][i]=atof(strtok(NULL,",")); + //printf("temp[%d][%d]: %g\n",LEN-1,i,data->temp[LEN-1][i]); + } + //printf("end print receive\n"); } rc = sftp_close(file); @@ -355,15 +364,18 @@ static void draw_function (GtkDrawingArea *area, { //printf("draw begin\n"); DATA *data=user_data; - - PLFLT y[LEN]; PLFLT xmin = data->t[0], xmax = data->t[LEN-1], ymin = 0, ymax = 6.; + int plot_counts=0; + gboolean active_checkbutton[VOLTLEN+TEMPLEN]; - for(int i=0;i<LEN;i++) - y[i]=data->volt[i][0]; + for(int i=0;i<(VOLTLEN+TEMPLEN);i++) + if((active_checkbutton[i]=gtk_check_button_get_active(GTK_CHECK_BUTTON(data->checkbutton[i])))) + plot_counts++; plsdev( "extcairo" ); + //plsetopt("geometry", "600x400"); + // change to white background and black foreground, and gray color palette // http://plplot.org/docbook-manual/plplot-html-5.15.0/color.html // seems should be put before plinit; or need pladv(), plvpor(), plwind() for a new picture? @@ -374,20 +386,39 @@ static void draw_function (GtkDrawingArea *area, plspal1("cmap1_gray.pal", 1); // Initialize plplot - plinit(); + plstar(1,plot_counts); pl_cmd( PLESC_DEVINIT, cr ); - // Create a labelled box to hold the plot. - plenv(xmin, xmax, ymin, ymax, 0, 0); - pllab("Time (s)","Voltage (V)","Time vs. Voltage"); - // Plot the data that was prepared above. - // plstring for scatter - // #(NNN) is Hershey font code, more see example 5, 6, 21 - // #(727) is centred X symbol; other maybe useful codes: #(728) - // hershey font code see http://plplot.org/examples.php?demo=07 ? - plstring(LEN, data->t, y, "#(727)"); - // pline for line - plline(LEN, data->t, y); + for(int i=0;i<(VOLTLEN+TEMPLEN);i++) + { + if(active_checkbutton[i]) + { + PLFLT y[LEN]; + + for(int j=0;j<LEN;j++) + { + if(i<VOLTLEN) + y[j]=data->volt[j][i]; + else + y[j]=data->temp[j][i-VOLTLEN]; + } + + // Create a labelled box to hold the plot. + plenv(xmin, xmax, ymin, ymax, 0, 0); + if(i<VOLTLEN) + pllab("Time (s)","Voltage (V)",checkbutton_names[i]); + else + pllab("Time (s)","Temperature (C)",checkbutton_names[i]); + // Plot the data that was prepared above. + // plstring for scatter + // #(NNN) is Hershey font code, more see example 5, 6, 21 + // #(727) is centred X symbol; other maybe useful codes: #(728) + // hershey font code see http://plplot.org/examples.php?demo=07 ? + plstring(LEN, data->t, y, "#(727)"); + // pline for line + plline(LEN, data->t, y); + } + } // Close PLplot library plend(); @@ -414,11 +445,12 @@ static void activate (GtkApplication *app, gpointer user_data) data->area = gtk_drawing_area_new (); GtkWidget *button; GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL,1); - GtkWidget *checkbutton[VOLTLEN+TEMPLEN]; GtkWidget *scrolled_window; for(int i=0;i<(VOLTLEN+TEMPLEN);i++) - checkbutton[i]=gtk_check_button_new_with_label(checkbutton_names[i]); + data->checkbutton[i]=gtk_check_button_new_with_label(checkbutton_names[i]); + gtk_check_button_set_active(GTK_CHECK_BUTTON(data->checkbutton[0]),TRUE); + gtk_check_button_set_active(GTK_CHECK_BUTTON(data->checkbutton[VOLTLEN]),TRUE); window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "remote_plot"); @@ -443,7 +475,7 @@ static void activate (GtkApplication *app, gpointer user_data) gtk_box_append(GTK_BOX(box), button); gtk_box_append(GTK_BOX(box), data->area); for(int i=0;i<(VOLTLEN+TEMPLEN);i++) - gtk_box_append(GTK_BOX(box), checkbutton[i]); + gtk_box_append(GTK_BOX(box), data->checkbutton[i]); gtk_window_set_child (GTK_WINDOW (window), scrolled_window); gtk_window_present (GTK_WINDOW (window)); |