/* ************************************************************** */ /* * Module PSD1DUI * This module contains functions for the PSD detector * user interface. * * Zachary Wolf * 3/28/01 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include "psd1duir.h" #include "psd1dui.h" #include "psd1d.h" /* ************************************************************** */ /* PRIVATE VARIABLES */ static int psd1d_panel; static int history_panel; static double ave_x = 0.; static long int num_points = 0; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONSS */ void psd1dui_error(char* msg); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * psd1dui_init * This function initializes the user interface for the quadrant * detector. * * Zachary Wolf * 3/16/99 */ void psd1dui_init() { /* Open the quadrant detector panel */ psd1d_panel = LoadPanel(0, "psd1duir.uir", PSD1DPAN); if (psd1d_panel < 0) { psd1dui_error("Could not open user interface panel"); return; } /* Open the history panel */ history_panel = LoadPanel(0, "psd1duir.uir", HISTORYPAN); if (history_panel < 0) { psd1dui_error("Could not open user history panel"); return; } /* Display the panel when the user interface runs */ DisplayPanel(psd1d_panel); DisplayPanel(history_panel); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * psd1dui_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 psd1dui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nPSD1DUI 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 psd1dui_cmd_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: psd1d_close(); QuitUserInterface(0); break; } return 0; } /* ************************************************************** */ int CVICALLBACK psd1dui_timer (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { /* Declare variables */ double v1, v2; double x; static double filt_x = 0.; static int filt_num_samp = 0; int filt_required_num_samp; double sum_x; switch (event) { case EVENT_TIMER_TICK: /* Get the voltages */ psd1d_get_v_ave(&v1, &v2); SetCtrlVal (psd1d_panel, PSD1DPAN_NUM_V1, v1); SetCtrlVal (psd1d_panel, PSD1DPAN_NUM_V2, v2); SetCtrlVal (psd1d_panel, PSD1DPAN_NUM_V3, 0.); SetCtrlVal (psd1d_panel, PSD1DPAN_NUM_V4, 0.); /* Calculate the beam position */ psd1d_calc_pos(v1, v2, &x); /* Update the beam position display */ filt_x = filt_x + x; filt_num_samp++; GetCtrlVal (psd1d_panel, PSD1DPAN_NUM_FILTER, &filt_required_num_samp); if (filt_num_samp >= filt_required_num_samp) { filt_x = filt_x / filt_num_samp; SetCtrlVal (psd1d_panel, PSD1DPAN_NUM_MET_X, filt_x); SetCtrlVal (psd1d_panel, PSD1DPAN_NUM_MET_Y, 0.); filt_x = 0.; filt_num_samp = 0; } /* Update the beam history plot */ PlotPoint (history_panel, HISTORYPAN_GRAPH_HISTORY, x, 0., VAL_SMALL_SOLID_SQUARE, VAL_BLACK); sum_x = ave_x * num_points + x; num_points = num_points + 1; ave_x = sum_x / num_points; SetCtrlVal (history_panel, HISTORYPAN_NUM_AVE_X, ave_x); SetCtrlVal (history_panel, HISTORYPAN_NUM_AVE_Y, 0.); break; } return 0; } /* ************************************************************** */ int CVICALLBACK psd1dui_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.; SetCtrlVal (history_panel, HISTORYPAN_NUM_AVE_X, ave_x); SetCtrlVal (history_panel, HISTORYPAN_NUM_AVE_Y, 0.); break; } return 0; }