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

Dependents:   NHK2018_BM

Files at this revision

API Documentation at this revision

Comitter:
tektomo
Date:
Thu Sep 27 09:24:36 2018 +0000
Parent:
1:5bb9feb40944
Commit message:
PID????????????

Changed in this revision

PS3_S.cpp Show annotated file Show diff for this revision Revisions of this file
PS3_S.h Show annotated file Show diff for this revision Revisions of this file
--- a/PS3_S.cpp	Sat Sep 22 11:09:22 2018 +0000
+++ b/PS3_S.cpp	Thu Sep 27 09:24:36 2018 +0000
@@ -18,81 +18,59 @@
 
 void PS3s::getdata()
 {
-    
-    if (Serial::readable() == true) {
-        databuffer = Serial::getc();
-        if(databuffer == 128) {
-            endval = 1;
-            dataval = 0;
-            checkval = 1;
-            Rdata[dataval] = databuffer;
-            dataval++;
-        }else if(endval == 1){
-            Rdata[dataval] = databuffer;
-            dataval++;
-            if(dataval == 7) {
-                endval = 0;
-                checkval = 0;
-                dataval = 0;
-            }
+    if (Serial::readable()) {
+        while(Serial::getc() != 128) {}
+        for (int i = 1;i < 8;i++){
+            Rdata[i] = Serial::getc();
         }
     }
 }
 
 void PS3s::checkdata()
 {
-    if (checkval == false) {
-        for (int i = 1; i < 7; i++) {
-            checksum_buffer += Rdata[i];
-        }
-        checksum_buffer = checksum_buffer & 0x0000007F;
-        checkval = 1;
-        if(checksum_buffer == (Rdata[7] & 0x0000007F)) {
-            button1_buffer = Rdata[1];
-            button2_buffer = Rdata[2];
-            condata[14] = Rdata[3];
-            condata[15] = Rdata[4];
-            condata[16] = Rdata[5];
-            condata[17] = Rdata[6];
+    button1_buffer = Rdata[1];
+    button2_buffer = Rdata[2];
+    condata[14] = Rdata[3];
+    condata[15] = Rdata[4];
+    condata[16] = Rdata[5];
+    condata[17] = Rdata[6];
 
-            int num1 = 16;
-            int num2 = 64;
-            int value1 = 0;
-            int value2 = 0;
+    int num1 = 16;
+    int num2 = 64;
+    int value1 = 0;
+    int value2 = 0;
 
-            for(int i = 5; i >= 1; i--) {
-                value1 = i + 6;
-                if (button1_buffer >= num1) {
-                    condata[value1] = 1;
-                    button1_buffer -= num1;
-                } else {
-                    condata[value1] = 0;
-                }
-                num1 /= 2;
-            }
+    for(int i = 5; i >= 1; i--) {
+        value1 = i + 6;
+        if (button1_buffer >= num1) {
+            condata[value1] = 1;
+            button1_buffer -= num1;
+        } else {
+            condata[value1] = 0;
+        }
+        num1 /= 2;
+    }
 
-            for(int j = 7; j >= 1; j--) {
-                value2 = j - 1;
-                if (button2_buffer - num2 >= 0) {
-                    condata[value2] = 1;
-                    button2_buffer -= num2;
-                } else {
-                    condata[value2] = 0;
-                }
-                num2 /= 2;
-            }
-            if(condata[0]!=0 && condata[1]!=0) {
-                condata[0] = 0;
-                condata[1] = 0;
-                condata[13] = 1;
-            } else if(condata[2]!=0 && condata[3]!=0) {
-                condata[2] = 0;
-                condata[3] = 0;
-                condata[12] = 1;
-            } else {
-                condata[12] = 0;
-                condata[13] = 0;
-            }
+    for(int j = 7; j >= 1; j--) {
+        value2 = j - 1;
+        if (button2_buffer - num2 >= 0) {
+            condata[value2] = 1;
+            button2_buffer -= num2;
+        } else {
+            condata[value2] = 0;
         }
+        num2 /= 2;
+    }
+    if(condata[0]!=0 && condata[1]!=0) {
+        condata[0] = 0;
+        condata[1] = 0;
+        condata[13] = 1;
+    } else if(condata[2]!=0 && condata[3]!=0) {
+        condata[2] = 0;
+        condata[3] = 0;
+        condata[12] = 1;
+    } else {
+        condata[12] = 0;
+        condata[13] = 0;
     }
 }
\ No newline at end of file
--- a/PS3_S.h	Sat Sep 22 11:09:22 2018 +0000
+++ b/PS3_S.h	Thu Sep 27 09:24:36 2018 +0000
@@ -31,10 +31,6 @@
     int button1_buffer;
     int button2_buffer;
     int dataval;
-    int endval;
-    int checkval;
-    int checksum_buffer;
-    int databuffer;
     
 void getdata();
 void checkdata();