SDFileSystem, slightly modified for the ExoController

Dependencies:   SDFileSystem

Dependents:   Data-Management-Honka

Fork of SDFileSystem_HelloWorld by Bradley Perry

Revision:
9:5bad923e18ce
Parent:
8:964f832265b8
Child:
10:23a3c0102ab0
--- a/SDFile.cpp	Wed Mar 11 19:39:20 2015 +0000
+++ b/SDFile.cpp	Fri Apr 24 19:32:53 2015 +0000
@@ -39,10 +39,15 @@
 {
    
     //shift to the end of the file and go back accounting for the commas, spaces, \n, and \r (6 places per data)
-    fseek(_fp, -6*length, SEEK_END);
+    int s = fseek(_fp, -6*length, SEEK_END);
+    
+    //pc.printf("reading to array at %d\r\n", &array[0]);
     //cycle through the length of the vector and read the values.
     for(int i = 0; i < length; i++) {
-        fscanf(_fp, "%x, ", &array[i]);
+        pc.printf("File %d, array %d\r\n", _fp, &array[i]);
+        s= fscanf(_fp, "%x, ", &array[i]);
+      //  pc.printf("HHHHH\r\n", s);
+        //pc.printf("read %x now at %ld\r\n", array[i], ftell(_fp));
     }
    
     return array;
@@ -70,13 +75,30 @@
     fseek(_fp, 0, SEEK_SET);
 //    printf("Writing %d\r\n", array[0]);
     //printf("Starting to write\r\n");
+    int w;
     for(int i = 0; i < length-1; i++) {
         /* This line fails when run on testFile, reason unknown...*/
         //printf("%d\r\n", fprintf(_fp, "%04x, ", array[i]));
-        fprintf(_fp, "%04x, ", array[i]);
+        pc.printf("Writing at %ld\r\n", ftell(_fp));
+        w = fprintf(_fp, "%04x, ", array[i]);
+        pc.printf("Wrote %d, now at %ld\r\n", w, ftell(_fp));
     }
     //printf("%d\r\n", fprintf(_fp, "%04x\r\n", array[length-1]));
     fprintf(_fp, "%04x\r\n", array[length-1]);
+    fflush(_fp);
+}
+
+void SDFile::write_to_index(int index, int value)
+{
+     fseek(_fp, 6*index, SEEK_SET);
+    //pc.printf("Index %d, position %ld\r\n", 6*index, ftell(_fp));
+    //fscanf(_fp, "%x, ", &val);
+    //pc.printf("Val is %x\r\n", val);
+    //pc.printf("%d, %d\r\n", sizeof value, sizeof 0xdead);
+    //pc.printf("%04x, ", value);
+    int w = fprintf(_fp, "%04x, ", value & 0xffff); 
+    //pc.printf("Wrote %d, now at %ld\r\n", w, ftell(_fp));
+    fflush(_fp);
 }
 
 void SDFile::append(int length, int *array) {