GPS and IMU reading works

Dependencies:   mbed Servo SDFileSystem

/media/uploads/taoqiuyang/img_2352.jpg

Revision:
3:ab9f94d112c0
Parent:
2:afb333543af5
Child:
4:37d118f2348c
--- a/main.cpp	Sat Aug 08 08:01:25 2015 +0000
+++ b/main.cpp	Sat Aug 08 08:20:18 2015 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
- 
+#include <string>
+
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
  
@@ -7,13 +8,36 @@
 Serial IMU(p28, p27);  // tx, rx
 
 char IMU_message[256];
+int  IMU_message_counter=0;
  
 void callback() {
-    // Note: you need to actually read from the serial to clear the RX interrupt
-    pc.putc(IMU.getc());
+    char buf;
+    
+     while (IMU.readable()) {
+        buf = IMU.getc();
+        
+        IMU_message_counter+=1;
+        IMU_message[IMU_message_counter]=buf;
+        
+        if (buf=='#'){
+            IMU_message_counter=0;
+        }
+        
+        if (buf=='\n'){
+            int i;
+            for(i=0;i<=IMU_message_counter;i++){
+                pc.putc(IMU_message[i]);  
+            }  
+        } 
+    }
+     
+     
     led2 = !led2;
 }
  
+ 
+ 
+ 
 int main() {
     IMU.baud(57600);
     IMU.attach(&callback);