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.
Diff: PS3.cpp
- Revision:
- 3:c1318581351c
- Parent:
- 2:a2371f4c6fe8
- Child:
- 4:cfef9ff2d209
--- a/PS3.cpp Thu Sep 07 04:21:05 2017 +0000
+++ b/PS3.cpp Thu Sep 07 04:22:57 2017 +0000
@@ -1,10 +1,11 @@
#include "PS3.h"
-PS3::PS3(I2C *i, char addr){
+PS3::PS3(I2C *i, char addr)
+{
i2c = i;
ADDR = addr;
- for(int i=0;i<21;i++){
+ for(int i=0; i<21; i++) {
DATA_CONTROLLER[i] = 0;
DATA_CONTROLLER_OLD[i] = 0;
}
@@ -20,32 +21,29 @@
//UpDate
DATA_CONTROLLER[CONNECTION] = (data[1] >> 1) & 0x01;
- if(DATA_CONTROLLER[CONNECTION] == 1){
- DATA_CONTROLLER[UP] = (data[0] >> 7) & 0x01;
- DATA_CONTROLLER[RIGHT] = (data[0] >> 6) & 0x01;
- DATA_CONTROLLER[DOWN] = (data[0] >> 5) & 0x01;
- DATA_CONTROLLER[LEFT] = (data[0] >> 4) & 0x01;
- DATA_CONTROLLER[TRIANGLE] = (data[0] >> 3) & 0x01;
- DATA_CONTROLLER[CIRCLE] = (data[0] >> 2) & 0x01;
- DATA_CONTROLLER[CROSS] = (data[0] >> 1) & 0x01;
- DATA_CONTROLLER[SQUARE] = (data[0] >> 0) & 0x01;
- DATA_CONTROLLER[L1] = (data[1] >> 7) & 0x01;
- DATA_CONTROLLER[R1] = (data[1] >> 6) & 0x01;
- DATA_CONTROLLER[SELECT] = (data[1] >> 5) & 0x01;
- DATA_CONTROLLER[START] = (data[1] >> 4) & 0x01;
- DATA_CONTROLLER[L3] = (data[1] >> 3) & 0x01;
- DATA_CONTROLLER[R3] = (data[1] >> 2) & 0x01;
- DATA_CONTROLLER[LeftHatX] = data[2];
- DATA_CONTROLLER[LeftHatY] = data[3];
- DATA_CONTROLLER[RightHatX] = data[4];
- DATA_CONTROLLER[RightHatY] = data[5];
- DATA_CONTROLLER[L2] = data[6];
- DATA_CONTROLLER[R2] = data[7];
+ DATA_CONTROLLER[UP] = (data[0] >> 7) & 0x01;
+ DATA_CONTROLLER[RIGHT] = (data[0] >> 6) & 0x01;
+ DATA_CONTROLLER[DOWN] = (data[0] >> 5) & 0x01;
+ DATA_CONTROLLER[LEFT] = (data[0] >> 4) & 0x01;
+ DATA_CONTROLLER[TRIANGLE] = (data[0] >> 3) & 0x01;
+ DATA_CONTROLLER[CIRCLE] = (data[0] >> 2) & 0x01;
+ DATA_CONTROLLER[CROSS] = (data[0] >> 1) & 0x01;
+ DATA_CONTROLLER[SQUARE] = (data[0] >> 0) & 0x01;
+ DATA_CONTROLLER[L1] = (data[1] >> 7) & 0x01;
+ DATA_CONTROLLER[R1] = (data[1] >> 6) & 0x01;
+ DATA_CONTROLLER[SELECT] = (data[1] >> 5) & 0x01;
+ DATA_CONTROLLER[START] = (data[1] >> 4) & 0x01;
+ DATA_CONTROLLER[L3] = (data[1] >> 3) & 0x01;
+ DATA_CONTROLLER[R3] = (data[1] >> 2) & 0x01;
+ DATA_CONTROLLER[LeftHatX] = data[2];
+ DATA_CONTROLLER[LeftHatY] = data[3];
+ DATA_CONTROLLER[RightHatX] = data[4];
+ DATA_CONTROLLER[RightHatY] = data[5];
+ DATA_CONTROLLER[L2] = data[6];
+ DATA_CONTROLLER[R2] = data[7];
+ if(DATA_CONTROLLER[CONNECTION] == 1) {
return 1;
- }else{
- for(int i=0;i<21;i++){
- DATA_CONTROLLER[i] = 15 <= i && 18 >= i ? 127 : 0;
- }
+ } else {
return 0;
}
}
@@ -63,16 +61,16 @@
{
//mode:0 -> Rising
//mode:1 -> Falling
-
- if(button <= 13){
+
+ if(button <= 13) {
return mode*(DATA_CONTROLLER[button]*!DATA_CONTROLLER_OLD[button])
- + !mode*(!DATA_CONTROLLER[button]*DATA_CONTROLLER_OLD[button]);
+ + !mode*(!DATA_CONTROLLER[button]*DATA_CONTROLLER_OLD[button]);
- }else if( (19<=button) && (button<=20) ){
+ } else if( (19<=button) && (button<=20) ) {
return mode*((DATA_CONTROLLER[button]>127)*!(DATA_CONTROLLER_OLD[button]>127))
- + !mode*(!(DATA_CONTROLLER[button]>127)*(DATA_CONTROLLER_OLD[button]>127));
-
- }else{
+ + !mode*(!(DATA_CONTROLLER[button]>127)*(DATA_CONTROLLER_OLD[button]>127));
+
+ } else {
return 0;
}
}