Component Test's Software to work with "Universal Controller Box" - Software is an interpreter or "compiler" for programs to be done with a .txt file and read off of the SD Card
Dependencies: BridgeDriver FrontPanelButtons MCP23017 SDFileSystem TextLCD mbed
Initialization.cpp
00001 #include "Initialization.hpp" 00002 #include "Motor.hpp" 00003 #include "VoltageDriver.hpp" 00004 #include "PinIN.hpp" 00005 #include "TimerDevice.hpp" 00006 00007 00008 /**********************************************************************************************************************************/ 00009 /**********************************************************************************************************************************/ 00010 /************************** <MUST MODIFY> *************************/ 00011 /**********************************************************************************************************************************/ 00012 /**********************************************************************************************************************************/ 00013 00014 // ADD YOUR DEVICE NAME THE \\EXACT SAME WAY\\ AS THE ENUM NAME YOU DECLARED IN THE.hpp 00015 // Must Declare names in reverse order for some reason...., it's the way they're indexed I believe 00016 const string DeviceNames[] = {"MOTOR", "VOLTAGE_DRIVER", "PIN_IN", "TIMER_DEVICE", "CAN_DEVICE"}; 00017 00018 // ADD YOUR DEVICE TO THE LIST BELOW, CALLING YOUR DEVICE CLASS AS SHOWN 00019 Device* Device::newDevice(int deviceFound, string _name, LineData lineData){ 00020 00021 switch (Device_Map[deviceFound]){ 00022 case MOTOR: return new Motor(lineData); break; 00023 case VOLTAGE_DRIVER: return new VoltageDriver(lineData); break; 00024 case PIN_IN: return new PinIN(lineData); break; 00025 case TIMER_DEVICE: return new TimerDevice(lineData); break; 00026 00027 //********** ADD NEXT DEVICE ABOVE **************// 00028 default: break; 00029 } 00030 } 00031 00032 /************************** <MUST MODIFY> *************************/ 00033 /**********************************************************************************************************************************/ 00034 /**********************************************************************************************************************************/ 00035 00036 00037 00038 /******************************************************************************/ 00039 /*** <Global Initializations> ***/ 00040 /******************************************************************************/ 00041 00042 //Initializations 00043 Timer timer; // general purpose timer 00044 I2C i2c( P0_10, P0_11 ); // I2C bus (SDA, SCL) 00045 BridgeDriver bridges(&i2c, 1); // Bridge 00046 TextLCD_I2C lcd( &i2c, MCP23008_SA0, TextLCD::LCD20x4 ); // LCD 00047 SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // the pinout on the mbed LPC1768 00048 00049 DigitalIn killSw(KILL, PullUp); 00050 00051 //Ticker errorWatcher; 00052 00053 const int MAX_LINE_LENGTH = 100; 00054 int DummyMode = 0; // run through the code without performing actions 00055 FILE *selectedFile; 00056 int errorFLAG = 0; 00057 00058 vector<GoToLabel> GoToLabels; //Initialize vector of struct for GoTo Labels 00059 00060 /******************************************************************************/ 00061 /*** <Function Initializations> ***/ 00062 /******************************************************************************/ 00063 00064 void fullInit() { 00065 00066 killSw.mode(PullUp); 00067 initLCD(); 00068 00069 //Initialize the Error Watcher Interrupt / Ticker 00070 //errorWatcher.attach(&ErrorMonitor, 0.5); 00071 00072 } 00073 00074 void initLCD(void) { 00075 00076 i2c.frequency(1000000); 00077 lcd.setBacklight(TextLCD::LightOn); 00078 wait(.6); 00079 lcd.cls(); //clear the display 00080 lcd.setAddress(0,0); 00081 lcd.printf("Initializing..."); 00082 } 00083 00084 void ErrorOut(string message, int lineNumber){ 00085 00086 lcd.cls(); //clear the display 00087 00088 lcd.setAddress(0,0); 00089 lcd.printf("Error: %s", message); 00090 00091 lcd.setAddress(0,3); 00092 lcd.printf("Line Number: %d", lineNumber); 00093 } 00094 00095 /******************************************************************************/ 00096 /*** <Parent Device Class Initializations> ***/ 00097 /******************************************************************************/ 00098 00099 int numDevices = sizeof(DeviceNames)/sizeof(DeviceNames[0]); 00100 int currNumDevices = 0; 00101 00102 vector<Device*> devices; //create a vector to hold all of the devices 00103 00104 00105 /******************************************************************************/ 00106 /*** <Error Monitor Initializations> ***/ 00107 /******************************************************************************/ 00108 00109 //vector<ErrorCondition> errorMonitors; //Initialize vector of errors to monitor 00110 //ErrorCondition errorMonitors[15]; 00111 //int numErrorMonitors = 0; 00112 /* 00113 //Monitors the conditions to watch for erroring, and pauses system if any of the conditions turn out to be true 00114 void ErrorMonitor(){ 00115 00116 int i = 0, error = -1, numError = 0; 00117 for(i = 0; i < errorMonitors.size(); i++){ 00118 int checkCondition = 0; 00119 checkCondition = interpretCommand(errorMonitors[i].errorToWatch); 00120 00121 //if Condition is true, that means the error occurred 00122 if (checkCondition == 1){ 00123 numError++; 00124 00125 //if the error has a Fix / Reset command, do it 00126 if (errorMonitors[i].hasFix){ 00127 int returnValue; 00128 interpretCommand(errorMonitors[i].errorFix); //Fix / Reset the error based on how the user justified to do so 00129 } 00130 00131 error = i; //Record index of error, will display only one error, but error will be last error that was true in the list 00132 } 00133 } 00134 00135 if (numError){ 00136 char errorMsg[100] = "Error Occurred!!! Item: "; 00137 strcat(errorMsg, errorMonitors[error].errorToWatch.word[0].c_str()); //Send the first word of the error condition to help find out what the error was 00138 ErrorOut(errorMsg, numError); 00139 errorFLAG = 1; //set error flag equal to 1 if error occurred 00140 } 00141 else 00142 errorFLAG = 0; //set error flag equal to 0 if no errors occurred 00143 00144 } 00145 */ 00146
Generated on Sun Jul 24 2022 01:49:11 by
1.7.2