gyo

Committer:
kurobikari
Date:
Wed Oct 16 10:56:28 2019 +0000
Revision:
16:976121fe5c9d
Parent:
15:8c49a263e344
gyo

Who changed what in which revision?

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