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

Dependencies:   mbed LPS25HB_I2C

Committer:
kosukesuzuki
Date:
Tue Aug 09 09:56:07 2022 +0000
Revision:
1:d7561bf65def
Parent:
0:5ffa13919073
xbee-LPS(matter)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kosukesuzuki 0:5ffa13919073 1 #include "mbed.h"
kosukesuzuki 1:d7561bf65def 2 #include "LPS.h"
kosukesuzuki 0:5ffa13919073 3
kosukesuzuki 0:5ffa13919073 4 Timer t;
kosukesuzuki 0:5ffa13919073 5
kosukesuzuki 0:5ffa13919073 6 Serial pc(USBTX, USBRX); // tx, rx
kosukesuzuki 1:d7561bf65def 7 Serial xbee(D1, D0); // tx, rx
kosukesuzuki 0:5ffa13919073 8
kosukesuzuki 1:d7561bf65def 9 /////////////////////////////
kosukesuzuki 1:d7561bf65def 10 I2C i2c(D4,D5);
kosukesuzuki 1:d7561bf65def 11 LPS ps(i2c);
kosukesuzuki 1:d7561bf65def 12 ///////////////////////////
kosukesuzuki 1:d7561bf65def 13
kosukesuzuki 1:d7561bf65def 14 char cmd = xbee.getc();
kosukesuzuki 1:d7561bf65def 15
kosukesuzuki 1:d7561bf65def 16 int main() {//1
kosukesuzuki 1:d7561bf65def 17 pc.printf("settig start\r\n");
kosukesuzuki 1:d7561bf65def 18 xbee.printf("settig start\r\n");
kosukesuzuki 0:5ffa13919073 19
kosukesuzuki 1:d7561bf65def 20 ///////////////////////////////
kosukesuzuki 1:d7561bf65def 21 if (!ps.init()){//2
kosukesuzuki 1:d7561bf65def 22 printf("Failed to autodetect pressure sensor!\r\n");
kosukesuzuki 1:d7561bf65def 23 while (1);
kosukesuzuki 1:d7561bf65def 24 }//2
kosukesuzuki 1:d7561bf65def 25 ps.enableDefault();
kosukesuzuki 1:d7561bf65def 26 ///////////////////////////////
kosukesuzuki 1:d7561bf65def 27
kosukesuzuki 1:d7561bf65def 28 /**************************************************************/
kosukesuzuki 1:d7561bf65def 29
kosukesuzuki 1:d7561bf65def 30
kosukesuzuki 1:d7561bf65def 31 //ここに気圧の標高の較正とGPSの接続を行う。
kosukesuzuki 1:d7561bf65def 32
kosukesuzuki 1:d7561bf65def 33
kosukesuzuki 1:d7561bf65def 34 /**************************************************************/
kosukesuzuki 1:d7561bf65def 35
kosukesuzuki 1:d7561bf65def 36 pc.printf("begin\r\n");
kosukesuzuki 1:d7561bf65def 37 xbee.printf("begin\r\n");
kosukesuzuki 1:d7561bf65def 38
kosukesuzuki 1:d7561bf65def 39 for (;;) {//2
kosukesuzuki 1:d7561bf65def 40
kosukesuzuki 0:5ffa13919073 41 //if (pc.readable()) xbee.putc(pc.getc());
kosukesuzuki 0:5ffa13919073 42 if (xbee.readable()) pc.putc(xbee.getc());
kosukesuzuki 0:5ffa13919073 43 wait_us(1);
kosukesuzuki 0:5ffa13919073 44
kosukesuzuki 1:d7561bf65def 45 //char cmd = xbee.getc();//cmd共有
kosukesuzuki 1:d7561bf65def 46
kosukesuzuki 1:d7561bf65def 47 //機体の放出後→データを取る
kosukesuzuki 1:d7561bf65def 48 if(cmd == 'm'){//3
kosukesuzuki 0:5ffa13919073 49 pc.printf("start\r\n");
kosukesuzuki 0:5ffa13919073 50 t.start();
kosukesuzuki 1:d7561bf65def 51 cmd = ;
kosukesuzuki 0:5ffa13919073 52
kosukesuzuki 1:d7561bf65def 53 while(1){//4
kosukesuzuki 1:d7561bf65def 54 //if (pc.readable()) xbee.putc(pc.getc());
kosukesuzuki 1:d7561bf65def 55 if (xbee.readable()) pc.putc(xbee.getc());
kosukesuzuki 1:d7561bf65def 56 //printf("oo");
kosukesuzuki 1:d7561bf65def 57 wait_us(1);
kosukesuzuki 1:d7561bf65def 58
kosukesuzuki 1:d7561bf65def 59 /***********************************************************/
kosukesuzuki 1:d7561bf65def 60 //////////////////////////////////////
kosukesuzuki 1:d7561bf65def 61 float pressure = ps.readPressureMillibars();
kosukesuzuki 1:d7561bf65def 62 float altitude = ps.pressureToAltitudeMeters(pressure);
kosukesuzuki 1:d7561bf65def 63 float temperature = ps.readTemperatureC();
kosukesuzuki 1:d7561bf65def 64 pc.printf("p:%.2f\t mbar\ta:%.2f m\tt:%.2f deg C\r\n",pressure,altitude,temperature);
kosukesuzuki 1:d7561bf65def 65
kosukesuzuki 1:d7561bf65def 66 //////////////////////////////////////
kosukesuzuki 1:d7561bf65def 67
kosukesuzuki 1:d7561bf65def 68 //データ(気圧,GPS,地磁気)を取る。
kosukesuzuki 1:d7561bf65def 69 //データの保存を10回行い, 保存する。
kosukesuzuki 1:d7561bf65def 70
kosukesuzuki 1:d7561bf65def 71
kosukesuzuki 1:d7561bf65def 72 /***********************************************************/
kosukesuzuki 1:d7561bf65def 73 //char cmd2 = xbee.getc();//共有化
kosukesuzuki 1:d7561bf65def 74 xbee.printf("%x\r\n",cmd);
kosukesuzuki 1:d7561bf65def 75
kosukesuzuki 1:d7561bf65def 76
kosukesuzuki 1:d7561bf65def 77 //機体の着陸後→プログラムを終わらす。
kosukesuzuki 1:d7561bf65def 78 if(cmd == 'n'){//5
kosukesuzuki 1:d7561bf65def 79 pc.printf("end\r\n");
kosukesuzuki 1:d7561bf65def 80 pc.printf("time = %f",t.read());
kosukesuzuki 1:d7561bf65def 81 t.stop();
kosukesuzuki 1:d7561bf65def 82 cmd = 0;
kosukesuzuki 1:d7561bf65def 83
kosukesuzuki 1:d7561bf65def 84 return 0;
kosukesuzuki 1:d7561bf65def 85
kosukesuzuki 1:d7561bf65def 86 }//5
kosukesuzuki 1:d7561bf65def 87
kosukesuzuki 1:d7561bf65def 88 }//4
kosukesuzuki 1:d7561bf65def 89
kosukesuzuki 1:d7561bf65def 90
kosukesuzuki 1:d7561bf65def 91 }//3
kosukesuzuki 1:d7561bf65def 92 }//2
kosukesuzuki 1:d7561bf65def 93 }//1