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
Diff: main.cpp
- Revision:
- 8:e9f836163229
- Parent:
- 7:cca801103b86
- Child:
- 9:5a0c4c6e39c7
--- a/main.cpp Tue Sep 23 23:44:16 2014 +0000
+++ b/main.cpp Wed Sep 24 01:46:02 2014 +0000
@@ -1,4 +1,3 @@
-
#include "mbed.h"
#include "LocalPinNames.h"
#include "BridgeDriver.h"
@@ -171,27 +170,13 @@
if (k == numParam - 1)
last = 1;
- if (!last && (prevCondition != AND || prevCondition != OR)){
+ if (!last){
if (paramCondition[k].op != xAND && paramCondition[k].op != xOR && paramCondition[k + 1].op != xAND && paramCondition[k + 1].op != xOR){
- lcd.setAddress(0,3);
- lcd.printf("Test 0.1 ");
- wait(1);
-
//AND
if (paramCondition[k].op == AND){
- lcd.setAddress(0,3);
- lcd.printf("Test 1.1 ");
- wait(1);
- if (!first && prevCondition != xAND && prevCondition != xOR){
- lcd.setAddress(0,3);
- lcd.printf("Test 1.11 ");
- wait(1);
+ if (!first && prevCondition != xAND && prevCondition != xOR)
combinedCondition.back().value = combinedCondition.back().value && paramCondition[k + 1].value;
- }
else if (first || prevCondition == xAND || prevCondition == xOR){
- lcd.setAddress(0,3);
- lcd.printf("Test 1.12 ");
- wait(1);
tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value;
combinedCondition.push_back(tempCombinedCondition);
first = 0;
@@ -201,19 +186,9 @@
//OR
else if (paramCondition[k].op == OR){
- lcd.setAddress(0,3);
- lcd.printf("Test 1.2 ");
- wait(1);
- if (!first && prevCondition != xAND && prevCondition != xOR){
- lcd.setAddress(0,3);
- lcd.printf("Test 1.3 ");
- wait(1);
+ if (!first && prevCondition != xAND && prevCondition != xOR)
combinedCondition.back().value = combinedCondition.back().value || paramCondition[k + 1].value;
- }
else if (first || prevCondition == xAND || prevCondition == xOR){
- lcd.setAddress(0,3);
- lcd.printf("Test 1.4 ");
- wait(1);
tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value;
combinedCondition.push_back(tempCombinedCondition);
first = 0;
@@ -224,61 +199,58 @@
// first value is something, not exclusive, but next values are exclusive
else if (first && (paramCondition[k].op == AND || paramCondition[k].op == OR) && (paramCondition[k + 1].op == xAND || paramCondition[k + 1].op == xOR)){
- lcd.setAddress(0,3);
- lcd.printf("Test 1 ");
- wait(1);
tempCombinedCondition.value = paramCondition[k].value;
tempCombinedCondition.op = paramCondition[k].op;
combinedCondition.push_back(tempCombinedCondition);
prevCondition = paramCondition[k].op;
first = 0;
- lcd.setAddress(0,3);
- lcd.printf("1cCval: %d ", combinedCondition.back().value);
- wait(1);
}
else{
- /*lcd.setAddress(0,3);
- lcd.printf("Test 0.2 ");
- wait(1);*/
//xAND
- if (paramCondition[k].op == xAND && prevCondition == xAND){
- lcd.setAddress(0,3);
- lcd.printf("Test 2.1 ");
- wait(1);
- combinedCondition.back().value = combinedCondition.back().value && paramCondition[k + 1].value;
- prevCondition = xAND;
- }
- else if (paramCondition[k].op == xAND && prevCondition != xAND){
- lcd.setAddress(0,3);
- lcd.printf("Test 2.2 ");
- wait(1);
- tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value;
- combinedCondition.push_back(tempCombinedCondition);
- prevCondition = xAND;
+ if (paramCondition[k].op == xAND){
+ if (combinedCondition.size() == 0){ // No values so start a new combinedCondition
+ tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value;
+ tempCombinedCondition.op = xAND;
+ combinedCondition.push_back(tempCombinedCondition);
+ prevCondition = xAND;
+ }
+ else{
+ if (combinedCondition.back().op == xAND){ // AND the value to the back most combinedCondition
+ combinedCondition.back().value = combinedCondition.back().value && paramCondition[k + 1].value;
+ prevCondition = xAND;
+ }
+ else if (combinedCondition.back().op != xAND){ // Start a new combinedCondition
+ tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value;
+ tempCombinedCondition.op = xAND;
+ combinedCondition.push_back(tempCombinedCondition);
+ prevCondition = xAND;
+ }
+ }
+
}
//xOR
- else if (paramCondition[k].op == xOR && prevCondition == xOR){
- lcd.setAddress(0,3);
- lcd.printf("Test 2.3 ");
- wait(1);
- combinedCondition.back().value = combinedCondition.back().value || paramCondition[k + 1].value;
- prevCondition = xOR;
- lcd.setAddress(0,3);
- lcd.printf("2.3cCval: %d ", combinedCondition.back().value);
- wait(1);
- }
- else if (paramCondition[k].op == xOR && prevCondition != xOR){
- lcd.setAddress(0,3);
- lcd.printf("Test 2.4 ");
- wait(1);
- tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value;
- combinedCondition.push_back(tempCombinedCondition);
- prevCondition = xOR;
- lcd.setAddress(0,3);
- lcd.printf("2.4cCval: %d ", combinedCondition.back().value);
- wait(1);
+ else if (paramCondition[k].op == xOR){
+ if (combinedCondition.size() == 0){ // No values so start a new combinedCondition
+ tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value;
+ tempCombinedCondition.op = xOR;
+ combinedCondition.push_back(tempCombinedCondition);
+ prevCondition = xOR;
+ }
+ else{
+ if (combinedCondition.back().op == xOR){ // OR the value to the back most combinedCondition
+ combinedCondition.back().value = combinedCondition.back().value || paramCondition[k + 1].value;
+ prevCondition = xOR;
+ }
+ else if (combinedCondition.back().op != xOR){ // Start a new combinedCondition
+ tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value;
+ tempCombinedCondition.op = xOR;
+ combinedCondition.push_back(tempCombinedCondition);
+ prevCondition = xOR;
+ }
+ }
+
}
// Since the k + 1 value is included in the xAND or xOR exclusively, skip checking that value, and add the appropriate AND / OR as the
@@ -290,13 +262,12 @@
}
}
-
- //else if (last && (prevCondition != AND || prevCondition != OR)){
- //the last value was not included in any combination, since directly before the last value was an xAND / xOR set that
- // included the very last AND / OR as the set's operator
- else if (last && (prevCondition != AND || prevCondition != OR)){
+ // the last value was not included in any combination, since directly before the last value was an xAND / xOR set that
+ // included the very last AND / OR as the set's operator, yet there is still another value that has not been combined, as it is supposed
+ // to be AND /OR to the exclusive xAND / xOR set
+ else if (last && (prevCondition == xAND || prevCondition == xOR) && (combinedCondition.back().op == AND || combinedCondition.back().op == OR)){
tempCombinedCondition.value = paramCondition[k].value;
tempCombinedCondition.op = NONE;
combinedCondition.push_back(tempCombinedCondition);
@@ -306,10 +277,6 @@
tempCombinedCondition = ConditionOp();
}
-
- lcd.setAddress(0,3);
- lcd.printf("cCsize: %d ", combinedCondition.size());
- wait(1);
// run through all values in the combined Condition vector, AND'ing / OR'ing as appropriate
// in the end, the last value in the array should be the final condition of the Condition statement... whether it was successful or failed
@@ -604,7 +571,7 @@
getNextLine(selectedFile, lineData);
int checkEnd = interpretCommand(selectedFile, lineData);
- if (checkEnd == 0)
+ if (checkEnd == 2)
endOfFile = 1;
}