Flying Sea Glider / Mbed 2 deprecated 2019_13sep_jcw_nosd

Dependencies:   mbed MODSERIAL FATFileSystem

Course/Course.cpp

Committer:
mkelly10
Date:
2017-10-20
Revision:
9:d5fcdcb3c89d

File content as of revision 9:d5fcdcb3c89d:

#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);

}