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 Sep 24 01:46:02 2014 +0000
Revision:
8:e9f836163229
Parent:
7:cca801103b86
Child:
9:5a0c4c6e39c7
- all debugging and error checking (to ensure the function works in all cases.... not to tell the user about errors) for conditionCommand should be completed for any forseen combinations required for conditional statements

Who changed what in which revision?

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