/* ************************************************************** */ /* * Module IMAGUI * This module contains functions for the magnet current user * interface. * * Zachary Wolf * 8/10/98 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include "imaguir.h" #include "imagui.h" #include "imag.h" /* ************************************************************** */ /* PRIVATE PARAMETERS */ struct imag_param_struct imag_param; /* ************************************************************** */ /* PRIVATE VARIABLES */ static int imag_panel; static int imagop_panel; /* ************************************************************** */ /* PRIVATE FUNCTION PROTOTYPES */ void imagui_error(char* message); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * imagui_init * This function initializes the IMAG user interface. * * 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 * imag_param_in, magnet current system parameters * * Zachary Wolf * 8/14/98 */ void imagui_init(int top_pos, int left_pos, struct imag_param_struct imag_param_in) { /* Save the imag parameters */ imag_param = imag_param_in; /* Make sure the user interface panel is desired */ if (imag_param.show_ui != IMAG_TRUE) return; /* Display the magnet current panel */ imag_panel = LoadPanel(0, "c:\\dataccvi\\lib\\system\\imag\\imaguir.uir", IMAG); if (imag_panel < 0) { imagui_error("Could not open IMAG user interface panel"); return; } /* Set the position of the panels */ SetPanelPos(imag_panel, top_pos, left_pos); /* Display the panels */ DisplayPanel(imag_panel); /* Set the vertical scale on the strip chart */ SetAxisScalingMode(imag_panel, IMAG_STRIPCHART, VAL_LEFT_YAXIS, VAL_MANUAL, imag_param.min_curr_limit, imag_param.max_curr_limit); /* Done */ return; } /* ************************************************************** */ /* * imagopui_init * This function initializes the IMAG user interface. * * 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 * 8/14/98 */ void imagopui_init(int top_pos, int left_pos) { /* Make sure the user interface panel is desired */ if (imag_param.show_ui != IMAG_TRUE) return; /* Display the magnet current panel */ imagop_panel = LoadPanel(0, "imaguir.uir", IMAGOP); if (imagop_panel < 0) { imagui_error("Could not open IMAGOP user interface panel"); return; } /* Set the position of the panels */ SetPanelPos(imagop_panel, top_pos, left_pos); /* Display the panels */ DisplayPanel(imagop_panel); /* Done */ return; } /* ************************************************************** */ /* * imagui_scale_horiz_axis * This function sets the scale on the horizontal axis of the * magnet current strip chart. * * Input: * num_istand, number of standardization cycles * istand_min, minimum standardization current * istand_max, maximum standardization current * num_imag, number of magnet currents * imag[0 to num_imag - 1], magnet currents * * Zachary Wolf * 2/16/00 */ void imagui_scale_horiz_axis(int num_istand, double istand_min, double istand_max, int num_imag, double imag[]) { /* Declare variables */ int num_stand, num_ramp, num_points; int i; /* Make sure the user interface panel is being used */ if (imag_param.show_ui != IMAG_TRUE) return; /* Estimate the number of points used in the strip chart */ num_stand = num_istand * 2 * fabs(istand_max - istand_min) * 3 / (imag_param.stand_ramp_rate * IMAG_TIME_BETWEEN_CURRENT_STEPS); num_ramp = num_imag * 30; for (i = 1; i < num_imag; i++) num_ramp = num_ramp + (fabs(imag[i] - imag[i-1]) * 3 / (imag_param.ramp_rate * IMAG_TIME_BETWEEN_CURRENT_STEPS)); num_points = num_stand + num_ramp + 200 + 1; if (num_points > 10000) num_points = 10000; /* Set the horizontal scale of the magnet current strip chart */ SetCtrlAttribute(imag_panel, IMAG_STRIPCHART, ATTR_POINTS_PER_SCREEN, num_points); /* Done */ return; } /* ************************************************************** */ /* * imagui_update * This function updates the IMAG user interface so it has present * nominal current values. * * Zachary Wolf * 8/14/98 */ void imagui_update(double nominal_current) { /* Check for the user interface */ if (imag_param.show_ui != IMAG_TRUE) return; /* Update the interface */ PlotStripChartPoint(imag_panel, IMAG_STRIPCHART, nominal_current); SetCtrlVal(imag_panel, IMAG_NUMERIC, nominal_current); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * imagui_error * This function handles errors for the IMAGUI module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 10/11/98 */ void imagui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nIMAGUI 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 imagui_update_stripchart(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { /* Declare variables */ double current; double time_min; /* Update the strip chart */ switch (event) { case EVENT_TIMER_TICK: imag_get_present_nominal_current(¤t); time_min = Timer() / 60.; PlotStripChartPoint(panel, IMAG_STRIPCHART, current); SetCtrlVal(panel, IMAG_NUMERIC, current); break; } /* Done */ return 0; } /* ************************************************************** */ int CVICALLBACK imagui_cmd_test(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { /* Declare variables */ double current; double ave_current, sig_current; switch (event) { case EVENT_COMMIT: /* Initialize the magnet current system */ imag_monitor(); printf("\nTime = %f\n", Timer()); imag_ramp(100.); printf("\nTime = %f\n", Timer()); imag_get_current(¤t); printf("Current = %f Amps\n", current); Delay(10.); imag_monitor(); imag_ramp(50.); Delay(10.); imag_ramp(75.); imag_get_ave_current(&ave_current, &sig_current); printf("AVE Current = %f Amps\n", ave_current); printf("SIG Current = %f Amps\n", sig_current); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK imagui_ramp(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double current; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, IMAGOP_RAMP_DESIRED_CURRENT, ¤t); imag_ramp(current); break; } return 0; } /* ************************************************************** */ int CVICALLBACK imagui_get_current(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double current; switch (event) { case EVENT_COMMIT: imag_get_current(¤t); SetCtrlVal(panel, IMAGOP_NUM_MEASURED_CURRENT, current); break; } return 0; } /* ************************************************************** */ int CVICALLBACK imagui_standardize(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double stand_max; double stand_min; int num_cycles; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, IMAGOP_NUM_STAND_MAX, &stand_max); GetCtrlVal(panel, IMAGOP_NUM_STAND_MIN, &stand_min); GetCtrlVal(panel, IMAGOP_NUM_N_CYCLES, &num_cycles); imag_standardize(stand_max, stand_min, num_cycles); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK imagui_quit (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: imag_exit(); QuitUserInterface(0); break; } return 0; } /* ************************************************************** */ int CVICALLBACK imagui_set_ramp_rate (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double ramp_rate; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, IMAGOP_NUM_RAMP_RATE, &ramp_rate); imag_set_ramp_rate(ramp_rate); break; } return 0; }