diff options
author | Xiao Pan <xyz@flylightning.xyz> | 2025-04-25 06:03:34 -0700 |
---|---|---|
committer | Xiao Pan <xyz@flylightning.xyz> | 2025-04-25 06:03:34 -0700 |
commit | e9ed2416b0c3adb68b62904628b38b9b9975f41f (patch) | |
tree | 2259036d23f22a34da6c53ab90af003687edda78 /remote_plot.c | |
parent | 6b3369106d9fe06300bc7d2a032230a21bc2a497 (diff) |
Add average volt and temp labels
Diffstat (limited to 'remote_plot.c')
-rw-r--r-- | remote_plot.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/remote_plot.c b/remote_plot.c index e0b7e16..2cdd292 100644 --- a/remote_plot.c +++ b/remote_plot.c @@ -29,12 +29,13 @@ #include <gtk/gtk.h> -// voltage max format 8 bytes ,xxx.xxx -// temp max format 5 bytes ,xx.x +// max wire number is 65535, *0.001=65.535, *0.1=6553.5 +// voltage max format 7 bytes ,65.535 +// temp max format 7 bytes ,6553.5 // timestamp max 8 bytes 86400000 -// 96 voltage, 32 temp -// 96*8+32*5+8=936 bytes -#define MAX_XFER_BUF_SIZE 936 +// 1 timestamp, 96 voltage, 32 temp, 1 \n, 1 \0 +// 96*7+32*7+8+1+1=906 bytes +#define MAX_XFER_BUF_SIZE 906 #define LEN 10 #define VOLTLEN 96 @@ -179,6 +180,8 @@ typedef struct { PLFLT temp[LEN][TEMPLEN]; GtkWidget *area; GtkWidget *checkbutton[VOLTLEN+TEMPLEN]; + GtkWidget *volt_label; + GtkWidget *temp_label; }DATA; static gboolean sftp_read_sync(gpointer user_data) @@ -257,6 +260,25 @@ static gboolean sftp_read_sync(gpointer user_data) data->t[i]++; //printf("sftp_read_sync end\n"); + { + double sum,avg; + // max 29 char + 1 \0: Average temperature: 6553.5 C + char str[30]; + sum=avg=0; + + for(int i=0;i<VOLTLEN;i++) + sum+=data->volt[LEN-1][i]; + avg=sum/VOLTLEN; + sprintf(str,"Average voltage: %.3f V",avg); + gtk_label_set_text(GTK_LABEL(data->volt_label),str); + sum=0; + for(int i=0;i<TEMPLEN;i++) + sum+=data->temp[LEN-1][i]; + avg=sum/TEMPLEN; + sprintf(str,"Average temperature: %.1f C",avg); + gtk_label_set_text(GTK_LABEL(data->temp_label),str); + } + gtk_widget_queue_draw(data->area); //return SSH_OK; @@ -447,6 +469,9 @@ static void activate (GtkApplication *app, gpointer user_data) GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL,1); GtkWidget *scrolled_window; + data->volt_label=gtk_label_new("Average voltage:"); + data->temp_label=gtk_label_new("Average temperature:"); + for(int i=0;i<(VOLTLEN+TEMPLEN);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); @@ -473,6 +498,8 @@ static void activate (GtkApplication *app, gpointer user_data) gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), box); gtk_box_append(GTK_BOX(box), button); + gtk_box_append(GTK_BOX(box), data->volt_label); + gtk_box_append(GTK_BOX(box), data->temp_label); gtk_box_append(GTK_BOX(box), data->area); for(int i=0;i<(VOLTLEN+TEMPLEN);i++) gtk_box_append(GTK_BOX(box), data->checkbutton[i]); |