Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PS4 by
Diff: PS4.cpp
- Revision:
 - 8:73810fa167a8
 - Parent:
 - 7:ffa4066a789d
 - Child:
 - 9:b98be6c2f23e
 
--- a/PS4.cpp	Mon Oct 30 09:03:49 2017 +0000
+++ b/PS4.cpp	Mon Nov 06 08:42:00 2017 +0000
@@ -1,10 +1,9 @@
 #include "PS4.h"
 
-PS4::PS4(I2C *i, char addr)
+PS4::PS4(Serial *i)
 {
-    i2c = i;
-    ADDR = addr;
-
+    serial = i;
+    serial->baud(115200);
     for(int i=0; i<23; i++) {
         DATA_CONTROLLER[i] = 0;
         DATA_CONTROLLER_OLD[i] = 0;
@@ -13,13 +12,18 @@
 
 bool PS4::UpDate()
 {
+
     //Make backup
     memcpy( DATA_CONTROLLER_OLD, DATA_CONTROLLER, sizeof(DATA_CONTROLLER) );
 
     //Get data by I2C
-    int s = i2c->read((ADDR | 1), data, 17);
-
-    if(s == 0) {
+    //int s = i2c->read((ADDR | 1), data, 17);
+    if (serial->getc() == 0x80) {
+        for (int i = 0; i<17; i++) {
+            data[i]  = serial->getc();
+        }
+    }
+    if(/*s == 0*/1) {
 
         //UpDate
         DATA_CONTROLLER[CONNECTION] = (data[0] >> 0) & 0x01;
@@ -45,17 +49,18 @@
         DATA_CONTROLLER[RightHatY] = data[6];
         DATA_CONTROLLER[L2] = data[7];
         DATA_CONTROLLER[R2] = data[8];
-        DATA_TP[X][0] = data[9] >> 8 + data[10];
-        DATA_TP[Y][0] = data[11] >> 8 + data[12];
-        DATA_TP[X][1] = data[13] >> 8 + data[14];
-        DATA_TP[Y][1] = data[15] >> 8 + data[16];
-        
+        DATA_TP[X][0] = (data[9] << 8) + data[10];
+        DATA_TP[Y][0] = (data[11] << 8) + data[12];
+        DATA_TP[X][1] = (data[13] << 8) + data[14];
+        DATA_TP[Y][1] = (data[15] << 8) + data[16];
+
     } else {
         for(int i = 0; i < 23; i++) {
             DATA_CONTROLLER[i] = i >= 15 && i <= 18 ? 127 : 0;
         }
     }
-    return s;
+    //return s;
+    return 0;
 }
 
 int PS4::getPress( CONTROLLER buttom )
    