f303k8(メイン)用のプログラム。 ver1
Dependencies: mbed BufferedSerial
main.cpp@1:b12e35a43ee1, 2021-08-16 (annotated)
- Committer:
- MatsumotoKouki
- Date:
- Mon Aug 16 12:08:41 2021 +0000
- Revision:
- 1:b12e35a43ee1
- Parent:
- 0:9669502e17f0
- Child:
- 2:2c73772e8a8b
- Child:
- 3:bc0359b37d5c
2021/08/16 I think this will work, but do not test.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MatsumotoKouki | 0:9669502e17f0 | 1 | #include "mbed.h" |
MatsumotoKouki | 0:9669502e17f0 | 2 | |
MatsumotoKouki | 0:9669502e17f0 | 3 | //コマンド取得とモード変換は関数にいれたほうがわかりやすい |
MatsumotoKouki | 0:9669502e17f0 | 4 | void nichrome_ON(); |
MatsumotoKouki | 0:9669502e17f0 | 5 | void buzzerON(); |
MatsumotoKouki | 1:b12e35a43ee1 | 6 | int getCommand(); |
MatsumotoKouki | 0:9669502e17f0 | 7 | |
MatsumotoKouki | 0:9669502e17f0 | 8 | Serial pc(USBTX, USBRX,38400);//ボーレートを落とすと,USB側からのデータが正確に出力されない.//pcと直接通信してないのに定義する必要ある? |
MatsumotoKouki | 0:9669502e17f0 | 9 | Serial im920(PA_9,PA_10,19200);//TX(IM920_RX), RX(IM920_TX) |
MatsumotoKouki | 0:9669502e17f0 | 10 | DigitalOut mcu_1(PA_7); |
MatsumotoKouki | 0:9669502e17f0 | 11 | DigitalOut mcu_2(PA_6); |
MatsumotoKouki | 0:9669502e17f0 | 12 | DigitalOut cameraPow(PF_0); |
MatsumotoKouki | 0:9669502e17f0 | 13 | DigitalOut cameraRec(PF_1); |
MatsumotoKouki | 0:9669502e17f0 | 14 | DigitalOut nichrome(PA_8); |
MatsumotoKouki | 0:9669502e17f0 | 15 | DigitalOut buzzer(PA_11); |
MatsumotoKouki | 0:9669502e17f0 | 16 | DigitalIn flightPin(PA_12); |
MatsumotoKouki | 0:9669502e17f0 | 17 | Timeout t; |
MatsumotoKouki | 1:b12e35a43ee1 | 18 | char str[100]; |
MatsumotoKouki | 1:b12e35a43ee1 | 19 | int i=0; |
MatsumotoKouki | 0:9669502e17f0 | 20 | |
MatsumotoKouki | 0:9669502e17f0 | 21 | int main() |
MatsumotoKouki | 0:9669502e17f0 | 22 | { |
MatsumotoKouki | 0:9669502e17f0 | 23 | //ここに電源投入のプロトコル |
MatsumotoKouki | 1:b12e35a43ee1 | 24 | int flag=0; |
MatsumotoKouki | 1:b12e35a43ee1 | 25 | while(flightPin==1){ |
MatsumotoKouki | 1:b12e35a43ee1 | 26 | if(flag==0){ |
MatsumotoKouki | 1:b12e35a43ee1 | 27 | while(1){ |
MatsumotoKouki | 1:b12e35a43ee1 | 28 | if(getCommand()==1){ |
MatsumotoKouki | 1:b12e35a43ee1 | 29 | flag=1;//flagに1を代入することで先に進む |
MatsumotoKouki | 1:b12e35a43ee1 | 30 | cameraPow=1; |
MatsumotoKouki | 1:b12e35a43ee1 | 31 | cameraRec=1;//カメラスタートという指示しかないけど、電源と録画開始は同じ時間でいいのか? |
MatsumotoKouki | 1:b12e35a43ee1 | 32 | break; |
MatsumotoKouki | 0:9669502e17f0 | 33 | } |
MatsumotoKouki | 0:9669502e17f0 | 34 | } |
MatsumotoKouki | 0:9669502e17f0 | 35 | } |
MatsumotoKouki | 1:b12e35a43ee1 | 36 | |
MatsumotoKouki | 1:b12e35a43ee1 | 37 | else if(flag==1){ |
MatsumotoKouki | 1:b12e35a43ee1 | 38 | while(1) { |
MatsumotoKouki | 1:b12e35a43ee1 | 39 | if(getCommand()==1){ |
MatsumotoKouki | 1:b12e35a43ee1 | 40 | flag=0;//flagに0を代入することで最初に戻る |
MatsumotoKouki | 1:b12e35a43ee1 | 41 | break; |
MatsumotoKouki | 0:9669502e17f0 | 42 | } |
MatsumotoKouki | 0:9669502e17f0 | 43 | } |
MatsumotoKouki | 0:9669502e17f0 | 44 | } |
MatsumotoKouki | 0:9669502e17f0 | 45 | } |
MatsumotoKouki | 0:9669502e17f0 | 46 | t.attach(nichrome_ON,3);//ニクロムを作動させるまでの時間 |
MatsumotoKouki | 0:9669502e17f0 | 47 | //ここからGPSの情報取得して送信 |
MatsumotoKouki | 0:9669502e17f0 | 48 | } |
MatsumotoKouki | 0:9669502e17f0 | 49 | |
MatsumotoKouki | 0:9669502e17f0 | 50 | void nichrome_ON(){ |
MatsumotoKouki | 0:9669502e17f0 | 51 | printf("テグスカット!\n\r"); |
MatsumotoKouki | 0:9669502e17f0 | 52 | nichrome=1; |
MatsumotoKouki | 0:9669502e17f0 | 53 | wait(2.0);//テグスを切るまでにかかる時間 |
MatsumotoKouki | 0:9669502e17f0 | 54 | nichrome=0; |
MatsumotoKouki | 0:9669502e17f0 | 55 | t.detach(); |
MatsumotoKouki | 0:9669502e17f0 | 56 | t.attach(buzzerON,6);//ブザー作動までの時間 |
MatsumotoKouki | 0:9669502e17f0 | 57 | } |
MatsumotoKouki | 0:9669502e17f0 | 58 | |
MatsumotoKouki | 0:9669502e17f0 | 59 | void buzzerON(){ |
MatsumotoKouki | 0:9669502e17f0 | 60 | printf("ブザー作動\n\r"); |
MatsumotoKouki | 0:9669502e17f0 | 61 | buzzer=1; |
MatsumotoKouki | 0:9669502e17f0 | 62 | //ここからモード変換だけど、わかりにくかったら他の関数に入れてもいいかも |
MatsumotoKouki | 0:9669502e17f0 | 63 | mcu_1=1; |
MatsumotoKouki | 0:9669502e17f0 | 64 | wait(0.1);//電流何秒流す? |
MatsumotoKouki | 0:9669502e17f0 | 65 | mcu_1=0; |
MatsumotoKouki | 0:9669502e17f0 | 66 | } |
MatsumotoKouki | 0:9669502e17f0 | 67 | |
MatsumotoKouki | 1:b12e35a43ee1 | 68 | int getCommand(){ |
MatsumotoKouki | 1:b12e35a43ee1 | 69 | char temp; |
MatsumotoKouki | 1:b12e35a43ee1 | 70 | if(im920.readable()) { //IM920からのデータがある場合 |
MatsumotoKouki | 1:b12e35a43ee1 | 71 | temp = im920.getc();//一文字読み込む |
MatsumotoKouki | 1:b12e35a43ee1 | 72 | if(temp != '\r') { //読み込み文字が改行で無い場合 |
MatsumotoKouki | 1:b12e35a43ee1 | 73 | str[i] = temp; |
MatsumotoKouki | 1:b12e35a43ee1 | 74 | i++; |
MatsumotoKouki | 1:b12e35a43ee1 | 75 | } else if(temp == '\r') { //読み込み文字が改行の場合//\nではなく\rを使うのに理由はある? |
MatsumotoKouki | 1:b12e35a43ee1 | 76 | if(str[i-2] == 's'&& str[i-1] == 't') { //startの"st" |
MatsumotoKouki | 1:b12e35a43ee1 | 77 | mcu_1=1; |
MatsumotoKouki | 1:b12e35a43ee1 | 78 | wait(0.1); //電流流すの何秒間にしましょう? |
MatsumotoKouki | 1:b12e35a43ee1 | 79 | mcu_1=0; |
MatsumotoKouki | 1:b12e35a43ee1 | 80 | return 1; |
MatsumotoKouki | 1:b12e35a43ee1 | 81 | } |
MatsumotoKouki | 1:b12e35a43ee1 | 82 | } |
MatsumotoKouki | 1:b12e35a43ee1 | 83 | else if(temp == '\r') { //読み込み文字が改行の場合//\nではなく\rを使うのに理由はある? |
MatsumotoKouki | 1:b12e35a43ee1 | 84 | if(str[i-2] == 'r' && str[i-1] == 'e') { |
MatsumotoKouki | 1:b12e35a43ee1 | 85 | mcu_1=1; |
MatsumotoKouki | 1:b12e35a43ee1 | 86 | mcu_2=1; |
MatsumotoKouki | 1:b12e35a43ee1 | 87 | wait(0.1); //電流流すの何秒間にしましょう? |
MatsumotoKouki | 1:b12e35a43ee1 | 88 | mcu_1=0; |
MatsumotoKouki | 1:b12e35a43ee1 | 89 | mcu_2=0; |
MatsumotoKouki | 1:b12e35a43ee1 | 90 | return 1; |
MatsumotoKouki | 1:b12e35a43ee1 | 91 | } |
MatsumotoKouki | 1:b12e35a43ee1 | 92 | } |
MatsumotoKouki | 1:b12e35a43ee1 | 93 | } |
MatsumotoKouki | 1:b12e35a43ee1 | 94 | } |