Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MODSERIAL FATFileSystem
Diff: Course/Course.cpp
- 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);
+
+}