/* ************************************************************** */ /* * Module VMAGUI * This module contains functions for the VMAG * user interface. * * Zachary Wolf * 12/15/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include "vmaguir.h" #include "vmagui.h" #include "vmag.h" /* ************************************************************** */ /* PRIVATE PARAMETERS */ static struct vmag_param_struct vmag_param; /* ************************************************************** */ /* PRIVATE VARIABLES */ static int vmag_panel; static int vmagop_panel; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONSS */ void vmagui_error(char* msg); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * vmagui_init * This function initializes the 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 * vmag_par, vmag system parameters * * Zachary Wolf * 12/15/00 */ void vmagui_init(int top_pos, int left_pos, struct vmag_param_struct vmag_par) { /* Declare variables */ char name_string[80]; /* Save parameters for future use */ vmag_param = vmag_par; /* Make sure the user interface panel is desired */ if (vmag_param.show_ui != VMAG_TRUE) return; /* Open the VMAG panel */ vmag_panel = LoadPanel(0, "vmaguir.uir", VMAGPAN); if (vmag_panel < 0) { vmagui_error("Could not open user interface panel"); return; } /* Set the panel position */ SetPanelPos(vmag_panel, top_pos, left_pos); /* Display the panel when the user interface runs */ DisplayPanel(vmag_panel); /* Write a header in the text box */ strcpy(name_string, "Magnet Voltage (V)"); SetCtrlVal (vmag_panel, VMAGPAN_TEXTMSG_DESCRIPTION, name_string); /* Done */ return; } /* ************************************************************** */ /* * vmagopui_init * This function initializes the user interface for the VMAG 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 * 12/15/00 */ void vmagopui_init(int top_pos, int left_pos) { /* Open the panel */ vmagop_panel = LoadPanel(0, "vmaguir.uir", VMAGOPPAN); if (vmag_panel < 0) { vmagui_error("Could not open user interface panel"); return; } /* Set the panel position */ SetPanelPos(vmagop_panel, top_pos, left_pos); /* Display the panel when the user interface runs */ DisplayPanel(vmagop_panel); /* Done */ return; } /* ************************************************************** */ void vmagui_update(double voltage) { /* Declare variables */ char vmag_val_string[80]; /* Check for the user interface */ if (vmag_param.show_ui != VMAG_TRUE) return; /* Display the new values */ sprintf(vmag_val_string, "%s %7.2f\n", TimeStr(), voltage); SetCtrlVal (vmag_panel, VMAGPAN_TEXTBOX_VALUE, vmag_val_string); /* Add the new value to the strip chart */ PlotStripChartPoint(vmag_panel, VMAGPAN_STRIPCHART_VOLTAGE, voltage); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * vmagui_error * This function handles error messages for the VMAG user interface. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/15/00 */ void vmagui_error(char* message) { /* Declare variables */ char buf[VMAG_MAX_CMD]; /* Notify the operator of the error */ printf("\nVMAGUI 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, VMAG_MAX_CMD, stdin); if (buf[0] == '\n') return; else exit(0); } /* ************************************************************** */ /* PRIVATE USER INTERFACE FUNCTIONS */ /* ************************************************************** */ int CVICALLBACK vmagui_get_voltage(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double voltage; switch (event) { case EVENT_COMMIT: vmag_get_voltage(&voltage); vmagui_update(voltage); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK vmagui_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: vmag_exit(); QuitUserInterface(0); break; case EVENT_RIGHT_CLICK: break; } return 0; }