diff options
-rw-r--r-- | data/displaywindow.ui | 3 | ||||
-rw-r--r-- | src/control.c | 1 | ||||
-rw-r--r-- | src/dirax.c | 83 | ||||
-rw-r--r-- | src/dirax.h | 1 | ||||
-rw-r--r-- | src/displaywindow.c | 28 | ||||
-rw-r--r-- | src/displaywindow.h | 1 |
6 files changed, 101 insertions, 16 deletions
diff --git a/data/displaywindow.ui b/data/displaywindow.ui index e770d51..e6e8264 100644 --- a/data/displaywindow.ui +++ b/data/displaywindow.ui @@ -1,5 +1,5 @@ <ui> - <menubar name="displaywindowwindow"> + <menubar name="displaywindow"> <menu name="file" action="FileAction"> <menuitem name="close" action="CloseAction" /> @@ -14,6 +14,7 @@ <menu name="tools" action="ToolsAction"> <menuitem name="dirax" action="DirAxAction" /> + <menuitem name="diraxstop" action="StopDirAxAction" /> </menu> <menu name="help" action="HelpAction"> diff --git a/src/control.c b/src/control.c index 032700d..80cf7ce 100644 --- a/src/control.c +++ b/src/control.c @@ -54,6 +54,7 @@ ControlContext *control_ctx_new() { ctx->y_centre = 0; ctx->have_centres = 0; ctx->cell = NULL; + ctx->dirax = NULL; return ctx; diff --git a/src/dirax.c b/src/dirax.c index 4834ba3..12b68fe 100644 --- a/src/dirax.c +++ b/src/dirax.c @@ -106,59 +106,106 @@ static void dirax_sendline(const char *line, ControlContext *ctx) { int i; write(ctx->dirax_pty, line, strlen(line)); - + copy = strdup(line); for ( i=0; i<strlen(copy); i++ ) { if ( copy[i] == '\r' ) copy[i]='\0'; if ( copy[i] == '\n' ) copy[i]='\0'; } - printf("sent '%s'", copy); /* No newline here */ + printf("DX: Sent '%s'\n", copy); /* No newline here */ free(copy); } +/* Send a "user" command to DirAx, failing if DirAx is not idle */ +static void dirax_sendline_if_idle(const char *line, ControlContext *ctx) { + + if ( ctx->dirax_step != 0 ) { + printf("DX: DirAx not idle\n"); + return; + } + + dirax_sendline(line, ctx); + +} static void dirax_send_next(ControlContext *ctx) { switch ( ctx->dirax_step ) { - case 0 : { + case 1 : { dirax_sendline("read dtr.drx\n", ctx); ctx->dirax_step++; break; } - case 1 : { - dirax_sendline("dmax 50\n", ctx); + case 2 : { + dirax_sendline("dmax 10\n", ctx); ctx->dirax_step++; break; } - case 2 : { - dirax_sendline("indexfit 2\n", ctx); + case 3 : { + dirax_sendline("indexfit 6\n", ctx); ctx->dirax_step++; break; } - case 3 : { + case 4 : { dirax_sendline("levelfit 300\n", ctx); ctx->dirax_step++; break; } - case 4 : { + case 5 : { dirax_sendline("go\n", ctx); ctx->dirax_step++; break; } - case 5 : { + case 6 : { + dirax_sendline("cell\n", ctx); + ctx->dirax_step++; + break; + } + + case 7 : { + dirax_sendline("go\n", ctx); + ctx->dirax_step++; + break; + } + + case 8 : { + dirax_sendline("cell\n", ctx); + ctx->dirax_step++; + break; + } + + case 9 : { + dirax_sendline("go\n", ctx); + ctx->dirax_step++; + break; + } + + case 10 : { + dirax_sendline("cell\n", ctx); + ctx->dirax_step++; + break; + } + + case 11 : { + dirax_sendline("go\n", ctx); + ctx->dirax_step++; + break; + } + + case 12 : { dirax_sendline("cell\n", ctx); ctx->dirax_step++; break; } default: { - printf("idle"); + ctx->dirax_step = 0; } } @@ -179,6 +226,7 @@ static gboolean dirax_readable(GIOChannel *dirax, GIOCondition condition, Contro waitpid(ctx->dirax_pid, NULL, 0); g_io_channel_shutdown(ctx->dirax, FALSE, NULL); ctx->dirax = NULL; + displaywindow_update_dirax(ctx, ctx->dw); return FALSE; } else { @@ -250,9 +298,8 @@ static gboolean dirax_readable(GIOChannel *dirax, GIOCondition condition, Contro memmove(ctx->dirax_rbuffer+i, ctx->dirax_rbuffer+i+7, 7); ctx->dirax_rbufpos -= 7; - printf("DX: Got prompt: "); + printf("DX: Prompt\n"); dirax_send_next(ctx); - printf("\n"); break; @@ -287,6 +334,12 @@ static gboolean dirax_readable(GIOChannel *dirax, GIOCondition condition, Contro } +void dirax_stop(ControlContext *ctx) { + + dirax_sendline_if_idle("end\n", ctx); + +} + void dirax_invoke(ControlContext *ctx) { FILE *fh; @@ -341,11 +394,13 @@ void dirax_invoke(ControlContext *ctx) { opts = fcntl(ctx->dirax_pty, F_GETFL); fcntl(ctx->dirax_pty, F_SETFL, opts | O_NONBLOCK); - ctx->dirax_step = 0; + ctx->dirax_step = 1; /* This starts the "initialisation" procedure */ ctx->dirax_read_cell = 0; ctx->dirax = g_io_channel_unix_new(ctx->dirax_pty); g_io_add_watch(ctx->dirax, G_IO_IN | G_IO_HUP, (GIOFunc)dirax_readable, ctx); + displaywindow_update_dirax(ctx, ctx->dw); + return; } diff --git a/src/dirax.h b/src/dirax.h index b06c6c9..c463561 100644 --- a/src/dirax.h +++ b/src/dirax.h @@ -21,6 +21,7 @@ #include "reflections.h" extern void dirax_invoke(ControlContext *ctx); +extern void dirax_stop(ControlContext *ctx); extern ReflectionList *dirax_load(const char *filename); extern int dirax_is_drxfile(const char *filename); diff --git a/src/displaywindow.c b/src/displaywindow.c index 1d3eb20..8899e0b 100644 --- a/src/displaywindow.c +++ b/src/displaywindow.c @@ -79,6 +79,10 @@ static void displaywindow_dirax(GtkWidget *widget, DisplayWindow *dw) { dirax_invoke(dw->ctx); } +static void displaywindow_dirax_stop(GtkWidget *widget, DisplayWindow *dw) { + dirax_stop(dw->ctx); +} + static void displaywindow_gl_set_ortho(DisplayWindow *dw, GLfloat w, GLfloat h) { glMatrixMode(GL_PROJECTION); @@ -173,7 +177,8 @@ static void displaywindow_addmenubar(DisplayWindow *dw) { { "ViewAction", NULL, "_View", NULL, NULL, NULL }, { "ToolsAction", NULL, "_Tools", NULL, NULL, NULL }, - { "DirAxAction", GTK_STOCK_EXECUTE, "Invoke _DirAx", "<Ctrl>D", NULL, G_CALLBACK(displaywindow_dirax) }, + { "DirAxAction", GTK_STOCK_EXECUTE, "Start _DirAx", "<Ctrl>D", NULL, G_CALLBACK(displaywindow_dirax) }, + { "StopDirAxAction", GTK_STOCK_CLOSE, "Stop DirAx", "<Ctrl>D", NULL, G_CALLBACK(displaywindow_dirax_stop) }, { "HelpAction", NULL, "_Help", NULL, NULL, NULL }, { "AboutAction", GTK_STOCK_ABOUT, "_About DTR...", NULL, NULL, G_CALLBACK(displaywindow_about) }, @@ -912,6 +917,8 @@ DisplayWindow *displaywindow_open(ControlContext *ctx) { g_signal_connect(GTK_OBJECT(dw->drawing_area), "button_press_event", G_CALLBACK(displaywindow_gl_button_press), dw); g_signal_connect(GTK_OBJECT(dw->drawing_area), "motion_notify_event", G_CALLBACK(displaywindow_gl_motion_notify), dw); + displaywindow_update_dirax(ctx, dw); + gtk_widget_show_all(dw->window); return dw; @@ -924,3 +931,22 @@ void displaywindow_update(DisplayWindow *dw) { gdk_window_invalidate_rect(dw->drawing_area->window, &dw->drawing_area->allocation, FALSE); } +/* Update the disabling of the menu for DirAx functions */ +void displaywindow_update_dirax(ControlContext *ctx, DisplayWindow *dw) { + + GtkWidget *start; + GtkWidget *stop; + + start = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/tools/dirax"); + stop = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/tools/diraxstop"); + + if ( ctx->dirax ) { + gtk_widget_set_sensitive(GTK_WIDGET(start), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(stop), TRUE); + } else { + gtk_widget_set_sensitive(GTK_WIDGET(start), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(stop), FALSE); + } + +} + diff --git a/src/displaywindow.h b/src/displaywindow.h index 8c4e388..6b4fb01 100644 --- a/src/displaywindow.h +++ b/src/displaywindow.h @@ -61,6 +61,7 @@ typedef struct dw_struct { extern DisplayWindow *displaywindow_open(ControlContext *ctx); extern void displaywindow_update(DisplayWindow *dw); +extern void displaywindow_update_dirax(ControlContext *ctx, DisplayWindow *dw); #endif /* DISPLAYWINDOW_H */ |