mbed-xbee(ATmode/pc対マイコン) ,LPS35HBの統合一段階目。 cmdの初期化が問題となっている。errorがでない。
Dependencies: mbed LPS25HB_I2C
Revision 2:39ad330d9ec8, committed 2022-08-09
- Comitter:
- kosukesuzuki
- Date:
- Tue Aug 09 14:07:28 2022 +0000
- Parent:
- 1:d7561bf65def
- Commit message:
- xbee-LPS
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d7561bf65def -r 39ad330d9ec8 main.cpp --- a/main.cpp Tue Aug 09 09:56:07 2022 +0000 +++ b/main.cpp Tue Aug 09 14:07:28 2022 +0000 @@ -11,83 +11,102 @@ LPS ps(i2c); /////////////////////////// -char cmd = xbee.getc(); +Ticker press; -int main() {//1 - pc.printf("settig start\r\n"); - xbee.printf("settig start\r\n"); - - /////////////////////////////// +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()); wait_us(1); - - //char cmd = xbee.getc();//cmd共有 + + char cmd1 = xbee.getc();//cmd共有 //機体の放出後→データを取る - if(cmd == 'm'){//3 + if(cmd1 == 'm'){//3 pc.printf("start\r\n"); t.start(); - cmd = ; - + cmd1 = 0; + + press.attach(&pre, 1.0); + 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); - + //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); - - + char cmd2 = xbee.getc();//共有化 + //xbee.printf("%x\r\n",cmd); + + //機体の着陸後→プログラムを終わらす。 - if(cmd == 'n'){//5 + if(cmd2 == 'n'){//5 pc.printf("end\r\n"); pc.printf("time = %f",t.read()); t.stop(); - cmd = 0; - + cmd2 = 0; + return 0; - + }//5 - + }//4 - - + + }//3 }//2 }//1 \ No newline at end of file