/* ************************************************************** */ /* * Module VTCOILUI * This module contains functions for the coil integrated voltage * system user interface. * * Zachary Wolf * 9/18/98 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include "vtcoiluir.h" #include "vtcoilui.h" #include "vtcoil.h" /* ************************************************************** */ /* PRIVATE PARAMETERS */ static struct vtcoil_param_struct vtcoil_param; /* ************************************************************** */ /* PRIVATE VARIABLES */ static int vtcoil_panel; static int vtcoilop_panel; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONS */ void vtcoilui_error(char* msg); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * vtcoilui_init * This function initializes the user interface for the VTcoil system. * * Input: * top_pos, vertical position of top left panel corner in screen coordinates * left_pos, horizontal position of top left panel corner in screen coordinates * vtcoil_par, vtcoil system parameters * * Zachary Wolf * 9/18/98 */ void vtcoilui_init(int top_pos, int left_pos, struct vtcoil_param_struct vtcoil_par) { /* Save parameters for future use */ vtcoil_param = vtcoil_par; /* Make sure the user interface panel is desired */ if (vtcoil_param.show_ui != VTCOIL_TRUE) return; /* Open the VTcoil panel */ vtcoil_panel = LoadPanel(0, "vtcoiluir.uir", VTCOILPAN); if (vtcoil_panel < 0) { vtcoilui_error("Could not open user interface panel"); return; } /* Set the panel position */ SetPanelPos(vtcoil_panel, top_pos, left_pos); /* Display the panel */ DisplayPanel(vtcoil_panel); /* Done */ return; } /* ************************************************************** */ /* * vtcoilopui_init * This function initializes the user interface for the VTcoil system. * * Input: * top_pos, vertical position of top left panel corner in screen coordinates * left_pos, horizontal position of top left panel corner in screen coordinates * * Zachary Wolf * 9/18/98 */ void vtcoilopui_init(int top_pos, int left_pos) { /* Make sure the user interface panel is desired */ if (vtcoil_param.show_ui != VTCOIL_TRUE) return; /* Open the VTcoilop panel */ vtcoilop_panel = LoadPanel(0, "vtcoiluir.uir", VTCOILOP); if (vtcoil_panel < 0) { vtcoilui_error("Could not open user interface panel"); return; } /* Set the panel position */ SetPanelPos(vtcoilop_panel, top_pos, left_pos); /* Display the panel when the user interface runs */ DisplayPanel(vtcoilop_panel); /* Done */ return; } /* ************************************************************** */ void vtcoilui_update(int num_samp, double vt[], double vtfft_re[], double vtfft_im[]) { /* Declare variables */ double* vt_angle; double* vt_freq; int num_rev; int i; /* Check the user interface */ if (vtcoil_param.show_ui != VTCOIL_TRUE) return; /* Remove previous VT sample plot */ DeleteGraphPlot(vtcoil_panel, VTCOILPAN_GRAPH_VT_SAMP, -1, VAL_IMMEDIATE_DRAW); /* Fill array of angles (rev) for VT sample X axis */ vt_angle = malloc((num_samp + 1) * sizeof(double)); for (i = 0; i <= num_samp; i++) vt_angle[i] = (double) i / vtcoil_param.num_samp_per_rev; /* Plot the VT samples */ PlotXY(vtcoil_panel, VTCOILPAN_GRAPH_VT_SAMP, vt_angle, vt, num_samp + 1, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_SOLID_CIRCLE, VAL_SOLID, 1, VAL_RED); /* Free internal storage */ free(vt_angle); /* Fill array of frequencies for VT FFT X axis */ num_rev = num_samp / vtcoil_param.num_samp_per_rev; vt_freq = malloc(num_samp * sizeof(double)); for (i = 0; i < num_samp; i++) vt_freq[i] = (double) i / (double) num_rev; /* Remove previous VTFFT sample plot */ DeleteGraphPlot(vtcoil_panel, VTCOILPAN_GRAPH_VT_FFT, -1, VAL_IMMEDIATE_DRAW); /* Plot the VT FFT data */ PlotXY(vtcoil_panel, VTCOILPAN_GRAPH_VT_FFT, vt_freq, vtfft_re, num_samp, VAL_DOUBLE, VAL_DOUBLE, VAL_SCATTER, VAL_SOLID_SQUARE, VAL_SOLID, 1, VAL_RED); PlotXY(vtcoil_panel, VTCOILPAN_GRAPH_VT_FFT, vt_freq, vtfft_im, num_samp, VAL_DOUBLE, VAL_DOUBLE, VAL_SCATTER, VAL_SOLID_SQUARE, VAL_SOLID, 1, VAL_BLUE); /* Free internal storage */ free(vt_freq); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * vtcoilui_error * This function handles error messages for the VTcoil user interface. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 9/18/98 */ void vtcoilui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nVTCOILUI ERROR: %s\n", message); Beep(); Delay(.5); Beep(); /* Terminate the program if the operator desires */ printf("Press ENTER to continue.\nPress any key then ENTER to terminate program.\n"); fgets(buf, 80, stdin); if (buf[0] == '\n') return; else exit(0); } /* ************************************************************** */ /* PRIVATE USER INTERFACE FUNCTIONS */ /* ************************************************************** */ int CVICALLBACK vtcoilui_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: vtcoil_exit(); QuitUserInterface(0); break; } return 0; } /* ************************************************************** */ int CVICALLBACK vtcoilui_locate_index(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: vtcoil_locate_index(); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK vtcoilui_route_signal(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { char integ_chan_str[80]; char integ_chan; int mux_chan; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, VTCOILOP_NUM_MUX_CHAN, &mux_chan); GetCtrlVal(panel, VTCOILOP_TXT_INTEGRATOR_CHAN, integ_chan_str); integ_chan = integ_chan_str[0]; vtcoil_route_signal(mux_chan, integ_chan); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK vtcoilui_auto_gain(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: vtcoil_auto_gain(); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK vtcoilui_get_vt(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { char rot_dir_str[10]; char rot_dir; int num_rev; int num_har = 32; double* vthar_re; double* vthar_im; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, VTCOILOP_TXT_ROT_DIR, rot_dir_str); rot_dir = rot_dir_str[0]; GetCtrlVal(panel, VTCOILOP_NUM_NUM_REV, &num_rev); vthar_re = malloc((num_har + 1) * sizeof(double)); vthar_im = malloc((num_har + 1) * sizeof(double)); vtcoil_get_vthar(rot_dir, num_rev, num_har, vthar_re, vthar_im); /* Does UI update */ free(vthar_re); free(vthar_im); break; case EVENT_RIGHT_CLICK: break; } return 0; }