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 16 15:28:59 2014 +0000
Revision:
0:22618cf06f45
Child:
1:5731f31f96be
- Initial Commit; - Code is a mess (in mid transition of general code architecture); - Functionality work to drive motors in both direction and turn off; - Delay functionality working; - Able to read a program from a txt file and perform functionality

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 "DeviceClasses.h"
mehatfie 0:22618cf06f45 10 #include "Device.hpp"
mehatfie 0:22618cf06f45 11 //#include "Motor.hpp"
mehatfie 0:22618cf06f45 12 //#include "VoltageDriver.hpp"
mehatfie 0:22618cf06f45 13 #include "TextFile.h"
mehatfie 0:22618cf06f45 14 #include <stdio.h>
mehatfie 0:22618cf06f45 15 #include <string>
mehatfie 0:22618cf06f45 16 #include <stdlib.h>
mehatfie 0:22618cf06f45 17 #include <iostream>
mehatfie 0:22618cf06f45 18 #include <fstream>
mehatfie 0:22618cf06f45 19 #include <vector>
mehatfie 0:22618cf06f45 20 using std::string;
mehatfie 0:22618cf06f45 21
mehatfie 0:22618cf06f45 22 //const int MAX_LINE_LENGTH = 100;
mehatfie 0:22618cf06f45 23 struct Line lineData;
mehatfie 0:22618cf06f45 24 //Device devices[15];
mehatfie 0:22618cf06f45 25 DeviceData devices[15];
mehatfie 0:22618cf06f45 26
mehatfie 0:22618cf06f45 27 //extern "C" void mbed_reset(); //enable software reset of code
mehatfie 0:22618cf06f45 28 /*
mehatfie 0:22618cf06f45 29 http://stackoverflow.com/questions/3081289/how-to-read-a-line-from-a-text-file-in-c-c
mehatfie 0:22618cf06f45 30 http://stackoverflow.com/questions/12475915/rewind-stream-pointer-to-the-line-back
mehatfie 0:22618cf06f45 31
mehatfie 0:22618cf06f45 32 recurrsive
mehatfie 0:22618cf06f45 33 */
mehatfie 0:22618cf06f45 34
mehatfie 0:22618cf06f45 35 void resetLineData(){
mehatfie 0:22618cf06f45 36
mehatfie 0:22618cf06f45 37 lineData.fullLine = NULL;
mehatfie 0:22618cf06f45 38 lineData.lineNumber = 0;
mehatfie 0:22618cf06f45 39 lineData.numWords = 0;
mehatfie 0:22618cf06f45 40 }
mehatfie 0:22618cf06f45 41
mehatfie 0:22618cf06f45 42 FrontPanelButtons buttons(&i2c);
mehatfie 0:22618cf06f45 43
mehatfie 0:22618cf06f45 44
mehatfie 0:22618cf06f45 45 /*
mehatfie 0:22618cf06f45 46 Make LOOP function
mehatfie 0:22618cf06f45 47 - All you need to do is remember (val = ftell(fp)) the beginning of the line you're currently reading.
mehatfie 0:22618cf06f45 48 - If it turns out to be a LOOP call, then you simply send that remembered value to the LOOP function, and it will continue to LOOP back to that position until the condition is met.
mehatfie 0:22618cf06f45 49
mehatfie 0:22618cf06f45 50
mehatfie 0:22618cf06f45 51 func LOOP (FILE *fp, int loopStart){
mehatfie 0:22618cf06f45 52
mehatfie 0:22618cf06f45 53 string conditions;
mehatfie 0:22618cf06f45 54 fseek(fp, loopStart, SEEK_SET);
mehatfie 0:22618cf06f45 55 fgets(conditions, MAX_LINE_LENGTH, fp);
mehatfie 0:22618cf06f45 56
mehatfie 0:22618cf06f45 57 int numCycles = interpretLoopCondtions();
mehatfie 0:22618cf06f45 58
mehatfie 0:22618cf06f45 59 int i = 0;
mehatfie 0:22618cf06f45 60 int checkEndLoop = 0;
mehatfie 0:22618cf06f45 61 while (i < numCycles) {
mehatfie 0:22618cf06f45 62
mehatfie 0:22618cf06f45 63 checkEndLoop = interpretLine(fp); //if end Loop return ____ (1?), return 0 on success
mehatfie 0:22618cf06f45 64 if (checkEndLoop) //if it's not the end of the loop, the counter will not increase and we'll just interpret the next line
mehatfie 0:22618cf06f45 65 i++;
mehatfie 0:22618cf06f45 66 }
mehatfie 0:22618cf06f45 67 } //loop conditions met, return to main code
mehatfie 0:22618cf06f45 68
mehatfie 0:22618cf06f45 69
mehatfie 0:22618cf06f45 70 */
mehatfie 0:22618cf06f45 71
mehatfie 0:22618cf06f45 72
mehatfie 0:22618cf06f45 73
mehatfie 0:22618cf06f45 74 int cyclePrograms(string files[], int SIZE, int currIndex, int direction){
mehatfie 0:22618cf06f45 75
mehatfie 0:22618cf06f45 76 int nextIndex = 0;
mehatfie 0:22618cf06f45 77 switch(direction){
mehatfie 0:22618cf06f45 78 case 0: //Cycle Back one File
mehatfie 0:22618cf06f45 79 if ((currIndex - 1) < 0)
mehatfie 0:22618cf06f45 80 nextIndex = SIZE - 1;
mehatfie 0:22618cf06f45 81 else
mehatfie 0:22618cf06f45 82 nextIndex = currIndex - 1;
mehatfie 0:22618cf06f45 83 break;
mehatfie 0:22618cf06f45 84 case 1: //Cycle Forward one File
mehatfie 0:22618cf06f45 85 if ((currIndex + 1) >= SIZE)
mehatfie 0:22618cf06f45 86 nextIndex = 0;
mehatfie 0:22618cf06f45 87 else
mehatfie 0:22618cf06f45 88 nextIndex = currIndex + 1;
mehatfie 0:22618cf06f45 89 break;
mehatfie 0:22618cf06f45 90 case -1: //set the selectedFile to the currIndex (used for initialization)
mehatfie 0:22618cf06f45 91 nextIndex = currIndex;
mehatfie 0:22618cf06f45 92 break;
mehatfie 0:22618cf06f45 93 }
mehatfie 0:22618cf06f45 94
mehatfie 0:22618cf06f45 95 //Output file on Display
mehatfie 0:22618cf06f45 96 lcd.setAddress(0,3);
mehatfie 0:22618cf06f45 97 lcd.printf(" "); // Clear the Line using Spaces (Emptyness) - Note one line is 20 Characters
mehatfie 0:22618cf06f45 98 wait(.2);
mehatfie 0:22618cf06f45 99 lcd.setAddress(0,3);
mehatfie 0:22618cf06f45 100 lcd.printf("%s",files[nextIndex]);
mehatfie 0:22618cf06f45 101
mehatfie 0:22618cf06f45 102 return nextIndex; // Return the file index in the Array
mehatfie 0:22618cf06f45 103 }
mehatfie 0:22618cf06f45 104
mehatfie 0:22618cf06f45 105
mehatfie 0:22618cf06f45 106 string* resize_StringArr(string oldArr[], int newSize) {
mehatfie 0:22618cf06f45 107
mehatfie 0:22618cf06f45 108 string newArr[newSize];
mehatfie 0:22618cf06f45 109 memcpy(newArr, oldArr, newSize * sizeof(string));
mehatfie 0:22618cf06f45 110
mehatfie 0:22618cf06f45 111 return newArr;
mehatfie 0:22618cf06f45 112 }
mehatfie 0:22618cf06f45 113
mehatfie 0:22618cf06f45 114
mehatfie 0:22618cf06f45 115 int main() {
mehatfie 0:22618cf06f45 116
mehatfie 0:22618cf06f45 117 fullInit(); //Initialize anything that's required to run the code (LCD)
mehatfie 0:22618cf06f45 118
mehatfie 0:22618cf06f45 119 /******************************************************************************/
mehatfie 0:22618cf06f45 120 /*** <Get all the Potential Programs> ***/
mehatfie 0:22618cf06f45 121 /******************************************************************************/
mehatfie 0:22618cf06f45 122 int numTextFiles = 0;
mehatfie 0:22618cf06f45 123 string tempTextFiles[25]; //Assuming Maximum of 25 txt files will be on the SD Card
mehatfie 0:22618cf06f45 124 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 125
mehatfie 0:22618cf06f45 126 vector<string> filenames = readFileNames("/sd");
mehatfie 0:22618cf06f45 127 numTextFiles = getFileNamesWithoutExt(tempTextFiles, filenames);
mehatfie 0:22618cf06f45 128 string *textFiles = resize_StringArr(tempTextFiles, numTextFiles); //Resize Array
mehatfie 0:22618cf06f45 129
mehatfie 0:22618cf06f45 130 //delete [] tempTextFiles; //free previous array
mehatfie 0:22618cf06f45 131
mehatfie 0:22618cf06f45 132
mehatfie 0:22618cf06f45 133 /******************************************************************************/
mehatfie 0:22618cf06f45 134 /*** <Select the Program txt File> ***/
mehatfie 0:22618cf06f45 135 /******************************************************************************/
mehatfie 0:22618cf06f45 136 int fileSelected = 0, selectedFileIndex = 0;
mehatfie 0:22618cf06f45 137
mehatfie 0:22618cf06f45 138 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 139 lcd.setAddress(0,1);
mehatfie 0:22618cf06f45 140 lcd.printf("Select Your Program");
mehatfie 0:22618cf06f45 141 lcd.setAddress(0,2);
mehatfie 0:22618cf06f45 142 lcd.printf("Num Programs = %d", numTextFiles);
mehatfie 0:22618cf06f45 143
mehatfie 0:22618cf06f45 144 uint8_t lastButState;
mehatfie 0:22618cf06f45 145 lcd.setCursor(TextLCD::CurOn_BlkOn); //turn blinking cursor on
mehatfie 0:22618cf06f45 146
mehatfie 0:22618cf06f45 147 selectedFileIndex = cyclePrograms(textFiles, numTextFiles, selectedFileIndex, -1); //Initialize the first file to the screen
mehatfie 0:22618cf06f45 148 while(!fileSelected) {
mehatfie 0:22618cf06f45 149
mehatfie 0:22618cf06f45 150 uint8_t curButState = buttons.readBus();
mehatfie 0:22618cf06f45 151 if(curButState != lastButState){
mehatfie 0:22618cf06f45 152 lastButState = curButState;
mehatfie 0:22618cf06f45 153 if(buttons.readRight())
mehatfie 0:22618cf06f45 154 selectedFileIndex = cyclePrograms(textFiles, numTextFiles, selectedFileIndex, 1);
mehatfie 0:22618cf06f45 155 else if(buttons.readLeft())
mehatfie 0:22618cf06f45 156 selectedFileIndex = cyclePrograms(textFiles, numTextFiles, selectedFileIndex, 0);
mehatfie 0:22618cf06f45 157 else if(buttons.readSel())
mehatfie 0:22618cf06f45 158 fileSelected = 1;
mehatfie 0:22618cf06f45 159 }
mehatfie 0:22618cf06f45 160 }
mehatfie 0:22618cf06f45 161
mehatfie 0:22618cf06f45 162 char selectedFileName[50];
mehatfie 0:22618cf06f45 163 strcpy(selectedFileName, textFiles[selectedFileIndex].c_str());
mehatfie 0:22618cf06f45 164
mehatfie 0:22618cf06f45 165 /******************************************************************************/
mehatfie 0:22618cf06f45 166 /*** <Open the Program txt File> ***/
mehatfie 0:22618cf06f45 167 /******************************************************************************/
mehatfie 0:22618cf06f45 168
mehatfie 0:22618cf06f45 169 //Create the string of the full directory and path to the program txt file
mehatfie 0:22618cf06f45 170 char selectedFileFullName[100] = "/sd/"; //Assuming that no directory and file name will be longer than 100 characters
mehatfie 0:22618cf06f45 171 strcat(selectedFileFullName, selectedFileName);
mehatfie 0:22618cf06f45 172 strcat(selectedFileFullName, ".txt");
mehatfie 0:22618cf06f45 173
mehatfie 0:22618cf06f45 174 FILE *selectedFile = fopen(selectedFileFullName, "r");
mehatfie 0:22618cf06f45 175 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 176
mehatfie 0:22618cf06f45 177 if(selectedFile == NULL) {
mehatfie 0:22618cf06f45 178 lcd.setAddress(0,0);
mehatfie 0:22618cf06f45 179 lcd.printf("Invalid");
mehatfie 0:22618cf06f45 180 wait(10);
mehatfie 0:22618cf06f45 181 }
mehatfie 0:22618cf06f45 182
mehatfie 0:22618cf06f45 183
mehatfie 0:22618cf06f45 184 while(1){
mehatfie 0:22618cf06f45 185
mehatfie 0:22618cf06f45 186 resetLineData();
mehatfie 0:22618cf06f45 187
mehatfie 0:22618cf06f45 188 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 189 lcd.setAddress(0,0);
mehatfie 0:22618cf06f45 190 lcd.printf("Program: %s", selectedFileName);
mehatfie 0:22618cf06f45 191
mehatfie 0:22618cf06f45 192
mehatfie 0:22618cf06f45 193 /******************************************************************************/
mehatfie 0:22618cf06f45 194 /*** <Start Running through the Program txt File Lines> ***/
mehatfie 0:22618cf06f45 195 /******************************************************************************/
mehatfie 0:22618cf06f45 196
mehatfie 0:22618cf06f45 197 int endOfFile = 0;
mehatfie 0:22618cf06f45 198
mehatfie 0:22618cf06f45 199 while (!endOfFile){
mehatfie 0:22618cf06f45 200
mehatfie 0:22618cf06f45 201 getNextLine(selectedFile);
mehatfie 0:22618cf06f45 202
mehatfie 0:22618cf06f45 203 if (strncmp(lineData.word[0],"device", 6) == 0){
mehatfie 0:22618cf06f45 204
mehatfie 0:22618cf06f45 205 int i = 0, deviceFound = -1;
mehatfie 0:22618cf06f45 206 for (i = 0; i < numDevices; i++)
mehatfie 0:22618cf06f45 207 if (strncmp(lineData.word[2], DeviceNames[i], strlen(DeviceNames[i])) == 0)
mehatfie 0:22618cf06f45 208 deviceFound = i;
mehatfie 0:22618cf06f45 209
mehatfie 0:22618cf06f45 210 //if the device type does not match any known type, error out
mehatfie 0:22618cf06f45 211 if (deviceFound == -1){
mehatfie 0:22618cf06f45 212 //Error Out since the device Name was not matched with anything *************************
mehatfie 0:22618cf06f45 213 }
mehatfie 0:22618cf06f45 214
mehatfie 0:22618cf06f45 215 //Add device to the array of devices and initialize it
mehatfie 0:22618cf06f45 216 else
mehatfie 0:22618cf06f45 217 addDevice(deviceFound);
mehatfie 0:22618cf06f45 218 }
mehatfie 0:22618cf06f45 219
mehatfie 0:22618cf06f45 220 else if (strncmp(lineData.word[0],"delay", 5) == 0){
mehatfie 0:22618cf06f45 221 char *duration = lineData.word[1];
mehatfie 0:22618cf06f45 222 int durationValue = atoi(duration);
mehatfie 0:22618cf06f45 223
mehatfie 0:22618cf06f45 224 if (durationValue){
mehatfie 0:22618cf06f45 225 timer.reset();
mehatfie 0:22618cf06f45 226 timer.start();
mehatfie 0:22618cf06f45 227 while (timer.read_ms() < durationValue); //Do Nothing while the timer has not reached the duration
mehatfie 0:22618cf06f45 228 timer.stop(); //Stop the Timer
mehatfie 0:22618cf06f45 229 }
mehatfie 0:22618cf06f45 230 else{
mehatfie 0:22618cf06f45 231 //Error Out
mehatfie 0:22618cf06f45 232 }
mehatfie 0:22618cf06f45 233 }
mehatfie 0:22618cf06f45 234
mehatfie 0:22618cf06f45 235 else if (strncmp(lineData.word[0],"loop", 4) == 0){
mehatfie 0:22618cf06f45 236 //Do something for looping
mehatfie 0:22618cf06f45 237 }
mehatfie 0:22618cf06f45 238
mehatfie 0:22618cf06f45 239 else if (strncmp(lineData.word[0],"end", 3) == 0){
mehatfie 0:22618cf06f45 240 if (strncmp(lineData.word[1],"program", 7) == 0)
mehatfie 0:22618cf06f45 241 endOfFile = 1;
mehatfie 0:22618cf06f45 242 }
mehatfie 0:22618cf06f45 243
mehatfie 0:22618cf06f45 244 //not a keyword so check if it's a localName for a device
mehatfie 0:22618cf06f45 245 else{
mehatfie 0:22618cf06f45 246
mehatfie 0:22618cf06f45 247 int i = 0, deviceFound = -1;
mehatfie 0:22618cf06f45 248 for (i = 0; i < currNumDevices; i++){
mehatfie 0:22618cf06f45 249 if (strncmp(lineData.word[0], devices[i].name, strlen(devices[i].name)) == 0)
mehatfie 0:22618cf06f45 250 deviceFound = i;
mehatfie 0:22618cf06f45 251 }
mehatfie 0:22618cf06f45 252
mehatfie 0:22618cf06f45 253 //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 0:22618cf06f45 254 if (deviceFound == -1){
mehatfie 0:22618cf06f45 255 lcd.setAddress(0,3);
mehatfie 0:22618cf06f45 256 lcd.printf("Final ERROR!");
mehatfie 0:22618cf06f45 257 wait(10);
mehatfie 0:22618cf06f45 258 }
mehatfie 0:22618cf06f45 259
mehatfie 0:22618cf06f45 260 //Local Name matches a device, send line to that device in order to process the functionality
mehatfie 0:22618cf06f45 261 else
mehatfie 0:22618cf06f45 262 addDevice(deviceFound);//devices[deviceFound].interpret();
mehatfie 0:22618cf06f45 263 }
mehatfie 0:22618cf06f45 264 }
mehatfie 0:22618cf06f45 265
mehatfie 0:22618cf06f45 266
mehatfie 0:22618cf06f45 267 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 268 lcd.setAddress(0,0);
mehatfie 0:22618cf06f45 269 lcd.printf("END OF PROGRAM");
mehatfie 0:22618cf06f45 270 lcd.setAddress(0,2);
mehatfie 0:22618cf06f45 271 lcd.printf("To Restart...");
mehatfie 0:22618cf06f45 272 lcd.setAddress(0,3);
mehatfie 0:22618cf06f45 273 lcd.printf("Press BACK");
mehatfie 0:22618cf06f45 274
mehatfie 0:22618cf06f45 275 while(!buttons.readBack());
mehatfie 0:22618cf06f45 276
mehatfie 0:22618cf06f45 277 lcd.setAddress(0,1);
mehatfie 0:22618cf06f45 278 rewind(selectedFile);
mehatfie 0:22618cf06f45 279 }
mehatfie 0:22618cf06f45 280
mehatfie 0:22618cf06f45 281
mehatfie 0:22618cf06f45 282 /***** Cycle through txt lines and remember last lines ******/
mehatfie 0:22618cf06f45 283 /*
mehatfie 0:22618cf06f45 284 int running = 0, selectedFile = 0;
mehatfie 0:22618cf06f45 285 int locCount = 0, tempSpot = 0;
mehatfie 0:22618cf06f45 286 int loc[4];
mehatfie 0:22618cf06f45 287 char line[32];
mehatfie 0:22618cf06f45 288 uint8_t lastButState;
mehatfie 0:22618cf06f45 289
mehatfie 0:22618cf06f45 290
mehatfie 0:22618cf06f45 291 while(1){
mehatfie 0:22618cf06f45 292 lcd.setCursor(TextLCD::CurOn_BlkOn); //turn blinking cursor on
mehatfie 0:22618cf06f45 293 while(!running) {
mehatfie 0:22618cf06f45 294 uint8_t curButState = buttons.readBus();
mehatfie 0:22618cf06f45 295
mehatfie 0:22618cf06f45 296 if(curButState != lastButState){
mehatfie 0:22618cf06f45 297 switch(lastButState = curButState){
mehatfie 0:22618cf06f45 298 case 0x1F: //right
mehatfie 0:22618cf06f45 299
mehatfie 0:22618cf06f45 300 loc[locCount] = ftell(fp);
mehatfie 0:22618cf06f45 301
mehatfie 0:22618cf06f45 302 if (locCount >= 3)
mehatfie 0:22618cf06f45 303 locCount = 0;
mehatfie 0:22618cf06f45 304 else
mehatfie 0:22618cf06f45 305 locCount++;
mehatfie 0:22618cf06f45 306
mehatfie 0:22618cf06f45 307 //tempSpot = ftell(fp);
mehatfie 0:22618cf06f45 308 fgets(line, 32, fp);
mehatfie 0:22618cf06f45 309
mehatfie 0:22618cf06f45 310 lcd.setAddress(0,1);
mehatfie 0:22618cf06f45 311 lcd.printf("L: %s", line);
mehatfie 0:22618cf06f45 312 wait(0.2);
mehatfie 0:22618cf06f45 313 break;
mehatfie 0:22618cf06f45 314 case 0x2F: //left
mehatfie 0:22618cf06f45 315
mehatfie 0:22618cf06f45 316 if (locCount == 0) {
mehatfie 0:22618cf06f45 317 locCount = 3;
mehatfie 0:22618cf06f45 318 fseek(fp, loc[locCount], SEEK_SET);
mehatfie 0:22618cf06f45 319 }
mehatfie 0:22618cf06f45 320 else {
mehatfie 0:22618cf06f45 321 fseek(fp, loc[locCount - 1], SEEK_SET);
mehatfie 0:22618cf06f45 322 locCount--;
mehatfie 0:22618cf06f45 323 }
mehatfie 0:22618cf06f45 324 fgets(line, 32, fp);
mehatfie 0:22618cf06f45 325 lcd.setAddress(0,1);
mehatfie 0:22618cf06f45 326 lcd.printf("L: %s", line);
mehatfie 0:22618cf06f45 327 wait(0.2);
mehatfie 0:22618cf06f45 328 break;
mehatfie 0:22618cf06f45 329 }
mehatfie 0:22618cf06f45 330 }
mehatfie 0:22618cf06f45 331 }
mehatfie 0:22618cf06f45 332 }
mehatfie 0:22618cf06f45 333 */
mehatfie 0:22618cf06f45 334
mehatfie 0:22618cf06f45 335
mehatfie 0:22618cf06f45 336
mehatfie 0:22618cf06f45 337
mehatfie 0:22618cf06f45 338
mehatfie 0:22618cf06f45 339 /******* Select the Program txt File ***********/
mehatfie 0:22618cf06f45 340 /*
mehatfie 0:22618cf06f45 341 int numTextFiles = 0;
mehatfie 0:22618cf06f45 342 string tempTextFiles[25]; //Assuming Maximum of 25 txt files will be on the SD Card
mehatfie 0:22618cf06f45 343 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 344 readFileNames("/sd");
mehatfie 0:22618cf06f45 345 numTextFiles = getFileNamesWithoutExt(tempTextFiles);
mehatfie 0:22618cf06f45 346
mehatfie 0:22618cf06f45 347 string *textFiles = resize_StringArr(tempTextFiles, numTextFiles); //Resize Array
mehatfie 0:22618cf06f45 348 //delete [] tempTextFiles; //free previous array
mehatfie 0:22618cf06f45 349
mehatfie 0:22618cf06f45 350
mehatfie 0:22618cf06f45 351 int running = 0, selectedFile = 0;
mehatfie 0:22618cf06f45 352
mehatfie 0:22618cf06f45 353 lcd.cls(); //clear the display
mehatfie 0:22618cf06f45 354 lcd.setAddress(0,1);
mehatfie 0:22618cf06f45 355 lcd.printf("Select Your Program");
mehatfie 0:22618cf06f45 356 lcd.setAddress(0,2);
mehatfie 0:22618cf06f45 357 lcd.printf("Num Programs = %d", numTextFiles);
mehatfie 0:22618cf06f45 358
mehatfie 0:22618cf06f45 359 uint8_t lastButState;
mehatfie 0:22618cf06f45 360 while(1){
mehatfie 0:22618cf06f45 361 lcd.setCursor(TextLCD::CurOn_BlkOn); //turn blinking cursor on
mehatfie 0:22618cf06f45 362 while(!running) {
mehatfie 0:22618cf06f45 363 uint8_t curButState = buttons.readBus();
mehatfie 0:22618cf06f45 364
mehatfie 0:22618cf06f45 365 if(curButState != lastButState){
mehatfie 0:22618cf06f45 366 switch(lastButState = curButState){
mehatfie 0:22618cf06f45 367 case 0x1F: //right
mehatfie 0:22618cf06f45 368 selectedFile = cyclePrograms(textFiles, numTextFiles, selectedFile, 1);
mehatfie 0:22618cf06f45 369 break;
mehatfie 0:22618cf06f45 370 case 0x2F: //left
mehatfie 0:22618cf06f45 371 selectedFile = cyclePrograms(textFiles, numTextFiles, selectedFile, 0);
mehatfie 0:22618cf06f45 372 break;
mehatfie 0:22618cf06f45 373 }
mehatfie 0:22618cf06f45 374 }
mehatfie 0:22618cf06f45 375 }
mehatfie 0:22618cf06f45 376 }
mehatfie 0:22618cf06f45 377
mehatfie 0:22618cf06f45 378 */
mehatfie 0:22618cf06f45 379
mehatfie 0:22618cf06f45 380
mehatfie 0:22618cf06f45 381
mehatfie 0:22618cf06f45 382
mehatfie 0:22618cf06f45 383 }
mehatfie 0:22618cf06f45 384
mehatfie 0:22618cf06f45 385
mehatfie 0:22618cf06f45 386
mehatfie 0:22618cf06f45 387
mehatfie 0:22618cf06f45 388
mehatfie 0:22618cf06f45 389
mehatfie 0:22618cf06f45 390
mehatfie 0:22618cf06f45 391
mehatfie 0:22618cf06f45 392
mehatfie 0:22618cf06f45 393 /*float speed = 0.5;
mehatfie 0:22618cf06f45 394 while(1){
mehatfie 0:22618cf06f45 395 bridges.drive(1, -1*speed);
mehatfie 0:22618cf06f45 396 wait(2);
mehatfie 0:22618cf06f45 397 bridges.drive(1, speed);
mehatfie 0:22618cf06f45 398 wait(2);
mehatfie 0:22618cf06f45 399 }*/
mehatfie 0:22618cf06f45 400
mehatfie 0:22618cf06f45 401 //BridgeDriver::MOTOR_A