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
Revision 14:953820302fb7, committed 2014-10-02
- Comitter:
- mehatfie
- Date:
- Thu Oct 02 23:49:44 2014 +0000
- Parent:
- 13:899db9d635e5
- Child:
- 15:c944ee3c8a5b
- Commit message:
- - Working system, code testing on two Test Systems and works directly as desired; - Fixed bug where the cycle timer does not add the first cycle and takes it as zero
Changed in this revision
--- a/Devices/Motor.cpp Wed Oct 01 23:08:39 2014 +0000
+++ b/Devices/Motor.cpp Thu Oct 02 23:49:44 2014 +0000
@@ -2,12 +2,13 @@
//Constructor
Motor::Motor(LineData lineData){
+ this->errorFlag = 0;
//Order of Line: Command, Local_Name, MOTOR, MotorID(A,B,C,D)
//Since we can't return from a constructor, instead we'll flip a flag, and check it after we've added the device in interpretCommand
if (lineData.numWords != 4)
this->errorFlag = 1;
-
+
string channel = lineData.word[3]; //Parameter is a single character, so dereference the point to the word
if ((channel.compare("A") == 0) || (channel.compare("a") == 0))
--- a/Devices/PinIN.cpp Wed Oct 01 23:08:39 2014 +0000
+++ b/Devices/PinIN.cpp Thu Oct 02 23:49:44 2014 +0000
@@ -5,6 +5,7 @@
//Constructor
PinIN::PinIN(LineData lineData){
+ this->errorFlag = 0;
//Order of Line: Command, Local_Name, PIN_IN, pinName, pinMode
if (lineData.numWords != 5)
--- a/Devices/VoltageDriver.cpp Wed Oct 01 23:08:39 2014 +0000
+++ b/Devices/VoltageDriver.cpp Thu Oct 02 23:49:44 2014 +0000
@@ -2,7 +2,8 @@
//Constructor
VoltageDriver::VoltageDriver(LineData lineData){
-
+ this->errorFlag = 0;
+
//Order of Line: Command, Local_Name, VOLTAGE_DRIVER, Channel(1,2,3,4,5,6,7,8)
if (lineData.numWords != 4)
this->errorFlag = 1;
--- a/Initialization.cpp Wed Oct 01 23:08:39 2014 +0000 +++ b/Initialization.cpp Thu Oct 02 23:49:44 2014 +0000 @@ -46,7 +46,7 @@ TextLCD_I2C lcd( &i2c, MCP23008_SA0, TextLCD::LCD20x4 ); // LCD SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // the pinout on the mbed LPC1768 -DigitalIn killSw(KILL); +DigitalIn killSw(KILL, PullUp); //Ticker errorWatcher;
--- a/main.cpp Wed Oct 01 23:08:39 2014 +0000
+++ b/main.cpp Thu Oct 02 23:49:44 2014 +0000
@@ -15,6 +15,8 @@
using std::string;
FrontPanelButtons buttons(&i2c);
+Timer cycleTimer;
+CycleWatch cycleWatch;
//extern "C" void mbed_reset(); //enable software reset of code
@@ -337,8 +339,6 @@
/**********************************************************************************************************************************/
/**********************************************************************************************************************************/
-Timer cycleTimer;
-CycleWatch cycleWatch;
int cycleCommand(LineData &lineData, int cycleState){
// if cycleState is 1, then initialize the cycle
@@ -414,6 +414,10 @@
ErrorOut("Init Cycle Failed to seek line", lineData.lineNumber); //Spaces make it look nice on the LCD
return -1;
}
+
+ //Restart the timer for the next cycle
+ cycleTimer.reset();
+ cycleTimer.start();
}
@@ -624,6 +628,37 @@
int interpretCommand(LineData &lineData){
+ //Monitor the Kill Switch, pause the system as needed
+ if(killSw == 1){
+ //place all devices into the pause functionality
+ int i = 0;
+ for(i = 0; i < devices.size(); i++)
+ devices[i]->pause();
+
+ cycleTimer.stop(); //pause the cycle timer
+
+ //Notify the User of the System Kill
+ lcd.setAddress(0,3);
+ lcd.printf(" Killed! ");
+
+ int flag = 0;
+ while (flag == 0){
+ while(killSw == 1);
+ wait(0.04);
+ if (killSw == 0)
+ flag = 1;
+ }
+
+ //place all devices into the resume functionality
+ for(i = 0; i < devices.size(); i++)
+ devices[i]->resume();
+
+ lcd.setAddress(0,3);
+ lcd.printf(" "); // Clear the Line using Spaces (Emptyness) - Note one line is 20 Characters
+ cycleTimer.start(); //start the cycle timer
+ }
+
+
//Monitors the conditions to watch for erroring, and pauses system if any of the conditions turn out to be true
if (!interprettingErrorFlag && enableErrors){
int j = 0, error = -1, numError = 0;
@@ -708,7 +743,7 @@
//since the constructor cannot return a value, it will trip the error Flag if something is wrong, check that flag, and return error if it has been tripped
if (devices.back()->errorFlag == 1){
- ErrorOut("Error initializing device", lineData.lineNumber);
+ ErrorOut("Error initializing device", lineData.lineNumber);
return -1;
}
}
@@ -1000,7 +1035,7 @@
/**********************************************************************************************************************************/
int main() {
-
+
fullInit(); //Initialize anything that's required to run the code (LCD)
LineData lineData;
@@ -1082,7 +1117,7 @@
/******************************************************************************/
/*** <Start Running through the Program txt File Lines> ***/
/******************************************************************************/
-
+while(1){
resetLineData(lineData); //Reset the values in the struct that holds the File / Line Data
lcd.cls(); //clear the display
@@ -1146,10 +1181,9 @@
lcd.printf("Press BACK");
while(!buttons.readBack());
-
- lcd.setAddress(0,1);
- //rewind(selectedFile);
+ rewind(selectedFile);
+}
}
\ No newline at end of file