Generation 3 of the Harp project

Dependencies:   Servo TMP36 GZ buffered-serial1 chan_fatfs_sd nmea_parser watchdog mbed-rtos mbed

Fork of HARP2 by Tyler Weaver

main.cpp

Committer:
tylerjw
Date:
2012-12-07
Revision:
8:13360ec824a7
Parent:
7:d8ecabe16c9e
Child:
9:4debfbc1fb3e

File content as of revision 8:13360ec824a7:

#include "mbed.h"
#include "rtos.h"

#include "MODSERIAL.h"

Serial pc(USBTX, USBRX);

float test_lat =  39.943039;
float test_long = -104.978226;

// Connect the TX of the GPS module to p10 RX input
MODSERIAL gps(NC, p14);

DigitalOut irq_led(LED1);

bool newline_detected = false;
Semaphore newlines(0);

// Called everytime a new character goes into
// the RX buffer. Test that character for \n
// Note, rxGetLastChar() gets the last char that
// we received but it does NOT remove it from
// the RX buffer.
void rxCallback(MODSERIAL_IRQ_INFO *q)
{
    newline_detected = true;
    //newlines++;
    newlines.release();
    irq_led = !irq_led;
}

void gps_thread(void const *args)
{
    char buffer[512];
    Timer t;
    t.start();
    float start;
    int number_lines = 0;
    float average_wait = 0.0;
    float wait[10];

    gps.baud(4800);
    pc.baud(9600);
    gps.autoDetectChar('\n');
    gps.attach(&rxCallback, MODSERIAL::RxAutoDetect);

    while(true) {
        // Wait here until we detect the \n going into the buffer.
        //if(newlines == 0)
            //pc.puts("Waiting... \r\n");
        //while (!newline_detected) ; // 100ms wait
        newlines.wait(); // wait for next line
        //pc.printf("%f\r\n",t.read());
        //if(newlines > 1)
            //pc.printf("Lines in buffer: %d\r\n",newlines);
        // When we get here the RX buffer now contains a NMEA sentence.
        // ...
        memset(buffer, 0, 512);
        gps.move(buffer, 512);
        pc.puts(buffer);
        //newlines--;
    }

}


int main()
{
    Thread thread(gps_thread, NULL, osPriorityRealtime);
    
    while(true);
}