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

Committer:
mehatfie
Date:
Wed Oct 01 19:31:02 2014 +0000
Revision:
12:2e3e86714243
Parent:
11:bc9cd2869f95
Child:
14:953820302fb7
- Working Copy; - Cycle Functionality working, able to update desired number of cycles on program; -Error Watch working, except doesn't seem to work for the first cycle... at the moment this is fine, considering technician will be there for first cycle

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mehatfie 2:3e7baa3e3fec 1 #include "Initialization.hpp"
mehatfie 2:3e7baa3e3fec 2 #include "Motor.hpp"
mehatfie 2:3e7baa3e3fec 3 #include "VoltageDriver.hpp"
mehatfie 4:86d0d04cc055 4 #include "PinIN.hpp"
mehatfie 11:bc9cd2869f95 5 #include "TimerDevice.hpp"
mehatfie 3:078e9a1e8be3 6
mehatfie 3:078e9a1e8be3 7
mehatfie 3:078e9a1e8be3 8 /**********************************************************************************************************************************/
mehatfie 3:078e9a1e8be3 9 /**********************************************************************************************************************************/
mehatfie 3:078e9a1e8be3 10 /************************** <MUST MODIFY> *************************/
mehatfie 3:078e9a1e8be3 11 /**********************************************************************************************************************************/
mehatfie 3:078e9a1e8be3 12 /**********************************************************************************************************************************/
mehatfie 3:078e9a1e8be3 13
mehatfie 3:078e9a1e8be3 14 // ADD YOUR DEVICE NAME THE \\EXACT SAME WAY\\ AS THE ENUM NAME YOU DECLARED IN THE.hpp
mehatfie 3:078e9a1e8be3 15 // Must Declare names in reverse order for some reason...., it's the way they're indexed I believe
mehatfie 11:bc9cd2869f95 16 const string DeviceNames[] = {"MOTOR", "VOLTAGE_DRIVER", "PIN_IN", "TIMER_DEVICE", "CAN_DEVICE"};
mehatfie 3:078e9a1e8be3 17
mehatfie 3:078e9a1e8be3 18 // ADD YOUR DEVICE TO THE LIST BELOW, CALLING YOUR DEVICE CLASS AS SHOWN
mehatfie 5:e36e0538a903 19 Device* Device::newDevice(int deviceFound, string _name, LineData lineData){
mehatfie 3:078e9a1e8be3 20
mehatfie 3:078e9a1e8be3 21 switch (Device_Map[deviceFound]){
mehatfie 3:078e9a1e8be3 22 case MOTOR: return new Motor(lineData); break;
mehatfie 3:078e9a1e8be3 23 case VOLTAGE_DRIVER: return new VoltageDriver(lineData); break;
mehatfie 4:86d0d04cc055 24 case PIN_IN: return new PinIN(lineData); break;
mehatfie 11:bc9cd2869f95 25 case TIMER_DEVICE: return new TimerDevice(lineData); break;
mehatfie 3:078e9a1e8be3 26
mehatfie 3:078e9a1e8be3 27 //********** ADD NEXT DEVICE ABOVE **************//
mehatfie 3:078e9a1e8be3 28 default: break;
mehatfie 3:078e9a1e8be3 29 }
mehatfie 3:078e9a1e8be3 30 }
mehatfie 3:078e9a1e8be3 31
mehatfie 3:078e9a1e8be3 32 /************************** <MUST MODIFY> *************************/
mehatfie 3:078e9a1e8be3 33 /**********************************************************************************************************************************/
mehatfie 3:078e9a1e8be3 34 /**********************************************************************************************************************************/
mehatfie 3:078e9a1e8be3 35
mehatfie 3:078e9a1e8be3 36
mehatfie 3:078e9a1e8be3 37
mehatfie 3:078e9a1e8be3 38 /******************************************************************************/
mehatfie 3:078e9a1e8be3 39 /*** <Global Initializations> ***/
mehatfie 3:078e9a1e8be3 40 /******************************************************************************/
mehatfie 3:078e9a1e8be3 41
mehatfie 2:3e7baa3e3fec 42 //Initializations
mehatfie 2:3e7baa3e3fec 43 Timer timer; // general purpose timer
mehatfie 2:3e7baa3e3fec 44 I2C i2c( P0_10, P0_11 ); // I2C bus (SDA, SCL)
mehatfie 2:3e7baa3e3fec 45 BridgeDriver bridges(&i2c, 1); // Bridge
mehatfie 2:3e7baa3e3fec 46 TextLCD_I2C lcd( &i2c, MCP23008_SA0, TextLCD::LCD20x4 ); // LCD
mehatfie 2:3e7baa3e3fec 47 SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // the pinout on the mbed LPC1768
mehatfie 2:3e7baa3e3fec 48
mehatfie 2:3e7baa3e3fec 49 DigitalIn killSw(KILL);
mehatfie 2:3e7baa3e3fec 50
mehatfie 11:bc9cd2869f95 51 //Ticker errorWatcher;
mehatfie 11:bc9cd2869f95 52
mehatfie 2:3e7baa3e3fec 53 const int MAX_LINE_LENGTH = 100;
mehatfie 6:d1594fd2ec5a 54 int DummyMode = 0; // run through the code without performing actions
mehatfie 11:bc9cd2869f95 55 FILE *selectedFile;
mehatfie 11:bc9cd2869f95 56 int errorFLAG = 0;
mehatfie 11:bc9cd2869f95 57
mehatfie 11:bc9cd2869f95 58 vector<GoToLabel> GoToLabels; //Initialize vector of struct for GoTo Labels
mehatfie 2:3e7baa3e3fec 59
mehatfie 3:078e9a1e8be3 60 /******************************************************************************/
mehatfie 3:078e9a1e8be3 61 /*** <Function Initializations> ***/
mehatfie 3:078e9a1e8be3 62 /******************************************************************************/
mehatfie 2:3e7baa3e3fec 63
mehatfie 2:3e7baa3e3fec 64 void fullInit() {
mehatfie 2:3e7baa3e3fec 65
mehatfie 2:3e7baa3e3fec 66 killSw.mode(PullUp);
mehatfie 2:3e7baa3e3fec 67 initLCD();
mehatfie 11:bc9cd2869f95 68
mehatfie 11:bc9cd2869f95 69 //Initialize the Error Watcher Interrupt / Ticker
mehatfie 11:bc9cd2869f95 70 //errorWatcher.attach(&ErrorMonitor, 0.5);
mehatfie 11:bc9cd2869f95 71
mehatfie 2:3e7baa3e3fec 72 }
mehatfie 2:3e7baa3e3fec 73
mehatfie 2:3e7baa3e3fec 74 void initLCD(void) {
mehatfie 2:3e7baa3e3fec 75
mehatfie 2:3e7baa3e3fec 76 i2c.frequency(1000000);
mehatfie 2:3e7baa3e3fec 77 lcd.setBacklight(TextLCD::LightOn);
mehatfie 2:3e7baa3e3fec 78 wait(.6);
mehatfie 2:3e7baa3e3fec 79 lcd.cls(); //clear the display
mehatfie 2:3e7baa3e3fec 80 lcd.setAddress(0,0);
mehatfie 9:5a0c4c6e39c7 81 lcd.printf("Initializing...");
mehatfie 2:3e7baa3e3fec 82 }
mehatfie 2:3e7baa3e3fec 83
mehatfie 9:5a0c4c6e39c7 84 void ErrorOut(string message, int lineNumber){
mehatfie 9:5a0c4c6e39c7 85
mehatfie 9:5a0c4c6e39c7 86 lcd.cls(); //clear the display
mehatfie 9:5a0c4c6e39c7 87
mehatfie 9:5a0c4c6e39c7 88 lcd.setAddress(0,0);
mehatfie 9:5a0c4c6e39c7 89 lcd.printf("Error: %s", message);
mehatfie 9:5a0c4c6e39c7 90
mehatfie 9:5a0c4c6e39c7 91 lcd.setAddress(0,3);
mehatfie 9:5a0c4c6e39c7 92 lcd.printf("Line Number: %d", lineNumber);
mehatfie 9:5a0c4c6e39c7 93 }
mehatfie 3:078e9a1e8be3 94
mehatfie 3:078e9a1e8be3 95 /******************************************************************************/
mehatfie 3:078e9a1e8be3 96 /*** <Parent Device Class Initializations> ***/
mehatfie 3:078e9a1e8be3 97 /******************************************************************************/
mehatfie 3:078e9a1e8be3 98
mehatfie 3:078e9a1e8be3 99 int numDevices = sizeof(DeviceNames)/sizeof(DeviceNames[0]);
mehatfie 3:078e9a1e8be3 100 int currNumDevices = 0;
mehatfie 3:078e9a1e8be3 101
mehatfie 11:bc9cd2869f95 102 vector<Device*> devices; //create a vector to hold all of the devices
mehatfie 11:bc9cd2869f95 103
mehatfie 11:bc9cd2869f95 104
mehatfie 11:bc9cd2869f95 105 /******************************************************************************/
mehatfie 11:bc9cd2869f95 106 /*** <Error Monitor Initializations> ***/
mehatfie 11:bc9cd2869f95 107 /******************************************************************************/
mehatfie 11:bc9cd2869f95 108
mehatfie 11:bc9cd2869f95 109 //vector<ErrorCondition> errorMonitors; //Initialize vector of errors to monitor
mehatfie 11:bc9cd2869f95 110 //ErrorCondition errorMonitors[15];
mehatfie 11:bc9cd2869f95 111 //int numErrorMonitors = 0;
mehatfie 11:bc9cd2869f95 112 /*
mehatfie 11:bc9cd2869f95 113 //Monitors the conditions to watch for erroring, and pauses system if any of the conditions turn out to be true
mehatfie 11:bc9cd2869f95 114 void ErrorMonitor(){
mehatfie 11:bc9cd2869f95 115
mehatfie 11:bc9cd2869f95 116 int i = 0, error = -1, numError = 0;
mehatfie 11:bc9cd2869f95 117 for(i = 0; i < errorMonitors.size(); i++){
mehatfie 11:bc9cd2869f95 118 int checkCondition = 0;
mehatfie 11:bc9cd2869f95 119 checkCondition = interpretCommand(errorMonitors[i].errorToWatch);
mehatfie 11:bc9cd2869f95 120
mehatfie 11:bc9cd2869f95 121 //if Condition is true, that means the error occurred
mehatfie 11:bc9cd2869f95 122 if (checkCondition == 1){
mehatfie 11:bc9cd2869f95 123 numError++;
mehatfie 11:bc9cd2869f95 124
mehatfie 11:bc9cd2869f95 125 //if the error has a Fix / Reset command, do it
mehatfie 11:bc9cd2869f95 126 if (errorMonitors[i].hasFix){
mehatfie 11:bc9cd2869f95 127 int returnValue;
mehatfie 11:bc9cd2869f95 128 interpretCommand(errorMonitors[i].errorFix); //Fix / Reset the error based on how the user justified to do so
mehatfie 11:bc9cd2869f95 129 }
mehatfie 11:bc9cd2869f95 130
mehatfie 11:bc9cd2869f95 131 error = i; //Record index of error, will display only one error, but error will be last error that was true in the list
mehatfie 11:bc9cd2869f95 132 }
mehatfie 11:bc9cd2869f95 133 }
mehatfie 11:bc9cd2869f95 134
mehatfie 11:bc9cd2869f95 135 if (numError){
mehatfie 11:bc9cd2869f95 136 char errorMsg[100] = "Error Occurred!!! Item: ";
mehatfie 11:bc9cd2869f95 137 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
mehatfie 11:bc9cd2869f95 138 ErrorOut(errorMsg, numError);
mehatfie 11:bc9cd2869f95 139 errorFLAG = 1; //set error flag equal to 1 if error occurred
mehatfie 11:bc9cd2869f95 140 }
mehatfie 11:bc9cd2869f95 141 else
mehatfie 11:bc9cd2869f95 142 errorFLAG = 0; //set error flag equal to 0 if no errors occurred
mehatfie 11:bc9cd2869f95 143
mehatfie 11:bc9cd2869f95 144 }
mehatfie 11:bc9cd2869f95 145 */
mehatfie 11:bc9cd2869f95 146