Skip to content

Commit 402a96d

Browse files
author
Luca Toniolo
committed
halscope open logs
1 parent 13755b9 commit 402a96d

4 files changed

Lines changed: 546 additions & 2 deletions

File tree

src/hal/utils/scope.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,33 @@ void start_capture(void)
340340
/* already running! */
341341
return;
342342
}
343+
344+
/* Check if data is from log file */
345+
if (ctrl_usr->data_from_log_file) {
346+
GtkWidget *dialog = gtk_message_dialog_new(
347+
GTK_WINDOW(ctrl_usr->main_win),
348+
GTK_DIALOG_MODAL,
349+
GTK_MESSAGE_WARNING,
350+
GTK_BUTTONS_OK_CANCEL,
351+
_("Overwrite loaded log file data?"));
352+
353+
gtk_message_dialog_format_secondary_text(
354+
GTK_MESSAGE_DIALOG(dialog),
355+
_("Starting acquisition will clear the data loaded from the CSV file. Continue?"));
356+
357+
int response = gtk_dialog_run(GTK_DIALOG(dialog));
358+
gtk_widget_destroy(dialog);
359+
360+
if (response != GTK_RESPONSE_OK) {
361+
/* User cancelled, switch back to STOP mode */
362+
set_run_mode(STOP);
363+
return;
364+
}
365+
366+
/* Clear the flag */
367+
ctrl_usr->data_from_log_file = 0;
368+
}
369+
343370
for (n = 0; n < 16; n++) {
344371
/* point to user space channel data */
345372
chan = &(ctrl_usr->chan[n]);
@@ -498,12 +525,41 @@ static void init_usr_control_struct(void *shmem)
498525
/* set all 16 channels to "no source assigned" */
499526
for (n = 0; n < 16; n++) {
500527
ctrl_usr->chan[n].data_source_type = -1;
528+
ctrl_usr->chan[n].is_phantom = 0;
501529
}
530+
ctrl_usr->data_from_log_file = 0;
502531
/* done */
503532
}
504533

505534
static void menuitem_response(gchar *string) {
506-
printf("%s\n", string);
535+
if (strcmp(string, "file/open datafile") == 0) {
536+
open_log_cb(GTK_WINDOW(ctrl_usr->main_win));
537+
} else {
538+
printf("%s\n", string);
539+
}
540+
}
541+
542+
void open_log_cb(GtkWindow *parent)
543+
{
544+
GtkWidget *filew;
545+
GtkFileChooser *chooser;
546+
547+
filew = gtk_file_chooser_dialog_new(_("Open Log File:"),
548+
parent,
549+
GTK_FILE_CHOOSER_ACTION_OPEN,
550+
_("_Cancel"), GTK_RESPONSE_CANCEL,
551+
_("_Open"), GTK_RESPONSE_ACCEPT,
552+
NULL);
553+
554+
chooser = GTK_FILE_CHOOSER(filew);
555+
set_file_filter(chooser, "Text CSV (.csv)", "*.csv");
556+
557+
if (gtk_dialog_run(GTK_DIALOG(filew)) == GTK_RESPONSE_ACCEPT) {
558+
char *filename = gtk_file_chooser_get_filename(chooser);
559+
read_log_file(filename);
560+
g_free(filename);
561+
}
562+
gtk_widget_destroy(filew);
507563
}
508564

509565
static void about(void) {
@@ -608,7 +664,7 @@ static void define_menubar(GtkWidget *vboxtop) {
608664
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), fileopendatafile);
609665
g_signal_connect_swapped(fileopendatafile, "activate",
610666
G_CALLBACK(menuitem_response), "file/open datafile");
611-
gtk_widget_set_sensitive(GTK_WIDGET(fileopendatafile), FALSE); // XXX
667+
gtk_widget_set_sensitive(GTK_WIDGET(fileopendatafile), TRUE);
612668
gtk_widget_show(fileopendatafile);
613669

614670
filesavedatafile = gtk_menu_item_new_with_mnemonic(_("S_ave Log File"));

0 commit comments

Comments
 (0)