PS3の移動ライブラリ(バグあり動作不可)です。 誠意製作中です。

Dependents:   NHK2018_BM

Committer:
tektomo
Date:
Sat Sep 22 11:09:22 2018 +0000
Revision:
1:5bb9feb40944
Parent:
0:1e79ec3fb922
Child:
2:9b3aeecc67d9
???????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tektomo 0:1e79ec3fb922 1 #include "PS3_S.h"
tektomo 0:1e79ec3fb922 2
tektomo 0:1e79ec3fb922 3 PS3s::PS3s(PinName TX, PinName RX) : Serial(TX, RX)
tektomo 0:1e79ec3fb922 4 {
tektomo 0:1e79ec3fb922 5 baud(2400);
tektomo 1:5bb9feb40944 6 Rdata[0] = 128;
tektomo 0:1e79ec3fb922 7 Rdata[1] = 0;
tektomo 0:1e79ec3fb922 8 Rdata[2] = 0;
tektomo 1:5bb9feb40944 9 Rdata[3] = 64;
tektomo 1:5bb9feb40944 10 Rdata[4] = 64;
tektomo 1:5bb9feb40944 11 Rdata[5] = 64;
tektomo 1:5bb9feb40944 12 Rdata[6] = 64;
tektomo 0:1e79ec3fb922 13 Rdata[7] = 0;
tektomo 0:1e79ec3fb922 14 for(int i = 0; i < 18; i++) {
tektomo 0:1e79ec3fb922 15 condata[i] = 0;
tektomo 0:1e79ec3fb922 16 }
tektomo 0:1e79ec3fb922 17 }
tektomo 0:1e79ec3fb922 18
tektomo 0:1e79ec3fb922 19 void PS3s::getdata()
tektomo 0:1e79ec3fb922 20 {
tektomo 0:1e79ec3fb922 21
tektomo 0:1e79ec3fb922 22 if (Serial::readable() == true) {
tektomo 0:1e79ec3fb922 23 databuffer = Serial::getc();
tektomo 0:1e79ec3fb922 24 if(databuffer == 128) {
tektomo 0:1e79ec3fb922 25 endval = 1;
tektomo 0:1e79ec3fb922 26 dataval = 0;
tektomo 0:1e79ec3fb922 27 checkval = 1;
tektomo 0:1e79ec3fb922 28 Rdata[dataval] = databuffer;
tektomo 0:1e79ec3fb922 29 dataval++;
tektomo 0:1e79ec3fb922 30 }else if(endval == 1){
tektomo 0:1e79ec3fb922 31 Rdata[dataval] = databuffer;
tektomo 0:1e79ec3fb922 32 dataval++;
tektomo 0:1e79ec3fb922 33 if(dataval == 7) {
tektomo 0:1e79ec3fb922 34 endval = 0;
tektomo 0:1e79ec3fb922 35 checkval = 0;
tektomo 0:1e79ec3fb922 36 dataval = 0;
tektomo 0:1e79ec3fb922 37 }
tektomo 0:1e79ec3fb922 38 }
tektomo 0:1e79ec3fb922 39 }
tektomo 0:1e79ec3fb922 40 }
tektomo 0:1e79ec3fb922 41
tektomo 0:1e79ec3fb922 42 void PS3s::checkdata()
tektomo 0:1e79ec3fb922 43 {
tektomo 0:1e79ec3fb922 44 if (checkval == false) {
tektomo 0:1e79ec3fb922 45 for (int i = 1; i < 7; i++) {
tektomo 0:1e79ec3fb922 46 checksum_buffer += Rdata[i];
tektomo 0:1e79ec3fb922 47 }
tektomo 0:1e79ec3fb922 48 checksum_buffer = checksum_buffer & 0x0000007F;
tektomo 0:1e79ec3fb922 49 checkval = 1;
tektomo 0:1e79ec3fb922 50 if(checksum_buffer == (Rdata[7] & 0x0000007F)) {
tektomo 0:1e79ec3fb922 51 button1_buffer = Rdata[1];
tektomo 0:1e79ec3fb922 52 button2_buffer = Rdata[2];
tektomo 0:1e79ec3fb922 53 condata[14] = Rdata[3];
tektomo 0:1e79ec3fb922 54 condata[15] = Rdata[4];
tektomo 0:1e79ec3fb922 55 condata[16] = Rdata[5];
tektomo 0:1e79ec3fb922 56 condata[17] = Rdata[6];
tektomo 0:1e79ec3fb922 57
tektomo 0:1e79ec3fb922 58 int num1 = 16;
tektomo 0:1e79ec3fb922 59 int num2 = 64;
tektomo 0:1e79ec3fb922 60 int value1 = 0;
tektomo 0:1e79ec3fb922 61 int value2 = 0;
tektomo 0:1e79ec3fb922 62
tektomo 0:1e79ec3fb922 63 for(int i = 5; i >= 1; i--) {
tektomo 0:1e79ec3fb922 64 value1 = i + 6;
tektomo 0:1e79ec3fb922 65 if (button1_buffer >= num1) {
tektomo 0:1e79ec3fb922 66 condata[value1] = 1;
tektomo 0:1e79ec3fb922 67 button1_buffer -= num1;
tektomo 0:1e79ec3fb922 68 } else {
tektomo 0:1e79ec3fb922 69 condata[value1] = 0;
tektomo 0:1e79ec3fb922 70 }
tektomo 0:1e79ec3fb922 71 num1 /= 2;
tektomo 0:1e79ec3fb922 72 }
tektomo 0:1e79ec3fb922 73
tektomo 0:1e79ec3fb922 74 for(int j = 7; j >= 1; j--) {
tektomo 0:1e79ec3fb922 75 value2 = j - 1;
tektomo 0:1e79ec3fb922 76 if (button2_buffer - num2 >= 0) {
tektomo 0:1e79ec3fb922 77 condata[value2] = 1;
tektomo 0:1e79ec3fb922 78 button2_buffer -= num2;
tektomo 0:1e79ec3fb922 79 } else {
tektomo 0:1e79ec3fb922 80 condata[value2] = 0;
tektomo 0:1e79ec3fb922 81 }
tektomo 0:1e79ec3fb922 82 num2 /= 2;
tektomo 0:1e79ec3fb922 83 }
tektomo 0:1e79ec3fb922 84 if(condata[0]!=0 && condata[1]!=0) {
tektomo 0:1e79ec3fb922 85 condata[0] = 0;
tektomo 0:1e79ec3fb922 86 condata[1] = 0;
tektomo 0:1e79ec3fb922 87 condata[13] = 1;
tektomo 0:1e79ec3fb922 88 } else if(condata[2]!=0 && condata[3]!=0) {
tektomo 0:1e79ec3fb922 89 condata[2] = 0;
tektomo 0:1e79ec3fb922 90 condata[3] = 0;
tektomo 0:1e79ec3fb922 91 condata[12] = 1;
tektomo 0:1e79ec3fb922 92 } else {
tektomo 0:1e79ec3fb922 93 condata[12] = 0;
tektomo 0:1e79ec3fb922 94 condata[13] = 0;
tektomo 0:1e79ec3fb922 95 }
tektomo 0:1e79ec3fb922 96 }
tektomo 0:1e79ec3fb922 97 }
tektomo 0:1e79ec3fb922 98 }