/* ************************************************************** */ /* * Module IAUXUI * This module contains functions for the magnet current user * interface. * * Zachary Wolf * 8/10/98 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include "iauxuir.h" #include "iauxui.h" #include "iaux.h" /* ************************************************************** */ /* PRIVATE PARAMETERS */ struct iaux_param_struct iaux_param; /* ************************************************************** */ /* PRIVATE VARIABLES */ static int iaux_panel; static int iauxop_panel; /* ************************************************************** */ /* PRIVATE FUNCTION PROTOTYPES */ void iauxui_error(char* message); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * iauxui_init * This function initializes the IAUX 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 * iaux_param_in, magnet current system parameters * * Zachary Wolf * 8/14/98 */ void iauxui_init(int top_pos, int left_pos, struct iaux_param_struct iaux_param_in) { /* Save the iaux parameters */ iaux_param = iaux_param_in; /* Make sure the user interface panel is desired */ if (iaux_param.show_ui != IAUX_TRUE) return; /* Display the magnet current panel */ iaux_panel = LoadPanel(0, "c:\\dataccvi\\lib\\system\\iaux\\iauxuir.uir", IAUX); if (iaux_panel < 0) { iauxui_error("Could not open IAUX user interface panel"); return; } /* Set the position of the panels */ SetPanelPos(iaux_panel, top_pos, left_pos); /* Display the panels */ DisplayPanel(iaux_panel); /* Set the vertical scale on the strip chart */ SetAxisScalingMode(iaux_panel, IAUX_STRIPCHART, VAL_LEFT_YAXIS, VAL_MANUAL, iaux_param.min_curr_limit, iaux_param.max_curr_limit); /* Done */ return; } /* ************************************************************** */ /* * iauxopui_init * This function initializes the IAUX 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 iauxopui_init(int top_pos, int left_pos) { /* Make sure the user interface panel is desired */ if (iaux_param.show_ui != IAUX_TRUE) return; /* Display the magnet current panel */ iauxop_panel = LoadPanel(0, "iauxuir.uir", IAUXOP); if (iauxop_panel < 0) { iauxui_error("Could not open IAUXOP user interface panel"); return; } /* Set the position of the panels */ SetPanelPos(iauxop_panel, top_pos, left_pos); /* Display the panels */ DisplayPanel(iauxop_panel); /* Done */ return; } /* ************************************************************** */ /* * iauxui_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_iaux, number of magnet currents * iaux[0 to num_iaux - 1], magnet currents * * Zachary Wolf * 2/16/00 */ void iauxui_scale_horiz_axis(int num_istand, double istand_min, double istand_max, int num_iaux, double iaux[]) { /* Declare variables */ int num_stand, num_ramp, num_points; int i; /* Make sure the user interface panel is being used */ if (iaux_param.show_ui != IAUX_TRUE) return; /* Estimate the number of points used in the strip chart */ num_stand = num_istand * 2 * fabs(istand_max - istand_min) * 3 / (iaux_param.stand_ramp_rate * IAUX_TIME_BETWEEN_CURRENT_STEPS); num_ramp = num_iaux * 30; for (i = 1; i < num_iaux; i++) num_ramp = num_ramp + (fabs(iaux[i] - iaux[i-1]) * 3 / (iaux_param.ramp_rate * IAUX_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(iaux_panel, IAUX_STRIPCHART, ATTR_POINTS_PER_SCREEN, num_points); /* Done */ return; } /* ************************************************************** */ /* * iauxui_update * This function updates the IAUX user interface so it has present * nominal current values. * * Zachary Wolf * 8/14/98 */ void iauxui_update(double nominal_current) { /* Check for the user interface */ if (iaux_param.show_ui != IAUX_TRUE) return; /* Update the interface */ PlotStripChartPoint(iaux_panel, IAUX_STRIPCHART, nominal_current); SetCtrlVal(iaux_panel, IAUX_NUMERIC, nominal_current); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * iauxui_error * This function handles errors for the IAUXUI module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 10/11/98 */ void iauxui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nIAUXUI 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 iauxui_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: iaux_get_present_nominal_current(¤t); time_min = Timer() / 60.; PlotStripChartPoint(panel, IAUX_STRIPCHART, current); SetCtrlVal(panel, IAUX_NUMERIC, current); break; } /* Done */ return 0; } /* ************************************************************** */ int CVICALLBACK iauxui_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 */ iaux_monitor(); printf("\nTime = %f\n", Timer()); iaux_ramp(100.); printf("\nTime = %f\n", Timer()); iaux_get_current(¤t); printf("Current = %f Amps\n", current); Delay(10.); iaux_monitor(); iaux_ramp(50.); Delay(10.); iaux_ramp(75.); iaux_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 iauxui_ramp(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double current; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, IAUXOP_RAMP_DESIRED_CURRENT, ¤t); iaux_ramp(current); break; } return 0; } /* ************************************************************** */ int CVICALLBACK iauxui_get_current(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double current; switch (event) { case EVENT_COMMIT: iaux_get_current(¤t); SetCtrlVal(panel, IAUXOP_NUM_MEASURED_CURRENT, current); break; } return 0; } /* ************************************************************** */ int CVICALLBACK iauxui_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, IAUXOP_NUM_STAND_MAX, &stand_max); GetCtrlVal(panel, IAUXOP_NUM_STAND_MIN, &stand_min); GetCtrlVal(panel, IAUXOP_NUM_N_CYCLES, &num_cycles); iaux_standardize(stand_max, stand_min, num_cycles); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK iauxui_quit (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: iaux_exit(); QuitUserInterface(0); break; } return 0; } /* ************************************************************** */ int CVICALLBACK iauxui_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, IAUXOP_NUM_RAMP_RATE, &ramp_rate); iaux_set_ramp_rate(ramp_rate); break; } return 0; }