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:
Tue Sep 23 18:24:19 2014 +0000
Revision:
5:e36e0538a903
Parent:
4:86d0d04cc055
Child:
6:d1594fd2ec5a
- Conditional Command working successfully; --- Also working with loop command; - Each major command (interpret, loop, condition), must have a unique ending return value

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mehatfie 0:22618cf06f45 1
mehatfie 0:22618cf06f45 2 #include "mbed.h"
mehatfie 0:22618cf06f45 3 #include "LocalPinNames.h"
mehatfie 0:22618cf06f45 4 #include "BridgeDriver.h"
mehatfie 0:22618cf06f45 5 #include "FrontPanelButtons.h"
mehatfie 0:22618cf06f45 6 #include "TextLCD.h"
mehatfie 0:22618cf06f45 7 #include "SDFileSystem.h"
mehatfie 0:22618cf06f45 8 #include "Initialization.hpp"
mehatfie 0:22618cf06f45 9 #include "TextFile.h"
mehatfie 0:22618cf06f45 10 #include <stdio.h>
mehatfie 0:22618cf06f45 11 #include <string>
mehatfie 0:22618cf06f45 12 #include <stdlib.h>
mehatfie 0:22618cf06f45 13 #include <fstream>
mehatfie 0:22618cf06f45 14 #include <vector>
mehatfie 0:22618cf06f45 15 using std::string;
mehatfie 0:22618cf06f45 16
mehatfie 1:5731f31f96be 17 FrontPanelButtons buttons(&i2c);
mehatfie 1:5731f31f96be 18
mehatfie 0:22618cf06f45 19 //extern "C" void mbed_reset(); //enable software reset of code
mehatfie 0:22618cf06f45 20
mehatfie 1:5731f31f96be 21
mehatfie 1:5731f31f96be 22
mehatfie 5:e36e0538a903 23 int interpretCommand(FILE *, LineData &);
mehatfie 5:e36e0538a903 24 int loopCommand(FILE *, LineData &);
mehatfie 1:5731f31f96be 25
mehatfie 1:5731f31f96be 26 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 27 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 28 /*************************** <FUNCTION: resetLineData> **************************/
mehatfie 1:5731f31f96be 29 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 30 /**********************************************************************************************************************************/
mehatfie 5:e36e0538a903 31 void resetLineData(LineData &lineData){
mehatfie 0:22618cf06f45 32
mehatfie 2:3e7baa3e3fec 33 //lineData.fullLine.clear();
mehatfie 0:22618cf06f45 34 lineData.lineNumber = 0;
mehatfie 0:22618cf06f45 35 lineData.numWords = 0;
mehatfie 2:3e7baa3e3fec 36 lineData.lineAddress = 0;
mehatfie 0:22618cf06f45 37 }
mehatfie 0:22618cf06f45 38
mehatfie 0:22618cf06f45 39
mehatfie 0:22618cf06f45 40
mehatfie 1:5731f31f96be 41 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 42 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 43 /************************ <FUNCTION: cyclePrograms> *****************************/
mehatfie 1:5731f31f96be 44 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 45 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 46
mehatfie 2:3e7baa3e3fec 47 int cyclePrograms(vector<string> files, int SIZE, int currIndex, int direction){
mehatfie 0:22618cf06f45 48
mehatfie 0:22618cf06f45 49 int nextIndex = 0;
mehatfie 0:22618cf06f45 50 switch(direction){
mehatfie 0:22618cf06f45 51 case 0: //Cycle Back one File
mehatfie 0:22618cf06f45 52 if ((currIndex - 1) < 0)
mehatfie 0:22618cf06f45 53 nextIndex = SIZE - 1;
mehatfie 0:22618cf06f45 54 else
mehatfie 0:22618cf06f45 55 nextIndex = currIndex - 1;
mehatfie 0:22618cf06f45 56 break;
mehatfie 0:22618cf06f45 57 case 1: //Cycle Forward one File
mehatfie 0:22618cf06f45 58 if ((currIndex + 1) >= SIZE)
mehatfie 0:22618cf06f45 59 nextIndex = 0;
mehatfie 0:22618cf06f45 60 else
mehatfie 0:22618cf06f45 61 nextIndex = currIndex + 1;
mehatfie 0:22618cf06f45 62 break;
mehatfie 0:22618cf06f45 63 case -1: //set the selectedFile to the currIndex (used for initialization)
mehatfie 0:22618cf06f45 64 nextIndex = currIndex;
mehatfie 0:22618cf06f45 65 break;
mehatfie 0:22618cf06f45 66 }
mehatfie 0:22618cf06f45 67
mehatfie 0:22618cf06f45 68 //Output file on Display
mehatfie 0:22618cf06f45 69 lcd.setAddress(0,3);
mehatfie 0:22618cf06f45 70 lcd.printf(" "); // Clear the Line using Spaces (Emptyness) - Note one line is 20 Characters
mehatfie 0:22618cf06f45 71 wait(.2);
mehatfie 0:22618cf06f45 72 lcd.setAddress(0,3);
mehatfie 4:86d0d04cc055 73 lcd.printf("%s", files[nextIndex]);
mehatfie 0:22618cf06f45 74
mehatfie 0:22618cf06f45 75 return nextIndex; // Return the file index in the Array
mehatfie 0:22618cf06f45 76 }
mehatfie 0:22618cf06f45 77
mehatfie 0:22618cf06f45 78
mehatfie 5:e36e0538a903 79 /**********************************************************************************************************************************/
mehatfie 5:e36e0538a903 80 /**********************************************************************************************************************************/
mehatfie 5:e36e0538a903 81 /************************** <FUNCTION: conditionCommand> *****************************/
mehatfie 5:e36e0538a903 82 /**********************************************************************************************************************************/
mehatfie 5:e36e0538a903 83 /**********************************************************************************************************************************/
mehatfie 5:e36e0538a903 84
mehatfie 5:e36e0538a903 85 //Create an enum map of the positble conditions
mehatfie 5:e36e0538a903 86 enum ConditionType{xAND, AND, xOR, OR, NONE};
mehatfie 5:e36e0538a903 87 //static const enum ConditionType Condition_Map[] = {xAND, AND, xOR, OR};
mehatfie 5:e36e0538a903 88
mehatfie 5:e36e0538a903 89 struct ConditionOp{
mehatfie 5:e36e0538a903 90
mehatfie 5:e36e0538a903 91 int value; //returned value of the interpret function: 1 = meets criteria, 0 = criteria not met, -1 = failed to interpret
mehatfie 5:e36e0538a903 92 ConditionType op; //operator that follows the given parameter: x val 2 AND y val 3, if this ConditionOp is for x, then the value will be AND
mehatfie 5:e36e0538a903 93 };
mehatfie 5:e36e0538a903 94
mehatfie 5:e36e0538a903 95 int conditionCommand(FILE *selectedFile, LineData &lineData){
mehatfie 5:e36e0538a903 96
mehatfie 5:e36e0538a903 97 //Get the number of condition parameters
mehatfie 5:e36e0538a903 98 string numConditionVals = lineData.word[1];
mehatfie 5:e36e0538a903 99 int numConditionValues = 0;
mehatfie 5:e36e0538a903 100 sscanf(numConditionVals.c_str(), "%d", &numConditionValues);
mehatfie 5:e36e0538a903 101
mehatfie 5:e36e0538a903 102 //LineData tempLineData;
mehatfie 5:e36e0538a903 103 LineData param[15];
mehatfie 5:e36e0538a903 104 //vector<LineData> param;
mehatfie 5:e36e0538a903 105 vector<ConditionOp> paramCondition;
mehatfie 5:e36e0538a903 106
mehatfie 5:e36e0538a903 107 /*
mehatfie 5:e36e0538a903 108 int val1, val2, val3, val4;
mehatfie 5:e36e0538a903 109 LineData temp;
mehatfie 5:e36e0538a903 110 temp.numWords = 3;
mehatfie 5:e36e0538a903 111 temp.word[1] = "val";
mehatfie 5:e36e0538a903 112 temp.word[2] = "1";
mehatfie 5:e36e0538a903 113 while (true){
mehatfie 5:e36e0538a903 114
mehatfie 5:e36e0538a903 115 temp.word[0] = "pin1";
mehatfie 5:e36e0538a903 116 val1 = interpretCommand(selectedFile, temp);
mehatfie 5:e36e0538a903 117
mehatfie 5:e36e0538a903 118 temp.word[0] = "pin2";
mehatfie 5:e36e0538a903 119 val2 = interpretCommand(selectedFile, temp);
mehatfie 5:e36e0538a903 120
mehatfie 5:e36e0538a903 121 temp.word[0] = "pin3";
mehatfie 5:e36e0538a903 122 val3 = interpretCommand(selectedFile, temp);
mehatfie 5:e36e0538a903 123
mehatfie 5:e36e0538a903 124 temp.word[0] = "pin4";
mehatfie 5:e36e0538a903 125 val4 = interpretCommand(selectedFile, temp);
mehatfie 5:e36e0538a903 126
mehatfie 5:e36e0538a903 127 lcd.cls(); //clear the display
mehatfie 5:e36e0538a903 128 lcd.setAddress(0,0);
mehatfie 5:e36e0538a903 129 lcd.printf("Pin1: %d", val1);
mehatfie 5:e36e0538a903 130 lcd.setAddress(0,1);
mehatfie 5:e36e0538a903 131 lcd.printf("Pin2: %d", val2);
mehatfie 5:e36e0538a903 132 lcd.setAddress(0,2);
mehatfie 5:e36e0538a903 133 lcd.printf("Pin3: %d", val3);
mehatfie 5:e36e0538a903 134 lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 135 lcd.printf("Pin4: %d", val4);
mehatfie 5:e36e0538a903 136 wait(0.2);
mehatfie 5:e36e0538a903 137 }*/
mehatfie 5:e36e0538a903 138
mehatfie 5:e36e0538a903 139 //Fill the param Vector with Line structs of each individual device, this way we can send the Line struct to the appropriate interpret function without modification within the function itself
mehatfie 5:e36e0538a903 140 int i = 2, numParam = 0, paramNumWords = 0;
mehatfie 5:e36e0538a903 141 for (i = 2; i < lineData.numWords; i++){
mehatfie 5:e36e0538a903 142
mehatfie 5:e36e0538a903 143 lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 144 lcd.printf("Test2");
mehatfie 5:e36e0538a903 145
mehatfie 5:e36e0538a903 146 /*lcd.setAddress(0,2);
mehatfie 5:e36e0538a903 147 lcd.printf("i: %d, nW-1: %d ", i, (lineData.numWords - 1));
mehatfie 5:e36e0538a903 148 wait(2);*/
mehatfie 5:e36e0538a903 149
mehatfie 5:e36e0538a903 150 // if the word is not an AND or an OR, it must mean it's for the specific function
mehatfie 5:e36e0538a903 151 // set the current parameter's next word to be equal to the current word we're checking
mehatfie 5:e36e0538a903 152 // increase number of words that the parameter has
mehatfie 5:e36e0538a903 153 if (lineData.word[i] != "AND" && lineData.word[i] != "xAND" && lineData.word[i] != "OR" && lineData.word[i] != "xOR"){
mehatfie 5:e36e0538a903 154 // lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 155 // lcd.printf("%dlD[%d]: %s", numParam, i, lineData.word[i]);
mehatfie 5:e36e0538a903 156 // wait(2);
mehatfie 5:e36e0538a903 157 //tempLineData.word[paramNumWords] = lineData.word[i];
mehatfie 5:e36e0538a903 158 param[numParam].word[paramNumWords] = lineData.word[i];
mehatfie 5:e36e0538a903 159 paramNumWords++;
mehatfie 5:e36e0538a903 160
mehatfie 5:e36e0538a903 161 //if this is the last word in the line....
mehatfie 5:e36e0538a903 162 if(i == (lineData.numWords - 1)){
mehatfie 5:e36e0538a903 163 param[numParam].numWords = paramNumWords;
mehatfie 5:e36e0538a903 164 paramCondition[numParam].op = NONE;
mehatfie 5:e36e0538a903 165 numParam++;
mehatfie 5:e36e0538a903 166 }
mehatfie 5:e36e0538a903 167
mehatfie 5:e36e0538a903 168 }
mehatfie 5:e36e0538a903 169
mehatfie 5:e36e0538a903 170 // if the word is an AND or an OR, it must mean the last function has been completely identified
mehatfie 5:e36e0538a903 171 // set the parameters number of Words value to the calculated value
mehatfie 5:e36e0538a903 172 // increase the number of Parameters (the current parameter function we're filling)
mehatfie 5:e36e0538a903 173 else if (lineData.word[i].compare("AND") == 0 || lineData.word[i].compare("xAND") == 0 || lineData.word[i].compare("OR") == 0 || lineData.word[i].compare("xOR") == 0){
mehatfie 5:e36e0538a903 174
mehatfie 5:e36e0538a903 175 //tempLineData.numWords = paramNumWords;
mehatfie 5:e36e0538a903 176 param[numParam].numWords = paramNumWords;
mehatfie 5:e36e0538a903 177
mehatfie 5:e36e0538a903 178 paramCondition.push_back(ConditionOp());
mehatfie 5:e36e0538a903 179 if (lineData.word[i].compare("AND") == 0)
mehatfie 5:e36e0538a903 180 paramCondition[numParam].op = AND;
mehatfie 5:e36e0538a903 181 else if (lineData.word[i].compare("xAND") == 0)
mehatfie 5:e36e0538a903 182 paramCondition[numParam].op = xAND;
mehatfie 5:e36e0538a903 183 else if (lineData.word[i].compare("OR") == 0)
mehatfie 5:e36e0538a903 184 paramCondition[numParam].op = OR;
mehatfie 5:e36e0538a903 185 else if (lineData.word[i].compare("xOR") == 0)
mehatfie 5:e36e0538a903 186 paramCondition[numParam].op = xOR;
mehatfie 5:e36e0538a903 187
mehatfie 5:e36e0538a903 188 //param.push_back(LineData());
mehatfie 5:e36e0538a903 189 //param[numParam] = tempLineData;
mehatfie 5:e36e0538a903 190 //param.push_back(tempLineData); //add it to the vector list of parameters
mehatfie 5:e36e0538a903 191 //tempLineData = LineData(); //reset
mehatfie 5:e36e0538a903 192 numParam++; // increase the index of param
mehatfie 5:e36e0538a903 193 paramNumWords = 0; // reset the number of words
mehatfie 5:e36e0538a903 194 }
mehatfie 5:e36e0538a903 195 }
mehatfie 5:e36e0538a903 196
mehatfie 5:e36e0538a903 197
mehatfie 5:e36e0538a903 198 vector<ConditionOp> combinedCondition;
mehatfie 5:e36e0538a903 199 ConditionOp tempCombinedCondition;
mehatfie 5:e36e0538a903 200 int j = 0, k = 0, returnValue = -1;
mehatfie 5:e36e0538a903 201 for (j = 0; j < numParam; j++){
mehatfie 5:e36e0538a903 202 paramCondition[j].value = interpretCommand(selectedFile, param[j]);
mehatfie 5:e36e0538a903 203 }
mehatfie 5:e36e0538a903 204
mehatfie 5:e36e0538a903 205 //create the combined Condition vector (take care of this xAND and xOR statements and combine them into one so that the whole vector is just AND's and OR's)
mehatfie 5:e36e0538a903 206 //this should make the xAND's / xOR's into a single member of the combinedCondition vector
mehatfie 5:e36e0538a903 207 enum ConditionType prevCondition = NONE;
mehatfie 5:e36e0538a903 208 int first = 1, last = 0;
mehatfie 5:e36e0538a903 209 for (k = 0; k < numParam; k++){
mehatfie 5:e36e0538a903 210 /*
mehatfie 5:e36e0538a903 211 lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 212 lcd.printf("k: %d ", k);
mehatfie 5:e36e0538a903 213 wait(1);*/
mehatfie 5:e36e0538a903 214
mehatfie 5:e36e0538a903 215 if (k == numParam - 1)
mehatfie 5:e36e0538a903 216 last = 1;
mehatfie 5:e36e0538a903 217
mehatfie 5:e36e0538a903 218 if (!last && (prevCondition != AND || prevCondition != OR)){
mehatfie 5:e36e0538a903 219 if (paramCondition[k].op != xAND && paramCondition[k].op != xOR && paramCondition[k + 1].op != xAND && paramCondition[k + 1].op != xOR){
mehatfie 5:e36e0538a903 220
mehatfie 5:e36e0538a903 221 /* lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 222 lcd.printf("Test 0.1 ");
mehatfie 5:e36e0538a903 223 wait(1);*/
mehatfie 5:e36e0538a903 224
mehatfie 5:e36e0538a903 225 //AND
mehatfie 5:e36e0538a903 226 if (paramCondition[k].op == AND){
mehatfie 5:e36e0538a903 227 if (!first && prevCondition != xAND && prevCondition != xOR){
mehatfie 5:e36e0538a903 228 /* lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 229 lcd.printf("Test 1.6 ");
mehatfie 5:e36e0538a903 230 wait(1);*/
mehatfie 5:e36e0538a903 231 combinedCondition.back().value = combinedCondition.back().value && paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 232 }
mehatfie 5:e36e0538a903 233 else if (first || prevCondition == xAND || prevCondition == xOR){
mehatfie 5:e36e0538a903 234 /* lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 235 lcd.printf("Test 1.5 ");
mehatfie 5:e36e0538a903 236 wait(1);*/
mehatfie 5:e36e0538a903 237 tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 238 combinedCondition.push_back(tempCombinedCondition);
mehatfie 5:e36e0538a903 239 first = 0;
mehatfie 5:e36e0538a903 240 }
mehatfie 5:e36e0538a903 241 prevCondition = AND;
mehatfie 5:e36e0538a903 242 }
mehatfie 5:e36e0538a903 243
mehatfie 5:e36e0538a903 244 //OR
mehatfie 5:e36e0538a903 245 else if (paramCondition[k].op == OR){
mehatfie 5:e36e0538a903 246 if (!first && prevCondition != xAND && prevCondition != xOR){
mehatfie 5:e36e0538a903 247 combinedCondition.back().value = combinedCondition.back().value || paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 248 /*lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 249 lcd.printf("Test 1.1 ");
mehatfie 5:e36e0538a903 250 wait(1);*/
mehatfie 5:e36e0538a903 251 }else if (first || prevCondition == xAND || prevCondition == xOR){
mehatfie 5:e36e0538a903 252 /* lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 253 lcd.printf("Test 1.2 ");
mehatfie 5:e36e0538a903 254 wait(1);*/
mehatfie 5:e36e0538a903 255 tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 256 combinedCondition.push_back(tempCombinedCondition);
mehatfie 5:e36e0538a903 257 first = 0;
mehatfie 5:e36e0538a903 258 }
mehatfie 5:e36e0538a903 259 prevCondition = OR;
mehatfie 5:e36e0538a903 260 }
mehatfie 5:e36e0538a903 261 }
mehatfie 5:e36e0538a903 262
mehatfie 5:e36e0538a903 263 else{
mehatfie 5:e36e0538a903 264 /*lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 265 lcd.printf("Test 0.2 ");
mehatfie 5:e36e0538a903 266 wait(1);*/
mehatfie 5:e36e0538a903 267 //xAND
mehatfie 5:e36e0538a903 268 if (paramCondition[k].op == xAND && prevCondition == xAND){
mehatfie 5:e36e0538a903 269 /*lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 270 lcd.printf("Test 2 ");
mehatfie 5:e36e0538a903 271 wait(1);*/
mehatfie 5:e36e0538a903 272 combinedCondition.back().value = combinedCondition.back().value && paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 273 prevCondition = xAND;
mehatfie 5:e36e0538a903 274 }
mehatfie 5:e36e0538a903 275 else if (paramCondition[k].op == xAND && prevCondition != xAND){
mehatfie 5:e36e0538a903 276 /*lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 277 lcd.printf("Test 1 ");
mehatfie 5:e36e0538a903 278 wait(1);*/
mehatfie 5:e36e0538a903 279 tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 280 combinedCondition.push_back(tempCombinedCondition);
mehatfie 5:e36e0538a903 281 prevCondition = xAND;
mehatfie 5:e36e0538a903 282 }
mehatfie 5:e36e0538a903 283 /*else if (paramCondition[k].op != xAND && prevCondition == xAND){
mehatfie 5:e36e0538a903 284 combinedCondition.back().op = paramCondition[k].op;
mehatfie 5:e36e0538a903 285 prevCondition = xAND;
mehatfie 5:e36e0538a903 286 }*/
mehatfie 5:e36e0538a903 287
mehatfie 5:e36e0538a903 288 //xOR
mehatfie 5:e36e0538a903 289 else if (paramCondition[k].op == xOR && prevCondition == xOR){
mehatfie 5:e36e0538a903 290 /*lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 291 lcd.printf("Test 1.3 ");
mehatfie 5:e36e0538a903 292 wait(1);*/
mehatfie 5:e36e0538a903 293 combinedCondition.back().value = combinedCondition.back().value || paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 294 prevCondition = xOR;
mehatfie 5:e36e0538a903 295 }
mehatfie 5:e36e0538a903 296 else if (paramCondition[k].op == xOR && prevCondition != xOR){
mehatfie 5:e36e0538a903 297 /* lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 298 lcd.printf("Test 1.4 ");
mehatfie 5:e36e0538a903 299 wait(1);*/
mehatfie 5:e36e0538a903 300 tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 301 combinedCondition.push_back(tempCombinedCondition);
mehatfie 5:e36e0538a903 302 prevCondition = xOR;
mehatfie 5:e36e0538a903 303 }
mehatfie 5:e36e0538a903 304 /*else if (paramCondition[k].op != xOR && prevCondition == xOR){
mehatfie 5:e36e0538a903 305 combinedCondition.back().op = paramCondition[k].op;
mehatfie 5:e36e0538a903 306 prevCondition = xOR;
mehatfie 5:e36e0538a903 307 }*/
mehatfie 5:e36e0538a903 308
mehatfie 5:e36e0538a903 309 // 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
mehatfie 5:e36e0538a903 310 // operator of this exclusive xAND / xOR set
mehatfie 5:e36e0538a903 311 if ((paramCondition[k + 1].op == AND || paramCondition[k + 1].op == OR) && (prevCondition == xAND || prevCondition == xOR)){
mehatfie 5:e36e0538a903 312 /*lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 313 lcd.printf("Test 3 ");
mehatfie 5:e36e0538a903 314 wait(1);*/
mehatfie 5:e36e0538a903 315 combinedCondition.back().op = paramCondition[k + 1].op;
mehatfie 5:e36e0538a903 316 k++;
mehatfie 5:e36e0538a903 317 }
mehatfie 5:e36e0538a903 318
mehatfie 5:e36e0538a903 319 }
mehatfie 5:e36e0538a903 320 }
mehatfie 5:e36e0538a903 321
mehatfie 5:e36e0538a903 322 //the last value was not included in any combination, since directly before the last value was an xAND / xOR set that
mehatfie 5:e36e0538a903 323 // included the very last AND / OR as the set's operator
mehatfie 5:e36e0538a903 324 else{
mehatfie 5:e36e0538a903 325 /*lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 326 lcd.printf("Test 5 ");
mehatfie 5:e36e0538a903 327 wait(1);*/
mehatfie 5:e36e0538a903 328 tempCombinedCondition.value = paramCondition[k].value;
mehatfie 5:e36e0538a903 329 tempCombinedCondition.op = NONE;
mehatfie 5:e36e0538a903 330 combinedCondition.push_back(tempCombinedCondition);
mehatfie 5:e36e0538a903 331 }
mehatfie 5:e36e0538a903 332
mehatfie 5:e36e0538a903 333 //reset the tempCombinedCondition variable
mehatfie 5:e36e0538a903 334 tempCombinedCondition = ConditionOp();
mehatfie 5:e36e0538a903 335 }
mehatfie 5:e36e0538a903 336
mehatfie 5:e36e0538a903 337 // run through all values in the combined Condition vector, AND'ing / OR'ing as appropriate
mehatfie 5:e36e0538a903 338 // in the end, the last value in the array should be the final condition of the Condition statement... whether it was successful or failed
mehatfie 5:e36e0538a903 339 for (i = 0; i < (combinedCondition.size() - 1); i++){
mehatfie 5:e36e0538a903 340 if (combinedCondition[i].op == AND)
mehatfie 5:e36e0538a903 341 combinedCondition[i + 1].value = combinedCondition[i].value && combinedCondition[i + 1].value;
mehatfie 5:e36e0538a903 342 else if (combinedCondition[i].op == OR)
mehatfie 5:e36e0538a903 343 combinedCondition[i + 1].value = combinedCondition[i].value || combinedCondition[i + 1].value;
mehatfie 5:e36e0538a903 344 }
mehatfie 5:e36e0538a903 345
mehatfie 5:e36e0538a903 346 int conditionSuccess = combinedCondition.back().value; //value is the success(1) or failure(0) of the condition statement
mehatfie 5:e36e0538a903 347
mehatfie 5:e36e0538a903 348
mehatfie 5:e36e0538a903 349
mehatfie 5:e36e0538a903 350 int checkEnd = 0;
mehatfie 5:e36e0538a903 351 if (!conditionSuccess){
mehatfie 5:e36e0538a903 352 lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 353 lcd.printf("CONDITION FAILURE");
mehatfie 5:e36e0538a903 354 wait(1);
mehatfie 5:e36e0538a903 355 while (checkEnd != 4){
mehatfie 5:e36e0538a903 356
mehatfie 5:e36e0538a903 357 getNextLine(selectedFile, lineData);
mehatfie 5:e36e0538a903 358 if (lineData.word[0].compare("end") == 0)
mehatfie 5:e36e0538a903 359 checkEnd = interpretCommand(selectedFile, lineData);
mehatfie 5:e36e0538a903 360
mehatfie 5:e36e0538a903 361 if (checkEnd == 4) // custom return value for this function
mehatfie 5:e36e0538a903 362 return 0;
mehatfie 5:e36e0538a903 363 }
mehatfie 5:e36e0538a903 364 }
mehatfie 5:e36e0538a903 365
mehatfie 5:e36e0538a903 366 lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 367 lcd.printf("CONDITION SUCCESS");
mehatfie 5:e36e0538a903 368 wait(1);
mehatfie 5:e36e0538a903 369 int returnValue2 = 1;
mehatfie 5:e36e0538a903 370 // Return success as the function either met the condition and will continue from the next line, or
mehatfie 5:e36e0538a903 371 // failed to meet the condition and ran through the lines inside the condition until "end condition" was found, therefore
mehatfie 5:e36e0538a903 372 // the program will proceed from the line after the "end condition" line
mehatfie 5:e36e0538a903 373 return returnValue2;
mehatfie 5:e36e0538a903 374 }
mehatfie 5:e36e0538a903 375 /*
mehatfie 5:e36e0538a903 376 for (k = 0; k < numParam; k++){
mehatfie 5:e36e0538a903 377 if (paramCondition[k].op == AND){
mehatfie 5:e36e0538a903 378 if (paramCondition[k + 1].op != xAND && paramCondition[k + 1].op != xOR)
mehatfie 5:e36e0538a903 379 tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 380 else
mehatfie 5:e36e0538a903 381 tempCombinedCondition.value = paramCondition[k].value;
mehatfie 5:e36e0538a903 382
mehatfie 5:e36e0538a903 383 tempCombinedCondition.op = AND;
mehatfie 5:e36e0538a903 384 combinedCondition.push_back(tempCombinedCondition);
mehatfie 5:e36e0538a903 385 prevCondition = AND;
mehatfie 5:e36e0538a903 386 }
mehatfie 5:e36e0538a903 387
mehatfie 5:e36e0538a903 388 else if (paramCondition[k].op == OR){
mehatfie 5:e36e0538a903 389 if (paramCondition[k + 1].op != xAND && paramCondition[k + 1].op != xOR)
mehatfie 5:e36e0538a903 390 tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 391 else
mehatfie 5:e36e0538a903 392 tempCombinedCondition.value = paramCondition[k].value;
mehatfie 5:e36e0538a903 393
mehatfie 5:e36e0538a903 394 tempCombinedCondition.op = OR;
mehatfie 5:e36e0538a903 395 combinedCondition.push_back(tempCombinedCondition);
mehatfie 5:e36e0538a903 396 prevCondition = OR;
mehatfie 5:e36e0538a903 397 }
mehatfie 5:e36e0538a903 398
mehatfie 5:e36e0538a903 399 else if (paramCondition[k].op == xAND){
mehatfie 5:e36e0538a903 400 if (prevCondition == xAND) // if previous one was also xAND, that means we already have a vector member for this (this last member)
mehatfie 5:e36e0538a903 401 combinedCondition.back().value = combinedCondition.back().value && paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 402 else{ // if the prevCondition was not xAND, then we need to add a new member to the vector
mehatfie 5:e36e0538a903 403 tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 404 combinedCondition.push_back(tempCombinedCondition);
mehatfie 5:e36e0538a903 405 }
mehatfie 5:e36e0538a903 406 prevCondition = xAND;
mehatfie 5:e36e0538a903 407 }
mehatfie 5:e36e0538a903 408 else if (paramCondition[k].op == xOR){
mehatfie 5:e36e0538a903 409 tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value;
mehatfie 5:e36e0538a903 410 prevCondition = xOR;
mehatfie 5:e36e0538a903 411 }
mehatfie 5:e36e0538a903 412 }
mehatfie 5:e36e0538a903 413
mehatfie 5:e36e0538a903 414
mehatfie 5:e36e0538a903 415 return 1;*/
mehatfie 5:e36e0538a903 416
mehatfie 0:22618cf06f45 417
mehatfie 1:5731f31f96be 418 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 419 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 420 /************************** <FUNCTION: loopCommand> *****************************/
mehatfie 1:5731f31f96be 421 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 422 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 423
mehatfie 5:e36e0538a903 424 int loopCommand(FILE *selectedFile, LineData &lineData){
mehatfie 1:5731f31f96be 425
mehatfie 2:3e7baa3e3fec 426 //Get the Condition value for number of times to loop
mehatfie 2:3e7baa3e3fec 427 string loopCondition = lineData.word[1];
mehatfie 2:3e7baa3e3fec 428 int loopConditionValue = 0;
mehatfie 2:3e7baa3e3fec 429 sscanf(loopCondition.c_str(), "%d", &loopConditionValue);
mehatfie 1:5731f31f96be 430
mehatfie 2:3e7baa3e3fec 431 int loopStartAddress = 0, loopLineNumber = 0, firstLineOfLoop = 1;
mehatfie 2:3e7baa3e3fec 432
mehatfie 2:3e7baa3e3fec 433 int counter = 0, checkEnd = 0;
mehatfie 1:5731f31f96be 434 while (counter < loopConditionValue){
mehatfie 1:5731f31f96be 435
mehatfie 5:e36e0538a903 436 /*lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 437 lcd.printf("BcheckEnd: %d ", checkEnd);
mehatfie 5:e36e0538a903 438 wait(1);*/
mehatfie 5:e36e0538a903 439
mehatfie 5:e36e0538a903 440 getNextLine(selectedFile, lineData);
mehatfie 5:e36e0538a903 441
mehatfie 5:e36e0538a903 442 //Must get the address before entering the interpret command
mehatfie 5:e36e0538a903 443 // if a Condition command is immediately after, and the condition fails, then
mehatfie 5:e36e0538a903 444 // the interpret command will return the line at the "end condition" line, and therefore
mehatfie 5:e36e0538a903 445 // set the loop's first line to be the "end condition" line, if interpretCommand is called BEFORE setting the first loop line address
mehatfie 1:5731f31f96be 446 if (firstLineOfLoop){
mehatfie 1:5731f31f96be 447 loopStartAddress = lineData.lineAddress; //Save the Line Address
mehatfie 1:5731f31f96be 448 loopLineNumber = lineData.lineNumber; //Save the Line Number
mehatfie 1:5731f31f96be 449 firstLineOfLoop = 0;
mehatfie 1:5731f31f96be 450 }
mehatfie 5:e36e0538a903 451
mehatfie 5:e36e0538a903 452 checkEnd = interpretCommand(selectedFile, lineData);
mehatfie 5:e36e0538a903 453
mehatfie 5:e36e0538a903 454 /*lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 455 lcd.printf("AcheckEnd: %d ", checkEnd);
mehatfie 5:e36e0538a903 456 wait(1);*/
mehatfie 1:5731f31f96be 457
mehatfie 5:e36e0538a903 458
mehatfie 5:e36e0538a903 459 /*
mehatfie 5:e36e0538a903 460 lcd.setAddress(0,3);
mehatfie 5:e36e0538a903 461 lcd.printf("checkEnd: %d ", checkEnd);
mehatfie 5:e36e0538a903 462 wait(2);*/
mehatfie 1:5731f31f96be 463 //Increase the loop counter and go back to the beginning of the loop
mehatfie 5:e36e0538a903 464 if (checkEnd == 3){
mehatfie 2:3e7baa3e3fec 465 counter++;
mehatfie 2:3e7baa3e3fec 466
mehatfie 1:5731f31f96be 467 lcd.setAddress(0,2);
mehatfie 2:3e7baa3e3fec 468 lcd.printf("Loop Cycle %d of %d", counter, loopConditionValue);
mehatfie 2:3e7baa3e3fec 469
mehatfie 1:5731f31f96be 470 fseek(selectedFile, loopStartAddress, SEEK_SET);
mehatfie 2:3e7baa3e3fec 471 lineData.lineNumber = loopLineNumber - 2;
mehatfie 5:e36e0538a903 472 checkEnd = 0;
mehatfie 1:5731f31f96be 473 }
mehatfie 1:5731f31f96be 474 }
mehatfie 2:3e7baa3e3fec 475
mehatfie 1:5731f31f96be 476 return 1;
mehatfie 1:5731f31f96be 477 }
mehatfie 1:5731f31f96be 478
mehatfie 1:5731f31f96be 479 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 480 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 481 /************************* <FUNCTION: interpretCommand> *************************/
mehatfie 1:5731f31f96be 482 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 483 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 484
mehatfie 5:e36e0538a903 485 int interpretCommand(FILE *selectedFile, LineData &lineData){
mehatfie 2:3e7baa3e3fec 486
mehatfie 2:3e7baa3e3fec 487 if (lineData.word[0].compare("device") == 0){
mehatfie 2:3e7baa3e3fec 488
mehatfie 1:5731f31f96be 489 int i = 0, deviceFound = -1;
mehatfie 2:3e7baa3e3fec 490 for (i = 0; i < numDevices; i++){
mehatfie 4:86d0d04cc055 491 if (lineData.word[2].compare(DeviceNames[i]) == 0){
mehatfie 1:5731f31f96be 492 deviceFound = i;
mehatfie 4:86d0d04cc055 493 }
mehatfie 2:3e7baa3e3fec 494 }
mehatfie 1:5731f31f96be 495
mehatfie 1:5731f31f96be 496 //if the device type does not match any known type, error out
mehatfie 1:5731f31f96be 497 if (deviceFound == -1){
mehatfie 1:5731f31f96be 498 //Error Out since the device Name was not matched with anything *************************
mehatfie 1:5731f31f96be 499 }
mehatfie 1:5731f31f96be 500
mehatfie 1:5731f31f96be 501 //Add device to the array of devices and initialize it
mehatfie 2:3e7baa3e3fec 502 else{
mehatfie 2:3e7baa3e3fec 503 devices.push_back(Device::newDevice(deviceFound, lineData.word[1], lineData));
mehatfie 2:3e7baa3e3fec 504 devices.back()->name = lineData.word[1];
mehatfie 2:3e7baa3e3fec 505 }
mehatfie 1:5731f31f96be 506 }
mehatfie 1:5731f31f96be 507
mehatfie 2:3e7baa3e3fec 508 else if (lineData.word[0].compare("delay") == 0){
mehatfie 2:3e7baa3e3fec 509 string duration = lineData.word[1];
mehatfie 2:3e7baa3e3fec 510 int durationValue = 0;
mehatfie 2:3e7baa3e3fec 511 sscanf(duration.c_str(), "%d", &durationValue);
mehatfie 1:5731f31f96be 512
mehatfie 1:5731f31f96be 513 if (durationValue){
mehatfie 1:5731f31f96be 514 timer.reset();
mehatfie 1:5731f31f96be 515 timer.start();
mehatfie 1:5731f31f96be 516 while (timer.read_ms() < durationValue); //Do Nothing while the timer has not reached the duration
mehatfie 1:5731f31f96be 517 timer.stop(); //Stop the Timer
mehatfie 1:5731f31f96be 518 }
mehatfie 1:5731f31f96be 519 else{
mehatfie 1:5731f31f96be 520 //Error Out
mehatfie 1:5731f31f96be 521 return -1;
mehatfie 1:5731f31f96be 522 }
mehatfie 1:5731f31f96be 523 }
mehatfie 1:5731f31f96be 524
mehatfie 2:3e7baa3e3fec 525 else if (lineData.word[0].compare("loop") == 0){
mehatfie 2:3e7baa3e3fec 526 int checkLoopEnd = loopCommand(selectedFile, lineData);
mehatfie 1:5731f31f96be 527 if (checkLoopEnd == 1)
mehatfie 1:5731f31f96be 528 return 1;
mehatfie 1:5731f31f96be 529 }
mehatfie 5:e36e0538a903 530
mehatfie 5:e36e0538a903 531 else if (lineData.word[0].compare("condition") == 0){
mehatfie 5:e36e0538a903 532 int checkLoopEnd = conditionCommand(selectedFile, lineData);
mehatfie 5:e36e0538a903 533 if (checkLoopEnd == 1)
mehatfie 5:e36e0538a903 534 return 2;
mehatfie 5:e36e0538a903 535 }
mehatfie 5:e36e0538a903 536 // end with custom return value for specific function
mehatfie 2:3e7baa3e3fec 537 else if (lineData.word[0].compare("end") == 0){
mehatfie 2:3e7baa3e3fec 538 if (lineData.word[1].compare("program") == 0){
mehatfie 5:e36e0538a903 539 return 2;
mehatfie 2:3e7baa3e3fec 540 }
mehatfie 2:3e7baa3e3fec 541 else if (lineData.word[1].compare("loop") == 0){
mehatfie 5:e36e0538a903 542 return 3;
mehatfie 5:e36e0538a903 543 }
mehatfie 5:e36e0538a903 544 else if (lineData.word[1].compare("condition") == 0){
mehatfie 5:e36e0538a903 545 return 4;
mehatfie 2:3e7baa3e3fec 546 }
mehatfie 1:5731f31f96be 547 }
mehatfie 1:5731f31f96be 548
mehatfie 1:5731f31f96be 549 //not a keyword so check if it's a localName for a device
mehatfie 1:5731f31f96be 550 else{
mehatfie 1:5731f31f96be 551
mehatfie 1:5731f31f96be 552 int i = 0, deviceFound = -1;
mehatfie 2:3e7baa3e3fec 553 for (i = 0; i < devices.size(); i++){
mehatfie 2:3e7baa3e3fec 554 if (lineData.word[0].compare(devices[i]->name) == 0)
mehatfie 1:5731f31f96be 555 deviceFound = i;
mehatfie 1:5731f31f96be 556 }
mehatfie 1:5731f31f96be 557
mehatfie 1:5731f31f96be 558 //no device was found that matched the local name, and this is also the last error check, meaning it can match no other potential keywords
mehatfie 1:5731f31f96be 559 if (deviceFound == -1){
mehatfie 1:5731f31f96be 560 lcd.setAddress(0,3);
mehatfie 1:5731f31f96be 561 lcd.printf("Final ERROR!");
mehatfie 1:5731f31f96be 562 wait(10);
mehatfie 1:5731f31f96be 563 }
mehatfie 1:5731f31f96be 564
mehatfie 1:5731f31f96be 565 //Local Name matches a device, send line to that device in order to process the functionality
mehatfie 2:3e7baa3e3fec 566 else{
mehatfie 2:3e7baa3e3fec 567 //addDevice(deviceFound);
mehatfie 5:e36e0538a903 568 return devices[deviceFound]->interpret(lineData);
mehatfie 2:3e7baa3e3fec 569 }
mehatfie 1:5731f31f96be 570 }
mehatfie 1:5731f31f96be 571
mehatfie 1:5731f31f96be 572 return -1;
mehatfie 1:5731f31f96be 573 }
mehatfie 1:5731f31f96be 574
mehatfie 1:5731f31f96be 575
mehatfie 1:5731f31f96be 576 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 577 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 578 /****************************** <FUNCTION: main> ********************************/
mehatfie 1:5731f31f96be 579 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 580 /**********************************************************************************************************************************/
mehatfie 1:5731f31f96be 581
mehatfie 0:22618cf06f45 582 int main() {
mehatfie 0:22618cf06f45 583
mehatfie 0:22618cf06f45 584 fullInit(); //Initialize anything that's required to run the code (LCD)
mehatfie 0:22618cf06f45 585
mehatfie 5:e36e0538a903 586 struct LineData lineData;
mehatfie 2:3e7baa3e3fec 587 resetLineData(lineData);
mehatfie 2:3e7baa3e3fec 588
mehatfie 0:22618cf06f45 589 /******************************************************************************/
mehatfie 0:22618cf06f45 590 /*** <Get all the Potential Programs> ***/
mehatfie 0:22618cf06f45 591 /******************************************************************************/
mehatfie 0:22618cf06f45 592 int numTextFiles = 0;
mehatfie 2:3e7baa3e3fec 593 vector<string> textFiles; //Assuming Maximum of 25 txt files will be on the SD Card
mehatfie 2:3e7baa3e3fec 594 vector<string> filenames = readFileNames("/sd");
mehatfie 2:3e7baa3e3fec 595 numTextFiles = getFileNamesWithoutExt(textFiles, filenames);
mehatfie 0:22618cf06f45 596
mehatfie 0:22618cf06f45 597
mehatfie 0:22618cf06f45 598 /******************************************************************************/
mehatfie 0:22618cf06f45 599 /*** <Select the Program txt File> ***/
mehatfie 0:22618cf06f45 600 /******************************************************************************/
mehatfie 0:22618cf06f45 601 int fileSelected = 0, selectedFileIndex = 0;
mehatfie 0:22618cf06f45 602
mehatfie 0:22618cf06f45 603 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 604 lcd.setAddress(0,1);
mehatfie 0:22618cf06f45 605 lcd.printf("Select Your Program");
mehatfie 0:22618cf06f45 606 lcd.setAddress(0,2);
mehatfie 0:22618cf06f45 607 lcd.printf("Num Programs = %d", numTextFiles);
mehatfie 0:22618cf06f45 608
mehatfie 0:22618cf06f45 609 uint8_t lastButState;
mehatfie 0:22618cf06f45 610 lcd.setCursor(TextLCD::CurOn_BlkOn); //turn blinking cursor on
mehatfie 2:3e7baa3e3fec 611
mehatfie 0:22618cf06f45 612 selectedFileIndex = cyclePrograms(textFiles, numTextFiles, selectedFileIndex, -1); //Initialize the first file to the screen
mehatfie 0:22618cf06f45 613 while(!fileSelected) {
mehatfie 0:22618cf06f45 614
mehatfie 0:22618cf06f45 615 uint8_t curButState = buttons.readBus();
mehatfie 0:22618cf06f45 616 if(curButState != lastButState){
mehatfie 0:22618cf06f45 617 lastButState = curButState;
mehatfie 0:22618cf06f45 618 if(buttons.readRight())
mehatfie 0:22618cf06f45 619 selectedFileIndex = cyclePrograms(textFiles, numTextFiles, selectedFileIndex, 1);
mehatfie 0:22618cf06f45 620 else if(buttons.readLeft())
mehatfie 0:22618cf06f45 621 selectedFileIndex = cyclePrograms(textFiles, numTextFiles, selectedFileIndex, 0);
mehatfie 0:22618cf06f45 622 else if(buttons.readSel())
mehatfie 0:22618cf06f45 623 fileSelected = 1;
mehatfie 0:22618cf06f45 624 }
mehatfie 0:22618cf06f45 625 }
mehatfie 0:22618cf06f45 626
mehatfie 0:22618cf06f45 627 char selectedFileName[50];
mehatfie 0:22618cf06f45 628 strcpy(selectedFileName, textFiles[selectedFileIndex].c_str());
mehatfie 0:22618cf06f45 629
mehatfie 0:22618cf06f45 630 /******************************************************************************/
mehatfie 0:22618cf06f45 631 /*** <Open the Program txt File> ***/
mehatfie 0:22618cf06f45 632 /******************************************************************************/
mehatfie 0:22618cf06f45 633
mehatfie 0:22618cf06f45 634 //Create the string of the full directory and path to the program txt file
mehatfie 0:22618cf06f45 635 char selectedFileFullName[100] = "/sd/"; //Assuming that no directory and file name will be longer than 100 characters
mehatfie 0:22618cf06f45 636 strcat(selectedFileFullName, selectedFileName);
mehatfie 0:22618cf06f45 637 strcat(selectedFileFullName, ".txt");
mehatfie 0:22618cf06f45 638
mehatfie 0:22618cf06f45 639 FILE *selectedFile = fopen(selectedFileFullName, "r");
mehatfie 2:3e7baa3e3fec 640
mehatfie 0:22618cf06f45 641 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 642
mehatfie 0:22618cf06f45 643 if(selectedFile == NULL) {
mehatfie 0:22618cf06f45 644 lcd.setAddress(0,0);
mehatfie 0:22618cf06f45 645 lcd.printf("Invalid");
mehatfie 0:22618cf06f45 646 wait(10);
mehatfie 0:22618cf06f45 647 }
mehatfie 0:22618cf06f45 648
mehatfie 0:22618cf06f45 649
mehatfie 0:22618cf06f45 650 while(1){
mehatfie 0:22618cf06f45 651
mehatfie 2:3e7baa3e3fec 652 resetLineData(lineData);
mehatfie 0:22618cf06f45 653
mehatfie 0:22618cf06f45 654 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 655 lcd.setAddress(0,0);
mehatfie 0:22618cf06f45 656 lcd.printf("Program: %s", selectedFileName);
mehatfie 0:22618cf06f45 657
mehatfie 0:22618cf06f45 658
mehatfie 0:22618cf06f45 659 /******************************************************************************/
mehatfie 0:22618cf06f45 660 /*** <Start Running through the Program txt File Lines> ***/
mehatfie 0:22618cf06f45 661 /******************************************************************************/
mehatfie 0:22618cf06f45 662
mehatfie 0:22618cf06f45 663 int endOfFile = 0;
mehatfie 0:22618cf06f45 664
mehatfie 0:22618cf06f45 665 while (!endOfFile){
mehatfie 0:22618cf06f45 666
mehatfie 2:3e7baa3e3fec 667 getNextLine(selectedFile, lineData);
mehatfie 2:3e7baa3e3fec 668 int checkEnd = interpretCommand(selectedFile, lineData);
mehatfie 2:3e7baa3e3fec 669
mehatfie 1:5731f31f96be 670 if (checkEnd == 0)
mehatfie 1:5731f31f96be 671 endOfFile = 1;
mehatfie 0:22618cf06f45 672 }
mehatfie 0:22618cf06f45 673
mehatfie 0:22618cf06f45 674
mehatfie 0:22618cf06f45 675 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 676 lcd.setAddress(0,0);
mehatfie 0:22618cf06f45 677 lcd.printf("END OF PROGRAM");
mehatfie 0:22618cf06f45 678 lcd.setAddress(0,2);
mehatfie 0:22618cf06f45 679 lcd.printf("To Restart...");
mehatfie 0:22618cf06f45 680 lcd.setAddress(0,3);
mehatfie 0:22618cf06f45 681 lcd.printf("Press BACK");
mehatfie 0:22618cf06f45 682
mehatfie 0:22618cf06f45 683 while(!buttons.readBack());
mehatfie 0:22618cf06f45 684
mehatfie 0:22618cf06f45 685 lcd.setAddress(0,1);
mehatfie 2:3e7baa3e3fec 686 //rewind(selectedFile);
mehatfie 0:22618cf06f45 687 }
mehatfie 0:22618cf06f45 688
mehatfie 2:3e7baa3e3fec 689 }
mehatfie 2:3e7baa3e3fec 690
mehatfie 2:3e7baa3e3fec 691
mehatfie 2:3e7baa3e3fec 692
mehatfie 2:3e7baa3e3fec 693
mehatfie 2:3e7baa3e3fec 694
mehatfie 2:3e7baa3e3fec 695
mehatfie 2:3e7baa3e3fec 696
mehatfie 2:3e7baa3e3fec 697
mehatfie 2:3e7baa3e3fec 698
mehatfie 2:3e7baa3e3fec 699
mehatfie 2:3e7baa3e3fec 700
mehatfie 2:3e7baa3e3fec 701
mehatfie 2:3e7baa3e3fec 702
mehatfie 2:3e7baa3e3fec 703
mehatfie 2:3e7baa3e3fec 704
mehatfie 2:3e7baa3e3fec 705
mehatfie 2:3e7baa3e3fec 706
mehatfie 2:3e7baa3e3fec 707
mehatfie 2:3e7baa3e3fec 708
mehatfie 2:3e7baa3e3fec 709
mehatfie 0:22618cf06f45 710 /***** Cycle through txt lines and remember last lines ******/
mehatfie 0:22618cf06f45 711 /*
mehatfie 0:22618cf06f45 712 int running = 0, selectedFile = 0;
mehatfie 0:22618cf06f45 713 int locCount = 0, tempSpot = 0;
mehatfie 0:22618cf06f45 714 int loc[4];
mehatfie 0:22618cf06f45 715 char line[32];
mehatfie 0:22618cf06f45 716 uint8_t lastButState;
mehatfie 0:22618cf06f45 717
mehatfie 0:22618cf06f45 718
mehatfie 0:22618cf06f45 719 while(1){
mehatfie 0:22618cf06f45 720 lcd.setCursor(TextLCD::CurOn_BlkOn); //turn blinking cursor on
mehatfie 0:22618cf06f45 721 while(!running) {
mehatfie 0:22618cf06f45 722 uint8_t curButState = buttons.readBus();
mehatfie 0:22618cf06f45 723
mehatfie 0:22618cf06f45 724 if(curButState != lastButState){
mehatfie 0:22618cf06f45 725 switch(lastButState = curButState){
mehatfie 0:22618cf06f45 726 case 0x1F: //right
mehatfie 0:22618cf06f45 727
mehatfie 0:22618cf06f45 728 loc[locCount] = ftell(fp);
mehatfie 0:22618cf06f45 729
mehatfie 0:22618cf06f45 730 if (locCount >= 3)
mehatfie 0:22618cf06f45 731 locCount = 0;
mehatfie 0:22618cf06f45 732 else
mehatfie 0:22618cf06f45 733 locCount++;
mehatfie 0:22618cf06f45 734
mehatfie 0:22618cf06f45 735 //tempSpot = ftell(fp);
mehatfie 0:22618cf06f45 736 fgets(line, 32, fp);
mehatfie 0:22618cf06f45 737
mehatfie 0:22618cf06f45 738 lcd.setAddress(0,1);
mehatfie 0:22618cf06f45 739 lcd.printf("L: %s", line);
mehatfie 0:22618cf06f45 740 wait(0.2);
mehatfie 0:22618cf06f45 741 break;
mehatfie 0:22618cf06f45 742 case 0x2F: //left
mehatfie 0:22618cf06f45 743
mehatfie 0:22618cf06f45 744 if (locCount == 0) {
mehatfie 0:22618cf06f45 745 locCount = 3;
mehatfie 0:22618cf06f45 746 fseek(fp, loc[locCount], SEEK_SET);
mehatfie 0:22618cf06f45 747 }
mehatfie 0:22618cf06f45 748 else {
mehatfie 0:22618cf06f45 749 fseek(fp, loc[locCount - 1], SEEK_SET);
mehatfie 0:22618cf06f45 750 locCount--;
mehatfie 0:22618cf06f45 751 }
mehatfie 0:22618cf06f45 752 fgets(line, 32, fp);
mehatfie 0:22618cf06f45 753 lcd.setAddress(0,1);
mehatfie 0:22618cf06f45 754 lcd.printf("L: %s", line);
mehatfie 0:22618cf06f45 755 wait(0.2);
mehatfie 0:22618cf06f45 756 break;
mehatfie 0:22618cf06f45 757 }
mehatfie 0:22618cf06f45 758 }
mehatfie 0:22618cf06f45 759 }
mehatfie 0:22618cf06f45 760 }
mehatfie 0:22618cf06f45 761 */
mehatfie 2:3e7baa3e3fec 762
mehatfie 0:22618cf06f45 763
mehatfie 0:22618cf06f45 764
mehatfie 0:22618cf06f45 765 /******* Select the Program txt File ***********/
mehatfie 0:22618cf06f45 766 /*
mehatfie 0:22618cf06f45 767 int numTextFiles = 0;
mehatfie 0:22618cf06f45 768 string tempTextFiles[25]; //Assuming Maximum of 25 txt files will be on the SD Card
mehatfie 0:22618cf06f45 769 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 770 readFileNames("/sd");
mehatfie 0:22618cf06f45 771 numTextFiles = getFileNamesWithoutExt(tempTextFiles);
mehatfie 0:22618cf06f45 772
mehatfie 0:22618cf06f45 773 string *textFiles = resize_StringArr(tempTextFiles, numTextFiles); //Resize Array
mehatfie 0:22618cf06f45 774 //delete [] tempTextFiles; //free previous array
mehatfie 0:22618cf06f45 775
mehatfie 0:22618cf06f45 776
mehatfie 0:22618cf06f45 777 int running = 0, selectedFile = 0;
mehatfie 0:22618cf06f45 778
mehatfie 0:22618cf06f45 779 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 780 lcd.setAddress(0,1);
mehatfie 0:22618cf06f45 781 lcd.printf("Select Your Program");
mehatfie 0:22618cf06f45 782 lcd.setAddress(0,2);
mehatfie 0:22618cf06f45 783 lcd.printf("Num Programs = %d", numTextFiles);
mehatfie 0:22618cf06f45 784
mehatfie 0:22618cf06f45 785 uint8_t lastButState;
mehatfie 0:22618cf06f45 786 while(1){
mehatfie 0:22618cf06f45 787 lcd.setCursor(TextLCD::CurOn_BlkOn); //turn blinking cursor on
mehatfie 0:22618cf06f45 788 while(!running) {
mehatfie 0:22618cf06f45 789 uint8_t curButState = buttons.readBus();
mehatfie 0:22618cf06f45 790
mehatfie 0:22618cf06f45 791 if(curButState != lastButState){
mehatfie 0:22618cf06f45 792 switch(lastButState = curButState){
mehatfie 0:22618cf06f45 793 case 0x1F: //right
mehatfie 0:22618cf06f45 794 selectedFile = cyclePrograms(textFiles, numTextFiles, selectedFile, 1);
mehatfie 0:22618cf06f45 795 break;
mehatfie 0:22618cf06f45 796 case 0x2F: //left
mehatfie 0:22618cf06f45 797 selectedFile = cyclePrograms(textFiles, numTextFiles, selectedFile, 0);
mehatfie 0:22618cf06f45 798 break;
mehatfie 0:22618cf06f45 799 }
mehatfie 0:22618cf06f45 800 }
mehatfie 0:22618cf06f45 801 }
mehatfie 0:22618cf06f45 802 }
mehatfie 0:22618cf06f45 803
mehatfie 0:22618cf06f45 804 */
mehatfie 0:22618cf06f45 805
mehatfie 0:22618cf06f45 806 /*float speed = 0.5;
mehatfie 0:22618cf06f45 807 while(1){
mehatfie 0:22618cf06f45 808 bridges.drive(1, -1*speed);
mehatfie 0:22618cf06f45 809 wait(2);
mehatfie 0:22618cf06f45 810 bridges.drive(1, speed);
mehatfie 0:22618cf06f45 811 wait(2);
mehatfie 0:22618cf06f45 812 }*/
mehatfie 0:22618cf06f45 813
mehatfie 0:22618cf06f45 814 //BridgeDriver::MOTOR_A