gyo

Committer:
nanjo
Date:
Sat Feb 16 07:24:19 2019 +0000
Revision:
9:8538fc8f6259
Parent:
7:30e05998769b
Child:
10:b352937cda3b
test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gotto0 0:afe58893bfe7 1 #include "SBDBT.h"
gotto0 0:afe58893bfe7 2
nanjo 9:8538fc8f6259 3 SBDBT::SBDBT(PinName p1, PinName p2)
gotto0 0:afe58893bfe7 4 {
gotto0 0:afe58893bfe7 5 i = 0;
gotto0 3:16a15d26ebe8 6 readable = 0;
gotto0 1:8810976be033 7 length = 8;
gotto0 1:8810976be033 8 value = 128;
gotto0 1:8810976be033 9 position = 0;
gotto0 2:1472e7c5317d 10 tmp = new char [length];
gotto0 1:8810976be033 11 data = new char [length];
gotto0 0:afe58893bfe7 12 sr = new Serial(p1,p2);
gotto0 0:afe58893bfe7 13 sr -> baud(2400);
gotto0 1:8810976be033 14 sr -> attach(this,&SBDBT::getf,Serial::RxIrq);
gotto0 0:afe58893bfe7 15 }
gotto0 0:afe58893bfe7 16
gotto0 1:8810976be033 17 SBDBT::SBDBT(PinName p1, PinName p2, int baud)
gotto0 1:8810976be033 18 {
gotto0 1:8810976be033 19 i = 0;
gotto0 2:1472e7c5317d 20 readable = 0;
gotto0 1:8810976be033 21 length = 8;
gotto0 1:8810976be033 22 value = 128;
gotto0 1:8810976be033 23 position = 0;
gotto0 2:1472e7c5317d 24 tmp = new char [length];
gotto0 1:8810976be033 25 data = new char [length];
gotto0 1:8810976be033 26 sr = new Serial(p1,p2);
gotto0 1:8810976be033 27 sr -> baud(baud);
gotto0 1:8810976be033 28 sr -> attach(this,&SBDBT::getf,Serial::RxIrq);
gotto0 1:8810976be033 29 }
gotto0 1:8810976be033 30
gotto0 1:8810976be033 31 void SBDBT::getf()
gotto0 0:afe58893bfe7 32 {
gotto0 2:1472e7c5317d 33 tmp[i] = sr -> getc();
gotto0 2:1472e7c5317d 34 if(tmp[i] == value) //受信したデータが訂正用定数であり
gotto0 0:afe58893bfe7 35 {
gotto0 1:8810976be033 36 if(i != position) //訂正用定数を受信すべき位置でないとき
gotto0 1:8810976be033 37 {
gotto0 2:1472e7c5317d 38 tmp[position] = value; //正しい位置に訂正用定数を代入
gotto0 1:8810976be033 39 i = position + 1; //受信先も正しい位置へもどす
gotto0 1:8810976be033 40 }
gotto0 1:8810976be033 41 else //訂正用定数を受信すべき位置であるとき
gotto0 1:8810976be033 42 i++; //次の位置で受信する
gotto0 1:8810976be033 43 }
gotto0 1:8810976be033 44 else //受信したデータが訂正用定数でなく
gotto0 1:8810976be033 45 {
gotto0 1:8810976be033 46 if(i == position){} //訂正用定数を受信すべき位置であるとき
gotto0 1:8810976be033 47 //再度同じ位置で受信する
gotto0 1:8810976be033 48 else //訂正用定数を受信すべき場所でないとき
gotto0 1:8810976be033 49 i++; //次の位置で受信する
gotto0 1:8810976be033 50 }
gotto0 1:8810976be033 51 if(i>=length) //位置がデータの長さを超えたら
gotto0 1:8810976be033 52 {
gotto0 2:1472e7c5317d 53 data[0] = tmp[0];
gotto0 2:1472e7c5317d 54 data[1] = tmp[1];
gotto0 2:1472e7c5317d 55 data[2] = tmp[2];
gotto0 2:1472e7c5317d 56 data[3] = tmp[3];
gotto0 2:1472e7c5317d 57 data[4] = tmp[4];
gotto0 2:1472e7c5317d 58 data[5] = tmp[5];
gotto0 2:1472e7c5317d 59 data[6] = tmp[6];
gotto0 2:1472e7c5317d 60 data[7] = tmp[7];
gotto0 2:1472e7c5317d 61 readable = 1; //全データ受信完了
nanjo 9:8538fc8f6259 62 check();
gotto0 1:8810976be033 63 i=0; //位置を初期化
gotto0 0:afe58893bfe7 64 }
gotto0 0:afe58893bfe7 65 }
gotto0 0:afe58893bfe7 66
gotto0 6:da71294502ee 67 void SBDBT::print()
gotto0 6:da71294502ee 68 {
nanjo 9:8538fc8f6259 69 printf("%3d %3d %3d %3d %3d %3d %3d %3d\r\n",data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7]);
gotto0 5:a4a994824c96 70 }
gotto0 5:a4a994824c96 71
nanjo 9:8538fc8f6259 72 int8_t SBDBT::State_check()
gotto0 5:a4a994824c96 73 {
nanjo 9:8538fc8f6259 74 if(readable == 1)return 1;
nanjo 9:8538fc8f6259 75 else return 0;
gotto0 5:a4a994824c96 76 }
gotto0 5:a4a994824c96 77
nanjo 9:8538fc8f6259 78 void SBDBT::check()
nanjo 9:8538fc8f6259 79 {
nanjo 9:8538fc8f6259 80 SQUARE=((data[1] & 1) ? 1 : 0);
nanjo 9:8538fc8f6259 81 L1 = ((data[1] & 2) ? 1 : 0);
nanjo 9:8538fc8f6259 82 L2 = ((data[1] & 4) ? 1 : 0);
nanjo 9:8538fc8f6259 83 L3 = ((data[1] & 8) ? 1 : 0);
nanjo 9:8538fc8f6259 84 R1 = ((data[1] & 16)? 1 : 0);
nanjo 9:8538fc8f6259 85 R2 = ((data[1] & 32)? 1 : 0);
nanjo 9:8538fc8f6259 86 R3 = ((data[1] & 64)? 1 : 0);
nanjo 9:8538fc8f6259 87
nanjo 9:8538fc8f6259 88 UPkey = ((data[2] & 1) ? 1 : 0);
nanjo 9:8538fc8f6259 89 DOWNkey = ((data[2] & 2) ? 1 : 0);
nanjo 9:8538fc8f6259 90 RIGHTkey = ((data[2] & 4) ? 1 : 0);
nanjo 9:8538fc8f6259 91 LEFTkey = ((data[2] & 8) ? 1 : 0);
nanjo 9:8538fc8f6259 92 TRIANGLE = ((data[2] & 16)? 1 : 0);
nanjo 9:8538fc8f6259 93 CROSS = ((data[2] & 32)? 1 : 0);
nanjo 9:8538fc8f6259 94 CIRCLE = ((data[2] & 64)? 1 : 0);
nanjo 9:8538fc8f6259 95
nanjo 9:8538fc8f6259 96 LX = data[3];
nanjo 9:8538fc8f6259 97 LY = data[4];
nanjo 9:8538fc8f6259 98 RX = data[5];
nanjo 9:8538fc8f6259 99 RY = data[6];
gotto0 5:a4a994824c96 100 }
gotto0 5:a4a994824c96 101
gotto0 6:da71294502ee 102
gotto0 6:da71294502ee 103 char SBDBT::rs_x_check()
gotto0 6:da71294502ee 104 {
gotto0 6:da71294502ee 105 return data[5]==data[5] ? 0 : 1;
gotto0 5:a4a994824c96 106 }
gotto0 5:a4a994824c96 107
gotto0 6:da71294502ee 108 char SBDBT::rs_y_check()
gotto0 5:a4a994824c96 109 {
gotto0 6:da71294502ee 110 return data[6]==data[6] ? 0 : 1;
gotto0 5:a4a994824c96 111 }
gotto0 5:a4a994824c96 112
gotto0 6:da71294502ee 113 char SBDBT::ls_x_check()
gotto0 5:a4a994824c96 114 {
gotto0 6:da71294502ee 115 return data[3]==data[3] ? 0 : 1;
gotto0 6:da71294502ee 116 }
gotto0 6:da71294502ee 117
gotto0 6:da71294502ee 118 char SBDBT::ls_y_check()
gotto0 6:da71294502ee 119 {
gotto0 6:da71294502ee 120 return data[4]==data[4] ? 0 : 1;
gotto0 5:a4a994824c96 121 }
gotto0 5:a4a994824c96 122
gotto0 0:afe58893bfe7 123 SBDBT::~SBDBT()
gotto0 0:afe58893bfe7 124 {
gotto0 0:afe58893bfe7 125 delete sr;
gotto0 6:da71294502ee 126 delete tmp;
gotto0 6:da71294502ee 127 delete data;
gotto0 0:afe58893bfe7 128 }
nanjo 9:8538fc8f6259 129