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

Revision:
8:13360ec824a7
Parent:
7:d8ecabe16c9e
Child:
9:4debfbc1fb3e
--- a/main.cpp	Fri Dec 07 19:19:00 2012 +0000
+++ b/main.cpp	Fri Dec 07 20:42:48 2012 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
 #include "rtos.h"
+
 #include "MODSERIAL.h"
 
 Serial pc(USBTX, USBRX);
@@ -13,6 +14,7 @@
 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
@@ -22,12 +24,20 @@
 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);
@@ -36,13 +46,19 @@
 
     while(true) {
         // Wait here until we detect the \n going into the buffer.
-        while (! newline_detected ) ;
-
+        //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--;
     }
 
 }
@@ -50,7 +66,7 @@
 
 int main()
 {
-    Thread thread(gps_thread);
+    Thread thread(gps_thread, NULL, osPriorityRealtime);
     
     while(true);
 }
\ No newline at end of file