/* ************************************************************** */ /* * Module AMBIENTUI * This module contains functions for the AMBIENT * user interface. * * Zachary Wolf * 3/26/02 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include "ambientuir.h" #include "ambientui.h" #include "ambient.h" /* ************************************************************** */ /* PRIVATE PARAMETERS */ static struct ambient_param_struct ambient_param; /* ************************************************************** */ /* PRIVATE VARIABLES */ static int ambient_panel; static int ambientop_panel; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONSS */ void ambientui_error(char* msg); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * ambientui_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 * ambient_par, ambient system parameters * * Zachary Wolf * 3/26/02 */ void ambientui_init(int top_pos, int left_pos, struct ambient_param_struct ambient_par) { /* Declare variables */ int i; char sn_name_string[80]; char name_string[800]; /* Save parameters for future use */ ambient_param = ambient_par; /* Make sure the user interface panel is desired */ if (ambient_param.show_ui != AMBIENT_TRUE) return; /* Open the AMBIENT panel */ ambient_panel = LoadPanel(0, "ambientuir.uir", AMBIENTPAN); if (ambient_panel < 0) { ambientui_error("Could not open user interface panel"); return; } /* Set the panel position */ SetPanelPos(ambient_panel, top_pos, left_pos); /* Display the panel when the user interface runs */ DisplayPanel(ambient_panel); /* Write the sensor names in the text box */ strcpy(name_string, ""); for (i = 0; i < ambient_param.num_sensors; i++) { sprintf(sn_name_string, "S%i: %-10.10s", i, ambient_param.sensor[i].name); strcat(name_string, sn_name_string); if ((i+1) % 3 == 0) strcat(name_string, "\n"); else strcat(name_string, " "); } SetCtrlVal (ambient_panel, AMBIENTPAN_TEXTMSG_DESCRIPTION, name_string); /* Set the number of traces in the strip chart */ SetCtrlAttribute(ambient_panel, AMBIENTPAN_STRIPCHART_AMBIENT, ATTR_NUM_TRACES, ambient_param.num_sensors); /* Done */ return; } /* ************************************************************** */ /* * ambientopui_init * This function initializes the user interface for the AMBIENT 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 * 3/26/02 */ void ambientopui_init(int top_pos, int left_pos) { /* Open the panel */ ambientop_panel = LoadPanel(0, "ambientuir.uir", AMBOPPAN); if (ambient_panel < 0) { ambientui_error("Could not open user interface panel"); return; } /* Set the panel position */ SetPanelPos(ambientop_panel, top_pos, left_pos); /* Display the panel when the user interface runs */ DisplayPanel(ambientop_panel); /* Done */ return; } /* ************************************************************** */ void ambientui_update(int num_sensors, double meas_value[]) { /* Declare variables */ char sensor_string[300]; char sensor_val_string[50]; int i; /* Check for the user interface */ if (ambient_param.show_ui != AMBIENT_TRUE) return; /* Display the new values */ sprintf(sensor_string, "%s ", TimeStr()); for (i = 0; i < num_sensors; i++) { sprintf(sensor_val_string, "%6.2f ", meas_value[i]); strcat(sensor_string, sensor_val_string); } strcat(sensor_string, "\n"); SetCtrlVal (ambient_panel, AMBIENTPAN_TEXTBOX_VALUE, sensor_string); /* Add the new values to the strip chart */ PlotStripChart(ambient_panel, AMBIENTPAN_STRIPCHART_AMBIENT, meas_value, num_sensors, 0, 0, VAL_DOUBLE); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * ambientui_error * This function handles error messages for the AMBIENT user interface. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 3/26/02 */ void ambientui_error(char* message) { /* Declare variables */ char buf[AMBIENT_MAX_CMD]; /* Notify the operator of the error */ printf("\nAMBIENTUI 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, AMBIENT_MAX_CMD, stdin); if (buf[0] == '\n') return; else exit(0); } /* ************************************************************** */ /* PRIVATE USER INTERFACE FUNCTIONS */ /* ************************************************************** */ int CVICALLBACK ambientui_get_meas(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int num_sensors; double meas_value[AMBIENT_MAX_NUM_SENSORS]; int i; switch (event) { case EVENT_COMMIT: ambient_get_num_sensors(&num_sensors); for (i = 0; i < num_sensors; i++) ambient_get_sensor_output(i, &meas_value[i]); ambientui_update(num_sensors, meas_value); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK ambientui_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: ambient_exit(); QuitUserInterface(0); break; case EVENT_RIGHT_CLICK: break; } return 0; }