mbed-xbee(ATmode/pc対マイコン) ,LPS35HBの統合一段階目。 cmdの初期化が問題となっている。

Dependencies:   mbed LPS25HB_I2C

Files at this revision

API Documentation at this revision

Comitter:
kosukesuzuki
Date:
Tue Aug 09 09:56:07 2022 +0000
Parent:
0:5ffa13919073
Commit message:
xbee-LPS(matter)

Changed in this revision

LPS25HB_I2C.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPS25HB_I2C.lib	Tue Aug 09 09:56:07 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/tajiri1999/code/LPS25HB_I2C/#4ea758df868a
--- a/main.cpp	Tue Aug 02 10:44:00 2022 +0000
+++ b/main.cpp	Tue Aug 09 09:56:07 2022 +0000
@@ -1,32 +1,93 @@
 #include "mbed.h"
+#include "LPS.h"
 
 Timer t;
 
 Serial pc(USBTX, USBRX); // tx, rx
-Serial xbee(PA_9, PA_10); // tx, rx
+Serial xbee(D1, D0); // tx, rx
 
-int main() {
+/////////////////////////////
+I2C i2c(D4,D5);
+LPS ps(i2c);
+///////////////////////////
+
+char cmd = xbee.getc();
+
+int main() {//1
+    pc.printf("settig start\r\n");
+    xbee.printf("settig start\r\n");
     
-    pc.printf("\rbegin\r");
- 
-    for (;;) {
+    ///////////////////////////////
+    if (!ps.init()){//2
+        printf("Failed to autodetect pressure sensor!\r\n");
+        while (1);
+    }//2
+    ps.enableDefault();
+    ///////////////////////////////
+    
+    /**************************************************************/
+    
+    
+            //ここに気圧の標高の較正とGPSの接続を行う。
+    
+    
+    /**************************************************************/
+    
+    pc.printf("begin\r\n");
+    xbee.printf("begin\r\n");
+    
+    for (;;) {//2
+        
         //if (pc.readable()) xbee.putc(pc.getc());
         if (xbee.readable()) pc.putc(xbee.getc());
         wait_us(1);
         
-        char cmd = xbee.getc();
-        if(cmd == 'm'){
+        //char cmd = xbee.getc();//cmd共有
+
+        //機体の放出後→データを取る
+        if(cmd == 'm'){//3
             pc.printf("start\r\n");
             t.start();
-            cmd = 0;
-            }
+            cmd = ;
             
-        if(cmd == 'n'){
-            pc.printf("end\r\n");
-            pc.printf("time = %f",t.read());
-            t.stop();
-            cmd = 0;
-            return 0;
-            }
-    }
-}
\ No newline at end of file
+            while(1){//4
+                //if (pc.readable()) xbee.putc(pc.getc());
+                if (xbee.readable()) pc.putc(xbee.getc());
+                //printf("oo");
+                wait_us(1);
+                
+                /***********************************************************/
+                //////////////////////////////////////
+                float pressure = ps.readPressureMillibars();
+                float altitude = ps.pressureToAltitudeMeters(pressure);
+                float temperature = ps.readTemperatureC();
+                pc.printf("p:%.2f\t mbar\ta:%.2f m\tt:%.2f deg C\r\n",pressure,altitude,temperature);
+                    
+                //////////////////////////////////////
+                
+                                //データ(気圧,GPS,地磁気)を取る。
+                                //データの保存を10回行い, 保存する。
+                
+                
+                /***********************************************************/
+                //char cmd2 = xbee.getc();//共有化
+                xbee.printf("%x\r\n",cmd);
+                
+                
+                //機体の着陸後→プログラムを終わらす。
+                if(cmd == 'n'){//5
+                    pc.printf("end\r\n");
+                    pc.printf("time = %f",t.read());
+                    t.stop();
+                    cmd = 0;
+                    
+                    return 0;
+                    
+                    }//5
+                
+                }//4
+            
+            
+            }//3
+    }//2
+}//1
\ No newline at end of file