f303k8(メイン)用のプログラム。 ver1
Dependencies: mbed BufferedSerial
Diff: main.cpp
- Revision:
- 1:b12e35a43ee1
- Parent:
- 0:9669502e17f0
- Child:
- 2:2c73772e8a8b
- Child:
- 3:bc0359b37d5c
diff -r 9669502e17f0 -r b12e35a43ee1 main.cpp --- a/main.cpp Sun Aug 15 14:07:43 2021 +0000 +++ b/main.cpp Mon Aug 16 12:08:41 2021 +0000 @@ -3,7 +3,7 @@ //コマンド取得とモード変換は関数にいれたほうがわかりやすい void nichrome_ON(); void buzzerON(); -void getCommand(); +int getCommand(); Serial pc(USBTX, USBRX,38400);//ボーレートを落とすと,USB側からのデータが正確に出力されない.//pcと直接通信してないのに定義する必要ある? Serial im920(PA_9,PA_10,19200);//TX(IM920_RX), RX(IM920_TX) @@ -15,53 +15,30 @@ DigitalOut buzzer(PA_11); DigitalIn flightPin(PA_12); Timeout t; +char str[100]; +int i=0; int main() { //ここに電源投入のプロトコル - char temp; - char str[100]; - int i=0; - - - Timeout t; - - while(1) { - if(im920.readable()) { //IM920からのデータがある場合 - temp = im920.getc();//一文字読み込む - if(temp != '\r') { //読み込み文字が改行で無い場合 - str[i] = temp; - i++; - } else if(temp == '\r') { //読み込み文字が改行の場合//\nではなく\rを使うのに理由はある? - if(str[i-2] == 's') { - if(str[i-1] == 't') { //今回はstartの"st"で判定する - mcu_1=1; - wait(0.1); //電流流すの何秒間にしましょう? - mcu_1=0; - break; - } + int flag=0; + while(flightPin==1){ + if(flag==0){ + while(1){ + if(getCommand()==1){ + flag=1;//flagに1を代入することで先に進む + cameraPow=1; + cameraRec=1;//カメラスタートという指示しかないけど、電源と録画開始は同じ時間でいいのか? + break; } } } - } - cameraPow=1; - cameraRec=1;//カメラスタートという指示しかないけど、電源と録画開始は同じ時間でいいのか? - - while(flightPin!=1) { - if(im920.readable()) { //IM920からのデータがある場合 - temp = im920.getc();//一文字読み込む - if(temp != '\r') { //読み込み文字が改行で無い場合 - str[i] = temp; - i++; - } else if(temp == '\r') { //読み込み文字が改行の場合//\nではなく\rを使うのに理由はある? - if(str[i-2] == 'r') { - if(str[i-1] == 'e') { //今回はresetの"re"で判定する - mcu_1=1; - mcu_2=1; - wait(0.1); //電流流すの何秒間にしましょう? - mcu_1=0; - mcu_2=0; - } + + else if(flag==1){ + while(1) { + if(getCommand()==1){ + flag=0;//flagに0を代入することで最初に戻る + break; } } } @@ -88,4 +65,30 @@ mcu_1=0; } -void getCommand(){} \ No newline at end of file +int getCommand(){ + char temp; + if(im920.readable()) { //IM920からのデータがある場合 + temp = im920.getc();//一文字読み込む + if(temp != '\r') { //読み込み文字が改行で無い場合 + str[i] = temp; + i++; + } else if(temp == '\r') { //読み込み文字が改行の場合//\nではなく\rを使うのに理由はある? + if(str[i-2] == 's'&& str[i-1] == 't') { //startの"st" + mcu_1=1; + wait(0.1); //電流流すの何秒間にしましょう? + mcu_1=0; + return 1; + } + } + else if(temp == '\r') { //読み込み文字が改行の場合//\nではなく\rを使うのに理由はある? + if(str[i-2] == 'r' && str[i-1] == 'e') { + mcu_1=1; + mcu_2=1; + wait(0.1); //電流流すの何秒間にしましょう? + mcu_1=0; + mcu_2=0; + return 1; + } + } + } +} \ No newline at end of file