aboutsummaryrefslogtreecommitdiff
path: root/remote_plot.c
diff options
context:
space:
mode:
authorXiao Pan <xyz@flylightning.xyz>2025-05-07 01:35:53 -0700
committerXiao Pan <xyz@flylightning.xyz>2025-05-07 01:35:53 -0700
commit29d054c2b4c680a586c6ab9d12e2d59a106a4bc4 (patch)
tree53bbda21c30cc78a182a30aad358a7b3f9521112 /remote_plot.c
parent8643c8ffc59dd8a9995ccf9b0461f3f1e118bcb6 (diff)
add unix time and last 50 seconds toggle
Diffstat (limited to 'remote_plot.c')
-rw-r--r--remote_plot.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/remote_plot.c b/remote_plot.c
index 2ece6f2..f7031b3 100644
--- a/remote_plot.c
+++ b/remote_plot.c
@@ -252,6 +252,8 @@ typedef struct {
GtkWidget *live_toggle;
GtkWidget *from_entry;
GtkWidget *to_entry;
+ GtkWidget *unix_time_toggle;
+ GtkWidget *last_seconds_toggle;
// .csv file already read offset
uint32_t offset;
uint32_t from_time;
@@ -323,9 +325,11 @@ static gboolean read_data(gpointer user_data)
// This is to represent a loop over time
// Let's try a random walk process
+ //printf("before sftp_open\n");
// No need `sftp_expand_path(data->sftp,"~/.local/share/mycan.csv")` because the current dir seems is home dir.
// Also old libssh seems does not have sftp_expand_path
file = sftp_open(data->sftp, ".local/share/mycan.csv", access_type, 0);
+ //printf("after sftp_open\n");
if (file == NULL) {
fprintf(stderr, "Can't open file for reading: %s\n",
ssh_get_error(data->session));
@@ -333,11 +337,15 @@ static gboolean read_data(gpointer user_data)
return G_SOURCE_REMOVE;
}
+ //printf("before sftp_seed\n");
if(data->offset != 0)
sftp_seek(file,data->offset);
+ //printf("after sftp_seed\n");
for(;;)
{
+ //printf("before sftp_read\n");
nbytes = sftp_read(file, buffer, sizeof(buffer));
+ //printf("after sftp_read\n");
//printf("nbytes: %d\n",nbytes);
//printf("%d\n",MAX_XFER_BUF_SIZE);
if (nbytes == 0) {
@@ -554,11 +562,14 @@ static void draw_function (GtkDrawingArea *area,
else
xmax=data->to_time;
- if(data->from_time_entered)
+ if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->last_seconds_toggle)))
+ xmin=data->cans.end->item.t-50;
+ else if(data->from_time_entered)
xmin=data->from_time;
else
xmin=data->cans.head->item.t;
+
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++;
@@ -592,6 +603,11 @@ static void draw_function (GtkDrawingArea *area,
// 10 char unix time: 1745925459
// set numbers of digits to display x axis labels
plsxax(10,0);
+ // smaller character size, so x axis characters won't stick together
+ //plschr(0.,.5);
+ //pltimefmt("%m-%d %H:%M:%S");
+ // show seconds will make x axis characters stick together
+ pltimefmt("%m-%d %H:%M");
for(int i=0;i<(VOLTLEN+TEMPLEN);i++)
{
@@ -613,7 +629,11 @@ static void draw_function (GtkDrawingArea *area,
}
// Create a labelled box to hold the plot.
- plenv(xmin, xmax, ymin, ymax, 0, 0);
+ if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->unix_time_toggle)))
+ plenv(xmin, xmax, ymin, ymax, 0, 0);
+ else
+ // use date / time labels
+ plenv(xmin, xmax, ymin, ymax, 0, 40);
if(i<VOLTLEN)
pllab("Time (s)","Voltage (V)",checkbutton_names[i]);
else
@@ -660,6 +680,7 @@ static void set_from_time (GtkWidget *widget, gpointer user_data)
if(!(data->from_time_entered))
data->from_time_entered=true;
data->from_time=strtoul(gtk_editable_get_text(GTK_EDITABLE(data->from_entry)),NULL,10);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->last_seconds_toggle),FALSE);
gtk_widget_queue_draw(data->area);
}
@@ -691,10 +712,11 @@ static void activate (GtkApplication *app, gpointer user_data)
GtkWidget *expander_temp = gtk_expander_new("Choose cell temperatures to plot");
GtkWidget *from_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0);
GtkWidget *to_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0);
- GtkWidget *from_button = gtk_button_new_with_label ("Enter from time");
- GtkWidget *to_button = gtk_button_new_with_label ("Enter to time");
+ GtkWidget *from_button = gtk_button_new_with_label ("Enter from unix time");
+ GtkWidget *to_button = gtk_button_new_with_label ("Enter to unix time");
GtkWidget *flowbox_top = gtk_flow_box_new();
GtkWidget *flowbox_expander = gtk_flow_box_new();
+ //GtkWidget *expander_more = gtk_expander_new("More");
data->from_entry = gtk_entry_new();
data->to_entry = gtk_entry_new();
@@ -716,6 +738,14 @@ static void activate (GtkApplication *app, gpointer user_data)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->live_toggle),TRUE);
g_signal_connect (data->live_toggle, "toggled", G_CALLBACK (update_drawing_area), user_data);
+ data->unix_time_toggle = gtk_toggle_button_new_with_label("Unix time");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->unix_time_toggle),FALSE);
+ g_signal_connect (data->unix_time_toggle, "toggled", G_CALLBACK (update_drawing_area), user_data);
+
+ data->last_seconds_toggle = gtk_toggle_button_new_with_label("Last 50 seconds");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->last_seconds_toggle),TRUE);
+ g_signal_connect (data->last_seconds_toggle, "toggled", G_CALLBACK (update_drawing_area), user_data);
+
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);
@@ -761,6 +791,8 @@ static void activate (GtkApplication *app, gpointer user_data)
gtk_flow_box_append(GTK_FLOW_BOX(flowbox_top), data->temp_label);
gtk_flow_box_append(GTK_FLOW_BOX(flowbox_top), from_box);
gtk_flow_box_append(GTK_FLOW_BOX(flowbox_top), to_box);
+ gtk_flow_box_append(GTK_FLOW_BOX(flowbox_top), data->unix_time_toggle);
+ gtk_flow_box_append(GTK_FLOW_BOX(flowbox_top), data->last_seconds_toggle);
gtk_flow_box_append(GTK_FLOW_BOX(flowbox_expander), expander_volt);
gtk_flow_box_append(GTK_FLOW_BOX(flowbox_expander), expander_temp);