From 09f19de0d372ac5a2730e9e5d42d556cba7b43b8 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 9 Sep 2012 22:13:52 +0200 Subject: [PATCH] Fixed conflict between PS3USB and PS3BT --- PS3BT.cpp | 55 ++---- PS3BT.h | 162 +---------------- PS3Enums.h | 158 +++++++++++++++++ PS3USB.cpp | 70 +++----- PS3USB.h | 119 +------------ examples/Bluetooth/PS3BT/PS3BT.ino | 254 ++++++++++++--------------- examples/Bluetooth/PS3SPP/PS3SPP.ino | 184 +++++++++---------- examples/PS3USB/PS3USB.ino | 192 +++++++++----------- keywords.txt | 34 ++-- 9 files changed, 494 insertions(+), 734 deletions(-) create mode 100644 PS3Enums.h diff --git a/PS3BT.cpp b/PS3BT.cpp index 65697af5..00375ebd 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -60,20 +60,13 @@ pBtd(p) // pointer to USB class instance - mandatory Reset(); } -bool PS3BT::getButton(Button b) { - if (l2capinbuf == NULL) - return false; - if(PS3MoveConnected) { - if((l2capinbuf[((uint16_t)b >> 8)-1] & ((uint8_t)b & 0xff))) // All the buttons locations are shifted one back on the Move controller - return true; - else - return false; - } else { - if((l2capinbuf[(uint16_t)b >> 8] & ((uint8_t)b & 0xff))) - return true; - else - return false; - } +bool PS3BT::getButtonPress(Button b) { + return (ButtonState & (uint32_t)b); +} +bool PS3BT::getButtonClick(Button b) { + bool click = (ButtonClickState & (uint32_t)b); + ButtonClickState &= ~((uint32_t)b); // clear "click" event + return click; } uint8_t PS3BT::getAnalogButton(AnalogButton a) { if (l2capinbuf == NULL) @@ -231,7 +224,7 @@ void PS3BT::disconnect() { // Use this void to disconnect any of the controllers void PS3BT::ACLData(uint8_t* ACLData) { if(!pBtd->l2capConnectionClaimed && !PS3Connected && !PS3MoveConnected && !PS3NavigationConnected) { if (ACLData[8] == L2CAP_CMD_CONNECTION_REQUEST) { - if((ACLData[12] | (ACLData[13] << 8)) == HID_CTRL_PSM) { + if((ACLData[12] | (ACLData[13] << 8)) == HID_CTRL_PSM) { pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection l2cap_state = L2CAP_WAIT; @@ -366,21 +359,8 @@ void PS3BT::ACLData(uint8_t* ACLData) { //Notify(PSTR("\r\nButtonState"); //PrintHex(ButtonState); - if(ButtonState != OldButtonState) { - buttonChanged = true; - if(ButtonState != 0x00) { - buttonPressed = true; - buttonReleased = false; - } else { - buttonPressed = false; - buttonReleased = true; - } - } - else { - buttonChanged = false; - buttonPressed = false; - buttonReleased = false; - } + if(ButtonState != OldButtonState) + ButtonClickState = ButtonState; OldButtonState = ButtonState; #ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers @@ -583,22 +563,17 @@ void PS3BT::setRumbleOn(Rumble mode) { * 5 - duration_left * 6 - power_left */ - if ((mode & 0x30) > 0) - { + if ((mode & 0x30) > 0) { HIDBuffer[3] = 0xfe; - HIDBuffer[5] = 0xfe; - - if (mode == RumbleHigh) - { + HIDBuffer[5] = 0xfe; + if (mode == RumbleHigh) { HIDBuffer[4] = 0;//low mode off HIDBuffer[6] = 0xff;//high mode on } - else - { + else { HIDBuffer[4] = 0xff;//low mode on HIDBuffer[6] = 0;//high mode off - } - + } HID_Command(HIDBuffer, HID_BUFFERSIZE); } } diff --git a/PS3BT.h b/PS3BT.h index 806193df..12d638cd 100644 --- a/PS3BT.h +++ b/PS3BT.h @@ -19,6 +19,7 @@ #define _ps3bt_h_ #include "BTD.h" +#include "PS3Enums.h" #define HID_BUFFERSIZE 50 // size of the buffer for the Playstation Motion Controller #define OUTPUT_REPORT_BUFFER_SIZE 48 //Size of the output report buffer for the controllers @@ -56,159 +57,6 @@ #define l2cap_disconnect_response_control_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE) #define l2cap_disconnect_response_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) -enum LED { - LED1 = 0x01, - LED2 = 0x02, - LED3 = 0x04, - LED4 = 0x08, - - LED5 = 0x09, - LED6 = 0x0A, - LED7 = 0x0C, - LED8 = 0x0D, - LED9 = 0x0E, - LED10 = 0x0F, -}; -enum Colors { - // Used to set the colors of the move controller - Red = 0xFF0000, // r = 255, g = 0, b = 0 - Green = 0xFF00, // r = 0, g = 255, b = 0 - Blue = 0xFF, // r = 0, g = 0, b = 255 - - Yellow = 0xFFEB04, // r = 255, g = 235, b = 4 - Lightblue = 0xFFFF, // r = 0, g = 255, b = 255 - Purble = 0xFF00FF, // r = 255, g = 0, b = 255 - - White = 0xFFFFFF, // r = 255, g = 255, b = 255 - Off = 0x00, // r = 0, g = 0, b = 0 -}; - -enum Button { - // byte location | bit location - - // Sixaxis Dualshcock 3 & Navigation controller - SELECT = (11 << 8) | 0x01, - L3 = (11 << 8) | 0x02, - R3 = (11 << 8) | 0x04, - START = (11 << 8) | 0x08, - UP = (11 << 8) | 0x10, - RIGHT = (11 << 8) | 0x20, - DOWN = (11 << 8) | 0x40, - LEFT = (11 << 8) | 0x80, - - L2 = (12 << 8) | 0x01, - R2 = (12 << 8) | 0x02, - L1 = (12 << 8) | 0x04, - R1 = (12 << 8) | 0x08, - TRIANGLE = (12 << 8) | 0x10, - CIRCLE = (12 << 8) | 0x20, - CROSS = (12 << 8) | 0x40, - SQUARE = (12 << 8) | 0x80, - - PS = (13 << 8) | 0x01, - - MOVE = (13/*12*/ << 8) | 0x08, // covers 12 bits - we only need to read the top 8 - T = (13/*12*/ << 8) | 0x10, // covers 12 bits - we only need to read the top 8 - - - // These are the true locations for the Move controller, but to make the same syntax for all controllers, it is handled by getButton() -/* - // Playstation Move Controller - SELECT_MOVE = (10 << 8) | 0x01, - START_MOVE = (10 << 8) | 0x08, - - TRIANGLE_MOVE = (11 << 8) | 0x10, - CIRCLE_MOVE = (11 << 8) | 0x20, - CROSS_MOVE = (11 << 8) | 0x40, - SQUARE_MOVE = (11 << 8) | 0x80, - - PS_MOVE = (12 << 8) | 0x01, - MOVE_MOVE = (12 << 8) | 0x08, // covers 12 bits - we only need to read the top 8 - T_MOVE = (12 << 8) | 0x10, // covers 12 bits - we only need to read the top 8 - */ -}; -enum AnalogButton { - //Sixaxis Dualshcock 3 & Navigation controller - UP_ANALOG = 23, - RIGHT_ANALOG = 24, - DOWN_ANALOG = 25, - LEFT_ANALOG = 26, - - L2_ANALOG = 27, - R2_ANALOG = 28, - L1_ANALOG = 29, - R1_ANALOG = 30, - TRIANGLE_ANALOG = 31, - CIRCLE_ANALOG = 32, - CROSS_ANALOG = 33, - SQUARE_ANALOG = 34, - - //Playstation Move Controller - T_ANALOG = 15, // Both at byte 14 (last reading) and byte 15 (current reading) -}; -enum AnalogHat { - LeftHatX = 15, - LeftHatY = 16, - RightHatX = 17, - RightHatY = 18, -}; -enum Sensor { - //Sensors inside the Sixaxis Dualshock 3 controller - aX = 50, - aY = 52, - aZ = 54, - gZ = 56, - - //Sensors inside the move motion controller - it only reads the 2nd frame - aXmove = 28, - aZmove = 30, - aYmove = 32, - - gXmove = 40, - gZmove = 42, - gYmove = 44, - - tempMove = 46, - - mXmove = 47, - mZmove = 49, - mYmove = 50, -}; -enum Angle { - Pitch = 0x01, - Roll = 0x02, -}; -enum Status { - // byte location | bit location - Plugged = (38 << 8) | 0x02, - Unplugged = (38 << 8) | 0x03, - - Charging = (39 << 8) | 0xEE, - NotCharging = (39 << 8) | 0xF1, - Shutdown = (39 << 8) | 0x01, - Dying = (39 << 8) | 0x02, - Low = (39 << 8) | 0x03, - High = (39 << 8) | 0x04, - Full = (39 << 8) | 0x05, - - MoveCharging = (21 << 8) | 0xEE, - MoveNotCharging = (21 << 8) | 0xF1, - MoveShutdown = (21 << 8) | 0x01, - MoveDying = (21 << 8) | 0x02, - MoveLow = (21 << 8) | 0x03, - MoveHigh = (21 << 8) | 0x04, - MoveFull = (21 << 8) | 0x05, - - CableRumble = (40 << 8) | 0x10,//Opperating by USB and rumble is turned on - Cable = (40 << 8) | 0x12,//Opperating by USB and rumble is turned off - BluetoothRumble = (40 << 8) | 0x14,//Opperating by bluetooth and rumble is turned on - Bluetooth = (40 << 8) | 0x16,//Opperating by bluetooth and rumble is turned off -}; -enum Rumble { - RumbleHigh = 0x10, - RumbleLow = 0x20, -}; - class PS3BT : public BluetoothService { public: PS3BT(BTD *pBtd, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0); @@ -220,7 +68,8 @@ public: virtual void disconnect(); // Use this void to disconnect any of the controllers /* PS3 Controller Commands */ - bool getButton(Button b); + bool getButtonPress(Button b); + bool getButtonClick(Button b); uint8_t getAnalogButton(AnalogButton a); uint8_t getAnalogHat(AnalogHat a); int16_t getSensor(Sensor a); @@ -246,9 +95,6 @@ public: bool PS3Connected;// Variable used to indicate if the normal playstation controller is successfully connected bool PS3MoveConnected;// Variable used to indicate if the move controller is successfully connected bool PS3NavigationConnected;// Variable used to indicate if the navigation controller is successfully connected - bool buttonChanged;//Indicate if a button has been changed - bool buttonPressed;//Indicate if a button has been pressed - bool buttonReleased;//Indicate if a button has been released private: /* mandatory members */ @@ -268,6 +114,8 @@ private: uint32_t ButtonState; uint32_t OldButtonState; + uint32_t ButtonClickState; + uint32_t timerHID;// timer used see if there has to be a delay before a new HID command uint32_t timerBulbRumble;// used to continuously set PS3 Move controller Bulb and rumble values diff --git a/PS3Enums.h b/PS3Enums.h new file mode 100644 index 00000000..d5e1906f --- /dev/null +++ b/PS3Enums.h @@ -0,0 +1,158 @@ +/* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved. + + This software may be distributed and modified under the terms of the GNU + General Public License version 2 (GPL2) as published by the Free Software + Foundation and appearing in the file GPL2.TXT included in the packaging of + this file. Please note that GPL2 Section 2[b] requires that all works based + on this software must also be made publicly available under the terms of + the GPL2 ("Copyleft"). + + Contact information + ------------------- + + Kristian Lauszus, TKJ Electronics + Web : http://www.tkjelectronics.com + e-mail : kristianl@tkjelectronics.com + */ + +#ifndef _ps3enums_h +#define _ps3enums_h + +enum LED { + LED1 = 0x01, + LED2 = 0x02, + LED3 = 0x04, + LED4 = 0x08, + + LED5 = 0x09, + LED6 = 0x0A, + LED7 = 0x0C, + LED8 = 0x0D, + LED9 = 0x0E, + LED10 = 0x0F, +}; +enum Colors { + // Used to set the colors of the move controller + Red = 0xFF0000, // r = 255, g = 0, b = 0 + Green = 0xFF00, // r = 0, g = 255, b = 0 + Blue = 0xFF, // r = 0, g = 0, b = 255 + + Yellow = 0xFFEB04, // r = 255, g = 235, b = 4 + Lightblue = 0xFFFF, // r = 0, g = 255, b = 255 + Purble = 0xFF00FF, // r = 255, g = 0, b = 255 + + White = 0xFFFFFF, // r = 255, g = 255, b = 255 + Off = 0x00, // r = 0, g = 0, b = 0 +}; +enum Button { + SELECT = 0x01, + L3 = 0x02, + R3 = 0x04, + START = 0x08, + UP = 0x10, + RIGHT = 0x20, + DOWN = 0x40, + LEFT = 0x80, + + L2 = 0x0100, + R2 = 0x0200, + L1 = 0x0400, + R1 = 0x0800, + TRIANGLE = 0x1000, + CIRCLE = 0x2000, + CROSS = 0x4000, + SQUARE = 0x8000, + + PS = 0x010000, + + MOVE = 0x080000, // covers 12 bits - we only need to read the top 8 + T = 0x100000, // covers 12 bits - we only need to read the top 8 +}; +enum AnalogButton { + // Note that the location is shiftet 9 when it's connected via USB + // Sixaxis Dualshcock 3 & Navigation controller + UP_ANALOG = 23, + RIGHT_ANALOG = 24, + DOWN_ANALOG = 25, + LEFT_ANALOG = 26, + + L2_ANALOG = 27, + R2_ANALOG = 28, + L1_ANALOG = 29, + R1_ANALOG = 30, + TRIANGLE_ANALOG = 31, + CIRCLE_ANALOG = 32, + CROSS_ANALOG = 33, + SQUARE_ANALOG = 34, + + //Playstation Move Controller + T_ANALOG = 15, // Both at byte 14 (last reading) and byte 15 (current reading) +}; +enum AnalogHat { + // Note that the location is shiftet 9 when it's connected via USB + LeftHatX = 15, + LeftHatY = 16, + RightHatX = 17, + RightHatY = 18, +}; +enum Sensor { + // Note that the location is shiftet 9 when it's connected via USB + // Sensors inside the Sixaxis Dualshock 3 controller + aX = 50, + aY = 52, + aZ = 54, + gZ = 56, + + // Sensors inside the Move Motion controller + aXmove = 28, + aZmove = 30, + aYmove = 32, + + gXmove = 40, + gZmove = 42, + gYmove = 44, + + tempMove = 46, + + mXmove = 47, + mZmove = 49, + mYmove = 50, +}; +enum Angle { + // Used to get the angle calculated using atan2 + Pitch = 0x01, + Roll = 0x02, +}; +enum Status { + // Note that the location is shiftet 9 when it's connected via USB + // Byte location | bit location + Plugged = (38 << 8) | 0x02, + Unplugged = (38 << 8) | 0x03, + + Charging = (39 << 8) | 0xEE, + NotCharging = (39 << 8) | 0xF1, + Shutdown = (39 << 8) | 0x01, + Dying = (39 << 8) | 0x02, + Low = (39 << 8) | 0x03, + High = (39 << 8) | 0x04, + Full = (39 << 8) | 0x05, + + MoveCharging = (21 << 8) | 0xEE, + MoveNotCharging = (21 << 8) | 0xF1, + MoveShutdown = (21 << 8) | 0x01, + MoveDying = (21 << 8) | 0x02, + MoveLow = (21 << 8) | 0x03, + MoveHigh = (21 << 8) | 0x04, + MoveFull = (21 << 8) | 0x05, + + CableRumble = (40 << 8) | 0x10,//Opperating by USB and rumble is turned on + Cable = (40 << 8) | 0x12,//Opperating by USB and rumble is turned off + BluetoothRumble = (40 << 8) | 0x14,//Opperating by bluetooth and rumble is turned on + Bluetooth = (40 << 8) | 0x16,//Opperating by bluetooth and rumble is turned off +}; +enum Rumble { + RumbleHigh = 0x10, + RumbleLow = 0x20, +}; + +#endif diff --git a/PS3USB.cpp b/PS3USB.cpp index 91ff9574..c8b05d0a 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -308,58 +308,43 @@ void PS3USB::readReport() { //Notify(PSTR("\r\nButtonState"); //PrintHex(ButtonState); - if(ButtonState != OldButtonState) { - buttonChanged = true; - if(ButtonState != 0x00) { - buttonPressed = true; - buttonReleased = false; - } else { - buttonPressed = false; - buttonReleased = true; - } - } - else { - buttonChanged = false; - buttonPressed = false; - buttonReleased = false; - } - + if(ButtonState != OldButtonState) + ButtonClickState = ButtonState; // Update click state variable OldButtonState = ButtonState; } void PS3USB::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers if (readBuf == NULL) return; - for(uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE;i++) - { + for(uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE;i++) { PrintHex(readBuf[i]); Serial.print(" "); } - Serial.println(""); + Serial.println(); } -bool PS3USB::getButton(Button b) { - if (readBuf == NULL) - return false; - if ((readBuf[(uint16_t)b >> 8] & ((uint8_t)b & 0xff)) > 0) - return true; - else - return false; +bool PS3USB::getButtonPress(Button b) { + return (ButtonState & (uint32_t)b); +} +bool PS3USB::getButtonClick(Button b) { + bool click = (ButtonClickState & (uint32_t)b); + ButtonClickState &= ~((uint32_t)b); // clear "click" event + return click; } uint8_t PS3USB::getAnalogButton(AnalogButton a) { if (readBuf == NULL) return 0; - return (uint8_t)(readBuf[(uint16_t)a]); + return (uint8_t)(readBuf[((uint16_t)a)-9]); } uint8_t PS3USB::getAnalogHat(AnalogHat a) { if (readBuf == NULL) return 0; - return (uint8_t)(readBuf[(uint16_t)a]); + return (uint8_t)(readBuf[((uint16_t)a)-9]); } uint16_t PS3USB::getSensor(Sensor a) { if (readBuf == NULL) return 0; - return ((readBuf[(uint16_t)a] << 8) | readBuf[(uint16_t)a + 1]); + return ((readBuf[((uint16_t)a)-9] << 8) | readBuf[((uint16_t)a + 1)-9]); } double PS3USB::getAngle(Angle a) { if(PS3Connected) { @@ -384,19 +369,17 @@ double PS3USB::getAngle(Angle a) { return angle; } } else - return 0; - + return 0; } bool PS3USB::getStatus(Status c) { if (readBuf == NULL) return false; - if (readBuf[(uint16_t)c >> 8] == ((uint8_t)c & 0xff)) + if (readBuf[((uint16_t)c >> 8)-9] == ((uint8_t)c & 0xff)) return true; return false; } String PS3USB::getStatusString() { - if (PS3Connected || PS3NavigationConnected) - { + if (PS3Connected || PS3NavigationConnected) { char statusOutput[100]; strcpy(statusOutput,"ConnectionStatus: "); @@ -455,22 +438,17 @@ void PS3USB::setRumbleOn(Rumble mode) { * 5 - duration_left * 6 - power_left */ - if ((mode & 0x30) > 0) - { + if ((mode & 0x30) > 0) { writeBuf[1] = 0xfe; - writeBuf[3] = 0xfe; - - if (mode == RumbleHigh) - { + writeBuf[3] = 0xfe; + if (mode == RumbleHigh) { writeBuf[2] = 0;//low mode off writeBuf[4] = 0xff;//high mode on } - else - { + else { writeBuf[2] = 0xff;//low mode on writeBuf[4] = 0;//high mode off } - PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE); } } @@ -498,8 +476,7 @@ void PS3USB::setBdaddr(uint8_t* BDADDR) { pUsb->ctrlReq(bAddress,epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL); #ifdef DEBUG Notify(PSTR("\r\nBluetooth Address was set to: ")); - for(int8_t i = 5; i > 0; i--) - { + for(int8_t i = 5; i > 0; i--) { PrintHex(my_bdaddr[i]); Serial.print(":"); } @@ -560,8 +537,7 @@ void PS3USB::setMoveBdaddr(uint8_t* BDADDR) { pUsb->ctrlReq(bAddress,epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00,11,11, buf, NULL); #ifdef DEBUG Notify(PSTR("\r\nBluetooth Address was set to: ")); - for(int8_t i = 5; i > 0; i--) - { + for(int8_t i = 5; i > 0; i--) { PrintHex(my_bdaddr[i]); Serial.print(":"); } diff --git a/PS3USB.h b/PS3USB.h index 35cae686..0088ccd7 100644 --- a/PS3USB.h +++ b/PS3USB.h @@ -25,6 +25,7 @@ #endif #include "Usb.h" +#include "PS3Enums.h" /* PS3 data taken from descriptors */ #define EP_MAXPKTSIZE 64 // max size for data via USB @@ -52,113 +53,6 @@ #define PS3_MAX_ENDPOINTS 3 -enum LED { - LED1 = 0x01, - LED2 = 0x02, - LED3 = 0x04, - LED4 = 0x08, - - LED5 = 0x09, - LED6 = 0x0A, - LED7 = 0x0C, - LED8 = 0x0D, - LED9 = 0x0E, - LED10 = 0x0F, -}; -enum Colors { - // Used to set the colors of the move controller - Red = 0xFF0000, // r = 255, g = 0, b = 0 - Green = 0xFF00, // r = 0, g = 255, b = 0 - Blue = 0xFF, // r = 0, g = 0, b = 255 - - Yellow = 0xFFEB04, // r = 255, g = 235, b = 4 - Lightblue = 0xFFFF, // r = 0, g = 255, b = 255 - Purble = 0xFF00FF, // r = 255, g = 0, b = 255 - - White = 0xFFFFFF, // r = 255, g = 255, b = 255 - Off = 0x00, // r = 0, g = 0, b = 0 -}; - -enum Button { - // byte location | bit location - - // Sixaxis Dualshcock 3 & Navigation controller - SELECT = (2 << 8) | 0x01, - L3 = (2 << 8) | 0x02, - R3 = (2 << 8) | 0x04, - START = (2 << 8) | 0x08, - UP = (2 << 8) | 0x10, - RIGHT = (2 << 8) | 0x20, - DOWN = (2 << 8) | 0x40, - LEFT = (2 << 8) | 0x80, - - L2 = (3 << 8) | 0x01, - R2 = (3 << 8) | 0x02, - L1 = (3 << 8) | 0x04, - R1 = (3 << 8) | 0x08, - TRIANGLE = (3 << 8) | 0x10, - CIRCLE = (3 << 8) | 0x20, - CROSS = (3 << 8) | 0x40, - SQUARE = (3 << 8) | 0x80, - - PS = (4 << 8) | 0x01, -}; -enum AnalogButton { - // Sixaxis Dualshcock 3 & Navigation controller - UP_ANALOG = 14, - RIGHT_ANALOG = 15, - DOWN_ANALOG = 16, - LEFT_ANALOG = 17, - - L2_ANALOG = 18, - R2_ANALOG = 19, - L1_ANALOG = 20, - R1_ANALOG = 21, - TRIANGLE_ANALOG = 22, - CIRCLE_ANALOG = 23, - CROSS_ANALOG = 24, - SQUARE_ANALOG = 25, -}; -enum AnalogHat { - LeftHatX = 6, - LeftHatY = 7, - RightHatX = 8, - RightHatY = 9, -}; -enum Sensor { - // Sensors inside the Sixaxis Dualshock 3 controller - aX = 41, - aY = 43, - aZ = 45, - gZ = 47, -}; -enum Angle { - Pitch = 0x01, - Roll = 0x02, -}; -enum Status { - // byte location | bit location - Plugged = (29 << 8) | 0x02, - Unplugged = (29 << 8) | 0x03, - - Charging = (30 << 8) | 0xEE, - NotCharging = (30 << 8) | 0xF1, - Shutdown = (30 << 8) | 0x01, - Dying = (30 << 8) | 0x02, - Low = (30 << 8) | 0x03, - High = (30 << 8) | 0x04, - Full = (30 << 8) | 0x05, - - CableRumble = (31 << 8) | 0x10, // Opperating by USB and rumble is turned on - Cable = (31 << 8) | 0x12, // Opperating by USB and rumble is turned off - BluetoothRumble = (31 << 8) | 0x14, // Opperating by bluetooth and rumble is turned on - Bluetooth = (31 << 8) | 0x16, // Opperating by bluetooth and rumble is turned off -}; -enum Rumble { - RumbleHigh = 0x10, - RumbleLow = 0x20, -}; - class PS3USB : public USBDeviceConfig { public: PS3USB(USB *pUsb, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0); @@ -174,7 +68,8 @@ public: void setMoveBdaddr(uint8_t* BDADDR); /* PS3 Controller Commands */ - bool getButton(Button b); + bool getButtonPress(Button b); + bool getButtonClick(Button b); uint8_t getAnalogButton(AnalogButton a); uint8_t getAnalogHat(AnalogHat a); uint16_t getSensor(Sensor a); @@ -198,9 +93,6 @@ public: bool PS3Connected;// Variable used to indicate if the normal playstation controller is successfully connected bool PS3MoveConnected;// Variable used to indicate if the move controller is successfully connected bool PS3NavigationConnected;// Variable used to indicate if the navigation controller is successfully connected */ - bool buttonChanged;//Indicate if a button has been changed - bool buttonPressed;//Indicate if a button has been pressed - bool buttonReleased;//Indicate if a button has been released protected: /* mandatory members */ @@ -214,7 +106,8 @@ private: uint32_t timer; // used to continuously set PS3 Move controller Bulb and rumble values uint32_t ButtonState; - uint32_t OldButtonState; + uint32_t OldButtonState; + uint32_t ButtonClickState; uint8_t my_bdaddr[6]; // Change to your dongles Bluetooth address in the constructor uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data @@ -225,7 +118,7 @@ private: /* Private commands */ void PS3_Command(uint8_t* data, uint16_t nbytes); - void enable_sixaxis();//Command used to enable the Dualshock 3 and Navigation controller to send data via USB + void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via USB void Move_Command(uint8_t* data, uint16_t nbytes); }; #endif diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index 899cc49a..472768bb 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -16,7 +16,6 @@ boolean printAngle; void setup() { Serial.begin(115200); - if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt @@ -28,168 +27,141 @@ void loop() { if(PS3.PS3Connected || PS3.PS3NavigationConnected) { if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) { - if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117) { - Serial.print(F("LeftHatX: ")); - Serial.print(PS3.getAnalogHat(LeftHatX)); - Serial.print("\t"); - } if(PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117) { - Serial.print(F("LeftHatY: ")); - Serial.print(PS3.getAnalogHat(LeftHatY)); - Serial.print("\t"); - } if(PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117) { - Serial.print(F("RightHatX: ")); - Serial.print(PS3.getAnalogHat(RightHatX)); - Serial.print("\t"); - } if(PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) { - Serial.print(F("RightHatY: ")); - Serial.print(PS3.getAnalogHat(RightHatY)); - } - Serial.println(""); + Serial.print(F("\r\nLeftHatX: ")); + Serial.print(PS3.getAnalogHat(LeftHatX)); + Serial.print(F("\tLeftHatY: ")); + Serial.print(PS3.getAnalogHat(LeftHatY)); + Serial.print(F("\tRightHatX: ")); + Serial.print(PS3.getAnalogHat(RightHatX)); + Serial.print(F("\tRightHatY: ")); + Serial.print(PS3.getAnalogHat(RightHatY)); } //Analog button values can be read from almost all buttons if(PS3.getAnalogButton(L2_ANALOG) > 0 || PS3.getAnalogButton(R2_ANALOG) > 0) { - if(PS3.getAnalogButton(L2_ANALOG) > 0) { - Serial.print(F("L2: ")); - Serial.print(PS3.getAnalogButton(L2_ANALOG)); - Serial.print("\t"); - } if(PS3.getAnalogButton(R2_ANALOG) > 0) { - Serial.print(F("R2: ")); - Serial.print(PS3.getAnalogButton(R2_ANALOG)); - } - Serial.println(""); + Serial.print(F("\r\nL2: ")); + Serial.print(PS3.getAnalogButton(L2_ANALOG)); + Serial.print(F("\tR2: ")); + Serial.print(PS3.getAnalogButton(R2_ANALOG)); } + if(PS3.getButtonClick(PS)) { + Serial.print(F("\r\nPS")); + PS3.disconnect(); + } + else { + if(PS3.getButtonClick(TRIANGLE)) + Serial.print(F("\r\nTraingle")); + if(PS3.getButtonClick(CIRCLE)) + Serial.print(F("\r\nCircle")); + if(PS3.getButtonClick(CROSS)) + Serial.print(F("\r\nCross")); + if(PS3.getButtonClick(SQUARE)) + Serial.print(F("\r\nSquare")); - if(PS3.buttonPressed) - { - Serial.print(F("PS3 Controller")); + if(PS3.getButtonClick(UP)) { + Serial.print(F("\r\nUp")); + if(PS3.PS3Connected) { + PS3.setAllOff(); + PS3.setLedOn(LED4); + } + } + if(PS3.getButtonClick(RIGHT)) { + Serial.print(F("\r\nRight")); + if(PS3.PS3Connected) { + PS3.setAllOff(); + PS3.setLedOn(LED1); + } + } + if(PS3.getButtonClick(DOWN)) { + Serial.print(F("\r\nDown")); + if(PS3.PS3Connected) { + PS3.setAllOff(); + PS3.setLedOn(LED2); + } + } + if(PS3.getButtonClick(LEFT)) { + Serial.print(F("\r\nLeft")); + if(PS3.PS3Connected) { + PS3.setAllOff(); + PS3.setLedOn(LED3); + } + } - if(PS3.getButton(PS)) { - Serial.print(F(" - PS")); - PS3.disconnect(); - } else { - if(PS3.getButton(TRIANGLE)) - Serial.print(F(" - Traingle")); - if(PS3.getButton(CIRCLE)) - Serial.print(F(" - Circle")); - if(PS3.getButton(CROSS)) - Serial.print(F(" - Cross")); - if(PS3.getButton(SQUARE)) - Serial.print(F(" - Square")); + if(PS3.getButtonClick(L1)) + Serial.print(F("\r\nL1")); + if(PS3.getButtonClick(L3)) + Serial.print(F("\r\nL3")); + if(PS3.getButtonClick(R1)) + Serial.print(F("\r\nR1")); + if(PS3.getButtonClick(R3)) + Serial.print(F("\r\nR3")); - if(PS3.getButton(UP)) { - Serial.print(F(" - Up")); - if(PS3.PS3Connected) { - PS3.setAllOff(); - PS3.setLedOn(LED4); - } - } if(PS3.getButton(RIGHT)) { - Serial.print(F(" - Right")); - if(PS3.PS3Connected) { - PS3.setAllOff(); - PS3.setLedOn(LED1); - } - } if(PS3.getButton(DOWN)) { - Serial.print(F(" - Down")); - if(PS3.PS3Connected) { - PS3.setAllOff(); - PS3.setLedOn(LED2); - } - } if(PS3.getButton(LEFT)) { - Serial.print(F(" - Left")); - if(PS3.PS3Connected) { - PS3.setAllOff(); - PS3.setLedOn(LED3); - } - } - - if(PS3.getButton(L1)) - Serial.print(F(" - L1")); - //if(PS3.getButton(L2)) - //Serial.print(F(" - L2")); - if(PS3.getButton(L3)) - Serial.print(F(" - L3")); - if(PS3.getButton(R1)) - Serial.print(F(" - R1")); - //if(PS3.getButton(R2)) - //Serial.print(F(" - R2")); - if(PS3.getButton(R3)) - Serial.print(F(" - R3")); - - if(PS3.getButton(SELECT)) { - Serial.print(F(" - Select - ")); - Serial.print(PS3.getStatusString()); - } if(PS3.getButton(START)) { - Serial.print(F(" - Start")); - printAngle = !printAngle; - while(PS3.getButton(START)) - Usb.Task(); - } - Serial.println(""); - } + if(PS3.getButtonClick(SELECT)) { + Serial.print(F("\r\nSelect - ")); + Serial.print(PS3.getStatusString()); + } + if(PS3.getButtonClick(START)) { + Serial.print(F("\r\nStart")); + printAngle = !printAngle; + } } if(printAngle) { - Serial.print(F("Pitch: ")); + Serial.print(F("\r\nPitch: ")); Serial.print(PS3.getAngle(Pitch)); Serial.print(F("\tRoll: ")); - Serial.println(PS3.getAngle(Roll)); + Serial.print(PS3.getAngle(Roll)); } } - else if(PS3.PS3MoveConnected) - { + else if(PS3.PS3MoveConnected) { if(PS3.getAnalogButton(T_ANALOG) > 0) { - Serial.print(F("T: ")); - Serial.println(PS3.getAnalogButton(T_ANALOG)); - } if(PS3.buttonPressed) { - Serial.print(F("PS3 Move Controller")); - - if(PS3.getButton(PS)) { - Serial.print(F(" - PS")); - PS3.disconnect(); - } else { - if(PS3.getButton(SELECT)) { - Serial.print(F(" - Select")); - printTemperature = !printTemperature; - while(PS3.getButton(SELECT)) - Usb.Task(); - } if(PS3.getButton(START)) { - Serial.print(F(" - Start")); - printAngle = !printAngle; - while(PS3.getButton(START)) - Usb.Task(); - } if(PS3.getButton(TRIANGLE)) { - Serial.print(F(" - Triangle")); - PS3.moveSetBulb(Red); - } if(PS3.getButton(CIRCLE)) { - Serial.print(F(" - Circle")); - PS3.moveSetBulb(Green); - } if(PS3.getButton(SQUARE)) { - Serial.print(F(" - Square")); - PS3.moveSetBulb(Blue); - } if(PS3.getButton(CROSS)) { - Serial.print(F(" - Cross")); - PS3.moveSetBulb(Yellow); - } if(PS3.getButton(MOVE)) { - PS3.moveSetBulb(Off); - Serial.print(F(" - Move")); - Serial.print(F(" - ")); - Serial.print(PS3.getStatusString()); - } - //if(PS3.getButton(T)) - //Serial.print(F(" - T")); - - Serial.println(""); + Serial.print(F("\r\nT: ")); + Serial.print(PS3.getAnalogButton(T_ANALOG)); + } + if(PS3.getButtonClick(PS)) { + Serial.print(F("\r\nPS")); + PS3.disconnect(); + } + else { + if(PS3.getButtonClick(SELECT)) { + Serial.print(F("\r\nSelect")); + printTemperature = !printTemperature; + } + if(PS3.getButtonClick(START)) { + Serial.print(F("\r\nStart")); + printAngle = !printAngle; + } + if(PS3.getButtonClick(TRIANGLE)) { + Serial.print(F("\r\nTriangle")); + PS3.moveSetBulb(Red); + } + if(PS3.getButtonClick(CIRCLE)) { + Serial.print(F("\r\nCircle")); + PS3.moveSetBulb(Green); + } + if(PS3.getButtonClick(SQUARE)) { + Serial.print(F("\r\nSquare")); + PS3.moveSetBulb(Blue); + } + if(PS3.getButtonClick(CROSS)) { + Serial.print(F("\r\nCross")); + PS3.moveSetBulb(Yellow); + } + if(PS3.getButtonClick(MOVE)) { + PS3.moveSetBulb(Off); + Serial.print(F("\r\nMove")); + Serial.print(F(" - ")); + Serial.print(PS3.getStatusString()); } } if(printAngle) { - Serial.print(F("Pitch: ")); + Serial.print(F("\r\nPitch: ")); Serial.print(PS3.getAngle(Pitch)); Serial.print(F("\tRoll: ")); - Serial.println(PS3.getAngle(Roll)); + Serial.print(PS3.getAngle(Roll)); } else if(printTemperature) { - Serial.print(F("Temperature: ")); - Serial.println(PS3.getTemperature()); + Serial.print(F("\r\nTemperature: ")); + Serial.print(PS3.getTemperature()); } } } diff --git a/examples/Bluetooth/PS3SPP/PS3SPP.ino b/examples/Bluetooth/PS3SPP/PS3SPP.ino index 10fa0e00..2f567150 100644 --- a/examples/Bluetooth/PS3SPP/PS3SPP.ino +++ b/examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -3,7 +3,7 @@ For more information visit my blog: http://blog.tkjelectronics.dk/ or send me an e-mail: kristianl@tkjelectronics.com */ - + /* Note: You will need a Arduino Mega 1280/2560 to run this sketch, @@ -22,9 +22,7 @@ PS3BT PS3(&Btd); // This will just create the instance //PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch boolean firstMessage = true; - -String analogOutput; // We will store the data in these string so we doesn't overflow the dongle -String digitalOutput; +String output; // We will store the data in these string so we doesn't overflow the dongle void setup() { Serial.begin(115200); // This wil lprint the debugging from the libraries @@ -50,118 +48,96 @@ void loop() { else firstMessage = true; - if(PS3.PS3Connected || PS3.PS3NavigationConnected) { - analogOutput = ""; // Reset analog output string + if(PS3.PS3Connected || PS3.PS3NavigationConnected) { + output = ""; // Reset analog output string if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) { - if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117) { - analogOutput += "LeftHatX: "; - analogOutput += PS3.getAnalogHat(LeftHatX); - analogOutput += "\t"; - } - if(PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117) { - analogOutput += "LeftHatY: "; - analogOutput += PS3.getAnalogHat(LeftHatY); - analogOutput += "\t"; - } - if(PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117) { - analogOutput += "RightHatX: "; - analogOutput += PS3.getAnalogHat(RightHatX); - analogOutput += "\t"; - } - if(PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) { - analogOutput += "RightHatY: "; - analogOutput += PS3.getAnalogHat(RightHatY); - analogOutput += "\t"; - } + output += "LeftHatX: "; + output += PS3.getAnalogHat(LeftHatX); + output += "\tLeftHatY: "; + output += PS3.getAnalogHat(LeftHatY); + output += "\tRightHatX: "; + output += PS3.getAnalogHat(RightHatX); + output += "\tRightHatY: "; + output += PS3.getAnalogHat(RightHatY); } //Analog button values can be read from almost all buttons if(PS3.getAnalogButton(L2_ANALOG) || PS3.getAnalogButton(R2_ANALOG)) { - if(analogOutput != "") - analogOutput += "\r\n"; - if(PS3.getAnalogButton(L2_ANALOG)) { - analogOutput += "L2: "; - analogOutput += PS3.getAnalogButton(L2_ANALOG); - analogOutput += "\t"; - } - if(PS3.getAnalogButton(R2_ANALOG)) { - analogOutput += "R2: "; - analogOutput += PS3.getAnalogButton(R2_ANALOG); - analogOutput += "\t"; - } + if(output != "") + output += "\r\n"; + output += "L2: "; + output += PS3.getAnalogButton(L2_ANALOG); + output += "\tR2: "; + output += PS3.getAnalogButton(R2_ANALOG); } - if(analogOutput != "") { - Serial.println(analogOutput); + if(output != "") { + Serial.println(output); if(SerialBT.connected) - SerialBT.println(analogOutput); + SerialBT.println(output); + output = ""; } + if(PS3.getButtonClick(PS)) { + output += " - PS"; + PS3.disconnect(); + } + else { + if(PS3.getButtonClick(TRIANGLE)) + output += " - Traingle"; + if(PS3.getButtonClick(CIRCLE)) + output += " - Circle"; + if(PS3.getButtonClick(CROSS)) + output += " - Cross"; + if(PS3.getButtonClick(SQUARE)) + output += " - Square"; - if(PS3.buttonPressed) { - digitalOutput = "PS3 Controller"; - if(PS3.getButton(PS)) { - digitalOutput += " - PS"; - PS3.disconnect(); + if(PS3.getButtonClick(UP)) { + output += " - Up"; + if(PS3.PS3Connected) { + PS3.setAllOff(); + PS3.setLedOn(LED4); + } + } + if(PS3.getButtonClick(RIGHT)) { + output += " - Right"; + if(PS3.PS3Connected) { + PS3.setAllOff(); + PS3.setLedOn(LED1); + } + } + if(PS3.getButtonClick(DOWN)) { + output += " - Down"; + if(PS3.PS3Connected) { + PS3.setAllOff(); + PS3.setLedOn(LED2); + } + } + if(PS3.getButtonClick(LEFT)) { + output += " - Left"; + if(PS3.PS3Connected) { + PS3.setAllOff(); + PS3.setLedOn(LED3); + } } - else { - if(PS3.getButton(TRIANGLE)) - digitalOutput += " - Traingle"; - if(PS3.getButton(CIRCLE)) - digitalOutput += " - Circle"; - if(PS3.getButton(CROSS)) - digitalOutput += " - Cross"; - if(PS3.getButton(SQUARE)) - digitalOutput += " - Square"; - if(PS3.getButton(UP)) { - digitalOutput += " - UP"; - if(PS3.PS3Connected) { - PS3.setAllOff(); - PS3.setLedOn(LED4); - } - } - if(PS3.getButton(RIGHT)) { - digitalOutput += " - Right"; - if(PS3.PS3Connected) { - PS3.setAllOff(); - PS3.setLedOn(LED1); - } - } - if(PS3.getButton(DOWN)) { - digitalOutput += " - Down"; - if(PS3.PS3Connected) { - PS3.setAllOff(); - PS3.setLedOn(LED2); - } - } - if(PS3.getButton(LEFT)) { - digitalOutput += " - Left"; - if(PS3.PS3Connected) { - PS3.setAllOff(); - PS3.setLedOn(LED3); - } - } + if(PS3.getButtonClick(L1)) + output += " - L1"; + if(PS3.getButtonClick(L3)) + output += " - L3"; + if(PS3.getButtonClick(R1)) + output += " - R1"; + if(PS3.getButtonClick(R3)) + output += " - R3"; - if(PS3.getButton(L1)) - digitalOutput += " - L1"; - //if(PS3.getButton(L2)) - //digitalOutput += " - L2"; - if(PS3.getButton(L3)) - digitalOutput += " - L3"; - if(PS3.getButton(R1)) - digitalOutput += " - R1"; - //if(PS3.getButton(R2)) - //digitalOutput += " - R2"; - if(PS3.getButton(R3)) - digitalOutput += " - R3"; + if(PS3.getButtonClick(SELECT)) + output += " - Select"; + if(PS3.getButtonClick(START)) + output += " - Start"; - if(PS3.getButton(SELECT)) - digitalOutput += " - Select"; - if(PS3.getButton(START)) - digitalOutput += " - Start"; - - Serial.println(digitalOutput); + if(output != "") { + String string = "PS3 Controller" + output; + Serial.println(string); if(SerialBT.connected) - SerialBT.println(digitalOutput); - } - } + SerialBT.println(string); + } + } } } diff --git a/examples/PS3USB/PS3USB.ino b/examples/PS3USB/PS3USB.ino index 0741d220..a516175e 100644 --- a/examples/PS3USB/PS3USB.ino +++ b/examples/PS3USB/PS3USB.ino @@ -15,7 +15,6 @@ uint8_t state = 0; void setup() { Serial.begin(115200); - if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt @@ -27,156 +26,124 @@ void loop() { if(PS3.PS3Connected || PS3.PS3NavigationConnected) { if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) { - if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117) { - Serial.print(F("LeftHatX: ")); - Serial.print(PS3.getAnalogHat(LeftHatX)); - Serial.print("\t"); - } - if(PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117) { - Serial.print(F("LeftHatY: ")); - Serial.print(PS3.getAnalogHat(LeftHatY)); - Serial.print("\t"); - } - if(PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117) { - Serial.print(F("RightHatX: ")); - Serial.print(PS3.getAnalogHat(RightHatX)); - Serial.print("\t"); - } - if(PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) { - Serial.print(F("RightHatY: ")); - Serial.print(PS3.getAnalogHat(RightHatY)); - } - Serial.println(""); + Serial.print(F("\r\nLeftHatX: ")); + Serial.print(PS3.getAnalogHat(LeftHatX)); + Serial.print(F("\tLeftHatY: ")); + Serial.print(PS3.getAnalogHat(LeftHatY)); + Serial.print(F("\tRightHatX: ")); + Serial.print(PS3.getAnalogHat(RightHatX)); + Serial.print(F("\tRightHatY: ")); + Serial.print(PS3.getAnalogHat(RightHatY)); } - // Analog button values can be read from almost all buttons if(PS3.getAnalogButton(L2_ANALOG) > 0 || PS3.getAnalogButton(R2_ANALOG) > 0) { - if(PS3.getAnalogButton(L2_ANALOG) > 0) { - Serial.print(F("L2: ")); - Serial.print(PS3.getAnalogButton(L2_ANALOG)); - Serial.print("\t"); - } - if(PS3.getAnalogButton(R2_ANALOG) > 0) { - Serial.print(F("R2: ")); - Serial.print(PS3.getAnalogButton(R2_ANALOG)); - } - Serial.println(""); + Serial.print(F("\r\nL2: ")); + Serial.print(PS3.getAnalogButton(L2_ANALOG)); + Serial.print(F("\tR2: ")); + Serial.print(PS3.getAnalogButton(R2_ANALOG)); } + if(PS3.getButtonClick(PS)) + Serial.print(F("\r\nPS")); - if(PS3.buttonPressed) - { - Serial.print(F("PS3 Controller")); + if(PS3.getButtonClick(TRIANGLE)) + Serial.print(F("\r\nTraingle")); + if(PS3.getButtonClick(CIRCLE)) + Serial.print(F("\r\nCircle")); + if(PS3.getButtonClick(CROSS)) + Serial.print(F("\r\nCross")); + if(PS3.getButtonClick(SQUARE)) + Serial.print(F("\r\nSquare")); - if(PS3.getButton(PS)) - Serial.print(F(" - PS")); - - if(PS3.getButton(TRIANGLE)) - Serial.print(F(" - Traingle")); - if(PS3.getButton(CIRCLE)) - Serial.print(F(" - Circle")); - if(PS3.getButton(CROSS)) - Serial.print(F(" - Cross")); - if(PS3.getButton(SQUARE)) - Serial.print(F(" - Square")); + if(PS3.getButtonClick(UP)) { + Serial.print(F("\r\nUp")); + PS3.setAllOff(); + PS3.setLedOn(LED4); + } + if(PS3.getButtonClick(RIGHT)) { + Serial.print(F("\r\nRight")); + PS3.setAllOff(); + PS3.setLedOn(LED1); + } + if(PS3.getButtonClick(DOWN)) { + Serial.print(F("\r\nDown")); + PS3.setAllOff(); + PS3.setLedOn(LED2); + } + if(PS3.getButtonClick(LEFT)) { + Serial.print(F("\r\nLeft")); + PS3.setAllOff(); + PS3.setLedOn(LED3); + } - if(PS3.getButton(UP)) { - Serial.print(F(" - Up")); - PS3.setAllOff(); - PS3.setLedOn(LED4); - } - if(PS3.getButton(RIGHT)) { - Serial.print(F(" - Right")); - PS3.setAllOff(); - PS3.setLedOn(LED1); - } - if(PS3.getButton(DOWN)) { - Serial.print(F(" - Down")); - PS3.setAllOff(); - PS3.setLedOn(LED2); - } - if(PS3.getButton(LEFT)) { - Serial.print(F(" - Left")); - PS3.setAllOff(); - PS3.setLedOn(LED3); - } + if(PS3.getButtonClick(L1)) + Serial.print(F("\r\nL1")); + if(PS3.getButtonClick(L3)) + Serial.print(F("\r\nL3")); + if(PS3.getButtonClick(R1)) + Serial.print(F("\r\nR1")); + if(PS3.getButtonClick(R3)) + Serial.print(F("\r\nR3")); - if(PS3.getButton(L1)) - Serial.print(F(" - L1")); - //if(PS3.getButton(L2)) - //Serial.print(F(" - L2")); - if(PS3.getButton(L3)) - Serial.print(F(" - L3")); - if(PS3.getButton(R1)) - Serial.print(F(" - R1")); - //if(PS3.getButton(R2)) - //Serial.print(F(" - R2")); - if(PS3.getButton(R3)) - Serial.print(F(" - R3")); - - if(PS3.getButton(SELECT)) { - Serial.print(F(" - Select - ")); - Serial.print(PS3.getStatusString()); - } - if(PS3.getButton(START)) { - Serial.print(F(" - Start")); - printAngle = !printAngle; - while(PS3.getButton(START)) - Usb.Task(); - } - Serial.println(""); - } - if(printAngle) { - Serial.print(F("Pitch: ")); - Serial.print(PS3.getAngle(Pitch)); - Serial.print(F("\tRoll: ")); - Serial.println(PS3.getAngle(Roll)); - } + if(PS3.getButtonClick(SELECT)) { + Serial.print(F("\r\nSelect - ")); + Serial.print(PS3.getStatusString()); + } + if(PS3.getButtonClick(START)) { + Serial.print(F("\r\nStart")); + printAngle = !printAngle; + } + } + if(printAngle) { + Serial.print(F("\r\nPitch: ")); + Serial.print(PS3.getAngle(Pitch)); + Serial.print(F("\tRoll: ")); + Serial.print(PS3.getAngle(Roll)); } else if(PS3.PS3MoveConnected) { // One can only set the color of the bulb, set the rumble, set and get the bluetooth address and calibrate the magnetometer via USB switch(state) { - case 0: + case 0: PS3.moveSetRumble(0); PS3.moveSetBulb(Off); state = 1; break; - - case 1: + + case 1: PS3.moveSetRumble(75); PS3.moveSetBulb(Red); state = 2; break; - - case 2: + + case 2: PS3.moveSetRumble(125); PS3.moveSetBulb(Green); state = 3; break; - - case 3: + + case 3: PS3.moveSetRumble(150); PS3.moveSetBulb(Blue); state = 4; break; - - case 4: + + case 4: PS3.moveSetRumble(175); PS3.moveSetBulb(Yellow); state = 5; break; - - case 5: + + case 5: PS3.moveSetRumble(200); PS3.moveSetBulb(Lightblue); state = 6; break; - - case 6: + + case 6: PS3.moveSetRumble(225); PS3.moveSetBulb(Purble); state = 7; break; - - case 7: + + case 7: PS3.moveSetRumble(250); PS3.moveSetBulb(White); state = 0; @@ -185,4 +152,3 @@ void loop() { delay(1000); } } - diff --git a/keywords.txt b/keywords.txt index 3e8f4346..fe595fd2 100644 --- a/keywords.txt +++ b/keywords.txt @@ -6,40 +6,38 @@ # Datatypes (KEYWORD1) #################################################### -PS3BT KEYWORD1 +PS3BT KEYWORD1 PS3USB KEYWORD1 #################################################### # Methods and Functions (KEYWORD2) #################################################### -setBdaddr KEYWORD2 +setBdaddr KEYWORD2 setMoveBdaddr KEYWORD2 -getButton KEYWORD2 +getButtonPress KEYWORD2 +getButtonClick KEYWORD2 getAnalogButton KEYWORD2 getAnalogHat KEYWORD2 -getSensor KEYWORD2 -getAngle KEYWORD2 -getStatus KEYWORD2 +getSensor KEYWORD2 +getAngle KEYWORD2 +getStatus KEYWORD2 getStatusString KEYWORD2 getTemperature KEYWORD2 -disconnect KEYWORD2 +disconnect KEYWORD2 -setAllOff KEYWORD2 +setAllOff KEYWORD2 setRumbleOff KEYWORD2 -setRumbleOn KEYWORD2 -setLedOff KEYWORD2 -setLedOn KEYWORD2 +setRumbleOn KEYWORD2 +setLedOff KEYWORD2 +setLedOn KEYWORD2 setLedToggle KEYWORD2 -moveSetBulb KEYWORD2 +moveSetBulb KEYWORD2 moveSetRumble KEYWORD2 -PS3Connected KEYWORD2 -PS3MoveConnected KEYWORD2 +PS3Connected KEYWORD2 +PS3MoveConnected KEYWORD2 PS3NavigationConnected KEYWORD2 -buttonChanged KEYWORD2 -buttonPressed KEYWORD2 -buttonReleased KEYWORD2 watingForConnection KEYWORD2 @@ -220,8 +218,6 @@ WII KEYWORD1 wiimoteConnected KEYWORD2 nunchuckConnected KEYWORD2 motionPlusConnected KEYWORD2 -getButtonPress KEYWORD2 -getButtonClick KEYWORD2 setRumbleToggle KEYWORD2 getPitch KEYWORD2 getRoll KEYWORD2