mbed-xbee(ATmode/pc対マイコン) ,LPS25HBの統合一段階目。 cmdの初期化が問題となっている。errorがでない。 確かめ付けました(2022/08/10) f

Dependencies:   mbed LPS25HB_I2C

main.cpp

Committer:
kosukesuzuki
Date:
21 months ago
Revision:
4:0ab4ae3013ae
Parent:
3:c0d472625a4b

File content as of revision 4:0ab4ae3013ae:

#include "mbed.h"
#include "LPS.h"

Timer t;

Serial pc(USBTX, USBRX); // tx, rx
Serial xbee(D1, D0); // tx, rx

/////////////////////////////
I2C i2c(D4,D5);
LPS ps(i2c);
///////////////////////////

Ticker press;

void pre() {
    if (!ps.init()){//2
        printf("Failed to autodetect pressure sensor!\r\n");
        while (1);
    }//2
   
    ps.enableDefault();
   
    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);
    
}



int main() {//1
    pc.printf("settig start\r\n");
    xbee.printf("settig start\r\n");
   
    ///////////////////////////////
    /*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());
       
        char cmd1 = xbee.getc();//cmd共有
        int va1 = xbee.readable();//これ1にならないと一向に進まないよ
        
        if(va1==1){//3 //これいいがいは永遠にまつ。
            wait_us(1);
            //機体の放出後→データを取る
            if(cmd1 == 'm'){//4
                pc.printf("start\r\n");
                t.start();
                cmd1 = 'a';
           
                press.attach(&pre, 1.0);
           
                while(1){//4
                    //if (pc.readable()) xbee.putc(pc.getc());
                    if (xbee.readable()) pc.putc(xbee.getc());
                    //printf("oo");
                    
                    /***********************************************************/
                    //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();
                    int va2 = xbee.readable();//これ1にならないと一向に進まないよ
                    
                    //xbee.printf("%x\r\n",cmd);
                    
                    if(va2 == 1){//5
                        wait_us(1);
                        //機体の着陸後→プログラムを終わらす。
                        if(cmd2 == 'n'){//5
                            press.detach();
                            pc.printf("end\r\n");
                            pc.printf("time = %f",t.read());
                            t.stop();
                            cmd2 = 'a';
                   
                            return 0;
                   
                            }//5
                        va2 = 0;
                        }//5
                    }//4
                }//4
           
           va1 =0;
            }//3
    }//2
}//1