Flying Sea Glider / Mbed 2 deprecated 2019_13sep_jcw_nosd

Dependencies:   mbed MODSERIAL FATFileSystem

Revision:
9:d5fcdcb3c89d
diff -r 70412939a506 -r d5fcdcb3c89d Course/Course.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Course/Course.cpp	Fri Oct 20 11:41:22 2017 +0000
@@ -0,0 +1,90 @@
+#include "Course.hpp"
+#include "StaticDefs.hpp"
+
+Course::Course()
+{
+    counter = 0;
+    getFromFile();
+    //eventually want to grab everything from the file
+}
+
+int Course::increment()
+{
+    counter++;
+    return counter;
+}
+
+int Course::decrement()
+{
+    counter--;
+    return counter;
+}
+
+int Course::jumpto(int jump)
+{
+    if (jump > total_legs) {
+        jump = total_legs-1;
+    }
+    counter = jump;
+    return counter;
+}
+
+float Course::readDepth()
+{
+    return course[counter].depth;
+}
+
+float Course::readThrottle()
+{
+    return course[counter].throttle;
+}
+
+float Course::readHeading()
+{
+    return course[counter].heading;
+}
+
+float Course::readTime()
+{
+    return course[counter].time;
+}
+
+int Course::readFinal()
+{
+    return course[counter].final;
+}
+
+int Course::readTotalLegs()
+{
+    return total_legs;
+}
+
+bool Course::getFromFile()
+{
+    ;//open file and read the stuff
+    FILE *fp = fopen("/local/course.txt", "r");
+
+    char line[MAXLINEWIDTH];
+
+    while ( fgets( line, sizeof line, fp ) != NULL ) { /* read a line */
+        if (( sscanf(line,"%f %f %f %f %i",&course[counter].depth, &course[counter].throttle, &course[counter].heading, &course[counter].time, &course[counter].final)) == 5) {
+            counter++;
+        }
+    }
+    total_legs = counter;
+    counter--; //rewind 1 click
+    fclose(fp); //close the file
+    
+    if (course[counter].final) {
+        counter = 0; //rewind everything
+        return true;
+    } else {
+        // something was fubared along the way
+        return false;
+    }
+
+    //returned = fscanf(pfile, "%f %f %f %f %i", &d, &s, &h, &t, &last) ;
+    //pc().printf("\n\r%f %f %f %f %i %i\n\r",d,s,h,t,last,returned);
+    //fclose(pfile);
+
+}