/* ************************************************************** */ /* * Module QUADDETUI * This module contains functions for the quadrant detector * user interface. * * Zachary Wolf * 3/23/99 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include "quaddetuir.h" #include "quaddetui.h" #include "quaddet.h" /* ************************************************************** */ /* PRIVATE VARIABLES */ static int quaddet_panel; static int history_panel; static double ave_x = 0.; static double ave_y = 0.; static long int num_points = 0; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONSS */ void quaddetui_error(char* msg); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * quaddetui_init * This function initializes the user interface for the quadrant * detector. * * Zachary Wolf * 3/16/99 */ void quaddetui_init() { /* Open the quadrant detector panel */ quaddet_panel = LoadPanel(0, "quaddetuir.uir", QUADDETPAN); if (quaddet_panel < 0) { quaddetui_error("Could not open user interface panel"); return; } /* Open the history panel */ history_panel = LoadPanel(0, "quaddetuir.uir", HISTORYPAN); if (history_panel < 0) { quaddetui_error("Could not open user history panel"); return; } /* Display the panel when the user interface runs */ DisplayPanel(quaddet_panel); DisplayPanel(history_panel); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * quaddetui_error * This function handles error messages for the quadrant * detector user interface. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 3/16/99 */ void quaddetui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nQUADDETUI ERROR: %s\n", message); Beep(); Delay(.5); Beep(); /* Terminate the program if the operator desires */ printf("Press 0 ENTER to continue, anything else to terminate program: "); scanf("%s", buf); if (buf[0] == '0') return; else exit(0); } /* ************************************************************** */ /* PRIVATE USER INTERFACE FUNCTIONS */ /* ************************************************************** */ int CVICALLBACK quaddetui_cmd_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: quaddet_close(); QuitUserInterface(0); break; } return 0; } /* ************************************************************** */ int CVICALLBACK quaddetui_timer (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { /* Declare variables */ double v1, v2, v3, v4; double x, y; static double filt_x = 0.; static double filt_y = 0.; static int filt_num_samp = 0; int filt_required_num_samp; double sum_x, sum_y; switch (event) { case EVENT_TIMER_TICK: /* Get the quadrant voltages */ quaddet_get_v_ave(&v1, &v2, &v3, &v4); SetCtrlVal (quaddet_panel, QUADDETPAN_NUM_V1, v1); SetCtrlVal (quaddet_panel, QUADDETPAN_NUM_V2, v2); SetCtrlVal (quaddet_panel, QUADDETPAN_NUM_V3, v3); SetCtrlVal (quaddet_panel, QUADDETPAN_NUM_V4, v4); /* Calculate the beam position */ quaddet_calc_pos(v1, v2, v3, v4, &x, &y); /* Update the beam position display */ filt_x = filt_x + x; filt_y = filt_y + y; filt_num_samp++; GetCtrlVal (quaddet_panel, QUADDETPAN_NUM_FILTER, &filt_required_num_samp); if (filt_num_samp >= filt_required_num_samp) { filt_x = filt_x / filt_num_samp; filt_y = filt_y / filt_num_samp; SetCtrlVal (quaddet_panel, QUADDETPAN_NUM_MET_X, filt_x); SetCtrlVal (quaddet_panel, QUADDETPAN_NUM_MET_Y, filt_y); filt_x = 0.; filt_y = 0.; filt_num_samp = 0; } /* Update the beam history plot */ PlotPoint (history_panel, HISTORYPAN_GRAPH_HISTORY, x, y, VAL_SMALL_SOLID_SQUARE, VAL_BLACK); sum_x = ave_x * num_points + x; sum_y = ave_y * num_points + y; num_points = num_points + 1; ave_x = sum_x / num_points; ave_y = sum_y / num_points; SetCtrlVal (history_panel, HISTORYPAN_NUM_AVE_X, ave_x); SetCtrlVal (history_panel, HISTORYPAN_NUM_AVE_Y, ave_y); break; } return 0; } /* ************************************************************** */ int CVICALLBACK quaddetui_cmd_reset (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: DeleteGraphPlot (history_panel, HISTORYPAN_GRAPH_HISTORY, -1, VAL_IMMEDIATE_DRAW); num_points = 0; ave_x = 0.; ave_y = 0.; SetCtrlVal (history_panel, HISTORYPAN_NUM_AVE_X, ave_x); SetCtrlVal (history_panel, HISTORYPAN_NUM_AVE_Y, ave_y); break; } return 0; }