PS4 controller with IM315

Dependents:  

Files at this revision

API Documentation at this revision

Comitter:
m2130
Date:
Wed Oct 12 09:35:15 2022 +0000
Parent:
1:090d61e465d7
Commit message:
hage;

Changed in this revision

IM315PS4.cpp Show annotated file Show diff for this revision Revisions of this file
IM315PS4.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/IM315PS4.cpp	Sat Aug 06 07:24:24 2022 +0000
+++ b/IM315PS4.cpp	Wed Oct 12 09:35:15 2022 +0000
@@ -2,6 +2,7 @@
 
 IM315PS4::IM315PS4(PinName TX, PinName RX){
     i = 0;
+    flag = false;
     len = 17;
     val = ':';
     data = new uint8_t[len];
@@ -16,6 +17,7 @@
 
 IM315PS4::IM315PS4(PinName TX, PinName RX, int baud){
     i = 0;
+    flag = false;
     len = 17;
     val = ':';
     data = new uint8_t[len];
@@ -45,6 +47,7 @@
         }
         if(i >= len){
             if(data[0] == val){
+                flag = !flag;
                 DATA[0] = ASCII(data[1], data[2]);
                 DATA[1] = ASCII(data[3], data[4]);
                 DATA[2] = ASCII(data[5], data[6]);
@@ -99,6 +102,10 @@
 }
 void IM315PS4::data_print(){_pc -> printf("%2x %2x %2x %2x %2x %2x %2x %2x\n", DATA[0], DATA[1], DATA[2], DATA[3], DATA[4], DATA[5], DATA[6], DATA[7]);}
 
+bool IM315PS4::available(){
+    return flag;
+}
+
 bool IM315PS4::up(){return DATA[1] & UP ? 1 : 0;}
 
 bool IM315PS4::right(){return DATA[1] & RIGHT ? 1 : 0;}
--- a/IM315PS4.hpp	Sat Aug 06 07:24:24 2022 +0000
+++ b/IM315PS4.hpp	Wed Oct 12 09:35:15 2022 +0000
@@ -57,6 +57,7 @@
     IM315PS4(PinName TX, PinName RX, int baud);    //マイコン ~ PC間のボーレート指定あり
     void button_state();                           //全ボタン, スティックの状態表示
     void data_print();
+    bool available();
     bool up();
     bool right();
     bool left();
@@ -87,6 +88,7 @@
     uint8_t *DATA;
     void get();
     uint8_t ASCII(uint8_t data1, uint8_t data2);
+    bool flag;
     int i;
     int val;
     int len;