Fixed conflict between PS3USB and PS3BT

This commit is contained in:
Kristian Lauszus 2012-09-09 22:13:52 +02:00
parent 5a424b5523
commit 09f19de0d3
9 changed files with 494 additions and 734 deletions

View file

@ -60,20 +60,13 @@ pBtd(p) // pointer to USB class instance - mandatory
Reset(); Reset();
} }
bool PS3BT::getButton(Button b) { bool PS3BT::getButtonPress(Button b) {
if (l2capinbuf == NULL) return (ButtonState & (uint32_t)b);
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::getButtonClick(Button b) {
bool click = (ButtonClickState & (uint32_t)b);
ButtonClickState &= ~((uint32_t)b); // clear "click" event
return click;
} }
uint8_t PS3BT::getAnalogButton(AnalogButton a) { uint8_t PS3BT::getAnalogButton(AnalogButton a) {
if (l2capinbuf == NULL) if (l2capinbuf == NULL)
@ -366,21 +359,8 @@ void PS3BT::ACLData(uint8_t* ACLData) {
//Notify(PSTR("\r\nButtonState"); //Notify(PSTR("\r\nButtonState");
//PrintHex<uint32_t>(ButtonState); //PrintHex<uint32_t>(ButtonState);
if(ButtonState != OldButtonState) { if(ButtonState != OldButtonState)
buttonChanged = true; ButtonClickState = ButtonState;
if(ButtonState != 0x00) {
buttonPressed = true;
buttonReleased = false;
} else {
buttonPressed = false;
buttonReleased = true;
}
}
else {
buttonChanged = false;
buttonPressed = false;
buttonReleased = false;
}
OldButtonState = ButtonState; OldButtonState = ButtonState;
#ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers #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 * 5 - duration_left
* 6 - power_left * 6 - power_left
*/ */
if ((mode & 0x30) > 0) if ((mode & 0x30) > 0) {
{
HIDBuffer[3] = 0xfe; HIDBuffer[3] = 0xfe;
HIDBuffer[5] = 0xfe; HIDBuffer[5] = 0xfe;
if (mode == RumbleHigh) {
if (mode == RumbleHigh)
{
HIDBuffer[4] = 0;//low mode off HIDBuffer[4] = 0;//low mode off
HIDBuffer[6] = 0xff;//high mode on HIDBuffer[6] = 0xff;//high mode on
} }
else else {
{
HIDBuffer[4] = 0xff;//low mode on HIDBuffer[4] = 0xff;//low mode on
HIDBuffer[6] = 0;//high mode off HIDBuffer[6] = 0;//high mode off
} }
HID_Command(HIDBuffer, HID_BUFFERSIZE); HID_Command(HIDBuffer, HID_BUFFERSIZE);
} }
} }

162
PS3BT.h
View file

@ -19,6 +19,7 @@
#define _ps3bt_h_ #define _ps3bt_h_
#include "BTD.h" #include "BTD.h"
#include "PS3Enums.h"
#define HID_BUFFERSIZE 50 // size of the buffer for the Playstation Motion Controller #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 #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_control_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)
#define l2cap_disconnect_response_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_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 { class PS3BT : public BluetoothService {
public: 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); 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 virtual void disconnect(); // Use this void to disconnect any of the controllers
/* PS3 Controller Commands */ /* PS3 Controller Commands */
bool getButton(Button b); bool getButtonPress(Button b);
bool getButtonClick(Button b);
uint8_t getAnalogButton(AnalogButton a); uint8_t getAnalogButton(AnalogButton a);
uint8_t getAnalogHat(AnalogHat a); uint8_t getAnalogHat(AnalogHat a);
int16_t getSensor(Sensor 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 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 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 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: private:
/* mandatory members */ /* mandatory members */
@ -268,6 +114,8 @@ private:
uint32_t ButtonState; uint32_t ButtonState;
uint32_t OldButtonState; 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 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 uint32_t timerBulbRumble;// used to continuously set PS3 Move controller Bulb and rumble values

158
PS3Enums.h Normal file
View file

@ -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

View file

@ -308,58 +308,43 @@ void PS3USB::readReport() {
//Notify(PSTR("\r\nButtonState"); //Notify(PSTR("\r\nButtonState");
//PrintHex<uint32_t>(ButtonState); //PrintHex<uint32_t>(ButtonState);
if(ButtonState != OldButtonState) { if(ButtonState != OldButtonState)
buttonChanged = true; ButtonClickState = ButtonState; // Update click state variable
if(ButtonState != 0x00) {
buttonPressed = true;
buttonReleased = false;
} else {
buttonPressed = false;
buttonReleased = true;
}
}
else {
buttonChanged = false;
buttonPressed = false;
buttonReleased = false;
}
OldButtonState = ButtonState; OldButtonState = ButtonState;
} }
void PS3USB::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers void PS3USB::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
if (readBuf == NULL) if (readBuf == NULL)
return; return;
for(uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE;i++) for(uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE;i++) {
{
PrintHex<uint8_t>(readBuf[i]); PrintHex<uint8_t>(readBuf[i]);
Serial.print(" "); Serial.print(" ");
} }
Serial.println(""); Serial.println();
} }
bool PS3USB::getButton(Button b) { bool PS3USB::getButtonPress(Button b) {
if (readBuf == NULL) return (ButtonState & (uint32_t)b);
return false; }
if ((readBuf[(uint16_t)b >> 8] & ((uint8_t)b & 0xff)) > 0) bool PS3USB::getButtonClick(Button b) {
return true; bool click = (ButtonClickState & (uint32_t)b);
else ButtonClickState &= ~((uint32_t)b); // clear "click" event
return false; return click;
} }
uint8_t PS3USB::getAnalogButton(AnalogButton a) { uint8_t PS3USB::getAnalogButton(AnalogButton a) {
if (readBuf == NULL) if (readBuf == NULL)
return 0; return 0;
return (uint8_t)(readBuf[(uint16_t)a]); return (uint8_t)(readBuf[((uint16_t)a)-9]);
} }
uint8_t PS3USB::getAnalogHat(AnalogHat a) { uint8_t PS3USB::getAnalogHat(AnalogHat a) {
if (readBuf == NULL) if (readBuf == NULL)
return 0; return 0;
return (uint8_t)(readBuf[(uint16_t)a]); return (uint8_t)(readBuf[((uint16_t)a)-9]);
} }
uint16_t PS3USB::getSensor(Sensor a) { uint16_t PS3USB::getSensor(Sensor a) {
if (readBuf == NULL) if (readBuf == NULL)
return 0; 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) { double PS3USB::getAngle(Angle a) {
if(PS3Connected) { if(PS3Connected) {
@ -385,18 +370,16 @@ double PS3USB::getAngle(Angle a) {
} }
} else } else
return 0; return 0;
} }
bool PS3USB::getStatus(Status c) { bool PS3USB::getStatus(Status c) {
if (readBuf == NULL) if (readBuf == NULL)
return false; 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 true;
return false; return false;
} }
String PS3USB::getStatusString() { String PS3USB::getStatusString() {
if (PS3Connected || PS3NavigationConnected) if (PS3Connected || PS3NavigationConnected) {
{
char statusOutput[100]; char statusOutput[100];
strcpy(statusOutput,"ConnectionStatus: "); strcpy(statusOutput,"ConnectionStatus: ");
@ -455,22 +438,17 @@ void PS3USB::setRumbleOn(Rumble mode) {
* 5 - duration_left * 5 - duration_left
* 6 - power_left * 6 - power_left
*/ */
if ((mode & 0x30) > 0) if ((mode & 0x30) > 0) {
{
writeBuf[1] = 0xfe; writeBuf[1] = 0xfe;
writeBuf[3] = 0xfe; writeBuf[3] = 0xfe;
if (mode == RumbleHigh) {
if (mode == RumbleHigh)
{
writeBuf[2] = 0;//low mode off writeBuf[2] = 0;//low mode off
writeBuf[4] = 0xff;//high mode on writeBuf[4] = 0xff;//high mode on
} }
else else {
{
writeBuf[2] = 0xff;//low mode on writeBuf[2] = 0xff;//low mode on
writeBuf[4] = 0;//high mode off writeBuf[4] = 0;//high mode off
} }
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE); 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); pUsb->ctrlReq(bAddress,epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nBluetooth Address was set to: ")); 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<uint8_t>(my_bdaddr[i]); PrintHex<uint8_t>(my_bdaddr[i]);
Serial.print(":"); 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); pUsb->ctrlReq(bAddress,epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00,11,11, buf, NULL);
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nBluetooth Address was set to: ")); 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<uint8_t>(my_bdaddr[i]); PrintHex<uint8_t>(my_bdaddr[i]);
Serial.print(":"); Serial.print(":");
} }

115
PS3USB.h
View file

@ -25,6 +25,7 @@
#endif #endif
#include "Usb.h" #include "Usb.h"
#include "PS3Enums.h"
/* PS3 data taken from descriptors */ /* PS3 data taken from descriptors */
#define EP_MAXPKTSIZE 64 // max size for data via USB #define EP_MAXPKTSIZE 64 // max size for data via USB
@ -52,113 +53,6 @@
#define PS3_MAX_ENDPOINTS 3 #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 { class PS3USB : public USBDeviceConfig {
public: 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); 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); void setMoveBdaddr(uint8_t* BDADDR);
/* PS3 Controller Commands */ /* PS3 Controller Commands */
bool getButton(Button b); bool getButtonPress(Button b);
bool getButtonClick(Button b);
uint8_t getAnalogButton(AnalogButton a); uint8_t getAnalogButton(AnalogButton a);
uint8_t getAnalogHat(AnalogHat a); uint8_t getAnalogHat(AnalogHat a);
uint16_t getSensor(Sensor 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 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 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 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: protected:
/* mandatory members */ /* mandatory members */
@ -215,6 +107,7 @@ private:
uint32_t ButtonState; 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 my_bdaddr[6]; // Change to your dongles Bluetooth address in the constructor
uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data

View file

@ -16,7 +16,6 @@ boolean printAngle;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
if (Usb.Init() == -1) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while(1); //halt
@ -28,168 +27,141 @@ void loop() {
if(PS3.PS3Connected || PS3.PS3NavigationConnected) { 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 || 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("\r\nLeftHatX: "));
Serial.print(F("LeftHatX: "));
Serial.print(PS3.getAnalogHat(LeftHatX)); Serial.print(PS3.getAnalogHat(LeftHatX));
Serial.print("\t"); Serial.print(F("\tLeftHatY: "));
} if(PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117) {
Serial.print(F("LeftHatY: "));
Serial.print(PS3.getAnalogHat(LeftHatY)); Serial.print(PS3.getAnalogHat(LeftHatY));
Serial.print("\t"); Serial.print(F("\tRightHatX: "));
} if(PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117) {
Serial.print(F("RightHatX: "));
Serial.print(PS3.getAnalogHat(RightHatX)); Serial.print(PS3.getAnalogHat(RightHatX));
Serial.print("\t"); Serial.print(F("\tRightHatY: "));
} if(PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) {
Serial.print(F("RightHatY: "));
Serial.print(PS3.getAnalogHat(RightHatY)); Serial.print(PS3.getAnalogHat(RightHatY));
} }
Serial.println("");
}
//Analog button values can be read from almost all buttons //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 || PS3.getAnalogButton(R2_ANALOG) > 0) {
if(PS3.getAnalogButton(L2_ANALOG) > 0) { Serial.print(F("\r\nL2: "));
Serial.print(F("L2: "));
Serial.print(PS3.getAnalogButton(L2_ANALOG)); Serial.print(PS3.getAnalogButton(L2_ANALOG));
Serial.print("\t"); Serial.print(F("\tR2: "));
} if(PS3.getAnalogButton(R2_ANALOG) > 0) {
Serial.print(F("R2: "));
Serial.print(PS3.getAnalogButton(R2_ANALOG)); Serial.print(PS3.getAnalogButton(R2_ANALOG));
} }
Serial.println(""); if(PS3.getButtonClick(PS)) {
} Serial.print(F("\r\nPS"));
if(PS3.buttonPressed)
{
Serial.print(F("PS3 Controller"));
if(PS3.getButton(PS)) {
Serial.print(F(" - PS"));
PS3.disconnect(); PS3.disconnect();
} else { }
if(PS3.getButton(TRIANGLE)) else {
Serial.print(F(" - Traingle")); if(PS3.getButtonClick(TRIANGLE))
if(PS3.getButton(CIRCLE)) Serial.print(F("\r\nTraingle"));
Serial.print(F(" - Circle")); if(PS3.getButtonClick(CIRCLE))
if(PS3.getButton(CROSS)) Serial.print(F("\r\nCircle"));
Serial.print(F(" - Cross")); if(PS3.getButtonClick(CROSS))
if(PS3.getButton(SQUARE)) Serial.print(F("\r\nCross"));
Serial.print(F(" - Square")); if(PS3.getButtonClick(SQUARE))
Serial.print(F("\r\nSquare"));
if(PS3.getButton(UP)) { if(PS3.getButtonClick(UP)) {
Serial.print(F(" - Up")); Serial.print(F("\r\nUp"));
if(PS3.PS3Connected) { if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED4); PS3.setLedOn(LED4);
} }
} if(PS3.getButton(RIGHT)) { }
Serial.print(F(" - Right")); if(PS3.getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight"));
if(PS3.PS3Connected) { if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED1); PS3.setLedOn(LED1);
} }
} if(PS3.getButton(DOWN)) { }
Serial.print(F(" - Down")); if(PS3.getButtonClick(DOWN)) {
Serial.print(F("\r\nDown"));
if(PS3.PS3Connected) { if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED2); PS3.setLedOn(LED2);
} }
} if(PS3.getButton(LEFT)) { }
Serial.print(F(" - Left")); if(PS3.getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft"));
if(PS3.PS3Connected) { if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED3); PS3.setLedOn(LED3);
} }
} }
if(PS3.getButton(L1)) if(PS3.getButtonClick(L1))
Serial.print(F(" - L1")); Serial.print(F("\r\nL1"));
//if(PS3.getButton(L2)) if(PS3.getButtonClick(L3))
//Serial.print(F(" - L2")); Serial.print(F("\r\nL3"));
if(PS3.getButton(L3)) if(PS3.getButtonClick(R1))
Serial.print(F(" - L3")); Serial.print(F("\r\nR1"));
if(PS3.getButton(R1)) if(PS3.getButtonClick(R3))
Serial.print(F(" - R1")); Serial.print(F("\r\nR3"));
//if(PS3.getButton(R2))
//Serial.print(F(" - R2"));
if(PS3.getButton(R3))
Serial.print(F(" - R3"));
if(PS3.getButton(SELECT)) { if(PS3.getButtonClick(SELECT)) {
Serial.print(F(" - Select - ")); Serial.print(F("\r\nSelect - "));
Serial.print(PS3.getStatusString()); 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(START)) {
Serial.print(F("\r\nStart"));
printAngle = !printAngle;
} }
} }
if(printAngle) { if(printAngle) {
Serial.print(F("Pitch: ")); Serial.print(F("\r\nPitch: "));
Serial.print(PS3.getAngle(Pitch)); Serial.print(PS3.getAngle(Pitch));
Serial.print(F("\tRoll: ")); 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) { if(PS3.getAnalogButton(T_ANALOG) > 0) {
Serial.print(F("T: ")); Serial.print(F("\r\nT: "));
Serial.println(PS3.getAnalogButton(T_ANALOG)); Serial.print(PS3.getAnalogButton(T_ANALOG));
} if(PS3.buttonPressed) { }
Serial.print(F("PS3 Move Controller")); if(PS3.getButtonClick(PS)) {
Serial.print(F("\r\nPS"));
if(PS3.getButton(PS)) {
Serial.print(F(" - PS"));
PS3.disconnect(); PS3.disconnect();
} else { }
if(PS3.getButton(SELECT)) { else {
Serial.print(F(" - Select")); if(PS3.getButtonClick(SELECT)) {
Serial.print(F("\r\nSelect"));
printTemperature = !printTemperature; printTemperature = !printTemperature;
while(PS3.getButton(SELECT)) }
Usb.Task(); if(PS3.getButtonClick(START)) {
} if(PS3.getButton(START)) { Serial.print(F("\r\nStart"));
Serial.print(F(" - Start"));
printAngle = !printAngle; printAngle = !printAngle;
while(PS3.getButton(START)) }
Usb.Task(); if(PS3.getButtonClick(TRIANGLE)) {
} if(PS3.getButton(TRIANGLE)) { Serial.print(F("\r\nTriangle"));
Serial.print(F(" - Triangle"));
PS3.moveSetBulb(Red); PS3.moveSetBulb(Red);
} if(PS3.getButton(CIRCLE)) { }
Serial.print(F(" - Circle")); if(PS3.getButtonClick(CIRCLE)) {
Serial.print(F("\r\nCircle"));
PS3.moveSetBulb(Green); PS3.moveSetBulb(Green);
} if(PS3.getButton(SQUARE)) { }
Serial.print(F(" - Square")); if(PS3.getButtonClick(SQUARE)) {
Serial.print(F("\r\nSquare"));
PS3.moveSetBulb(Blue); PS3.moveSetBulb(Blue);
} if(PS3.getButton(CROSS)) { }
Serial.print(F(" - Cross")); if(PS3.getButtonClick(CROSS)) {
Serial.print(F("\r\nCross"));
PS3.moveSetBulb(Yellow); PS3.moveSetBulb(Yellow);
} if(PS3.getButton(MOVE)) { }
if(PS3.getButtonClick(MOVE)) {
PS3.moveSetBulb(Off); PS3.moveSetBulb(Off);
Serial.print(F(" - Move")); Serial.print(F("\r\nMove"));
Serial.print(F(" - ")); Serial.print(F(" - "));
Serial.print(PS3.getStatusString()); Serial.print(PS3.getStatusString());
} }
//if(PS3.getButton(T))
//Serial.print(F(" - T"));
Serial.println("");
}
} }
if(printAngle) { if(printAngle) {
Serial.print(F("Pitch: ")); Serial.print(F("\r\nPitch: "));
Serial.print(PS3.getAngle(Pitch)); Serial.print(PS3.getAngle(Pitch));
Serial.print(F("\tRoll: ")); Serial.print(F("\tRoll: "));
Serial.println(PS3.getAngle(Roll)); Serial.print(PS3.getAngle(Roll));
} }
else if(printTemperature) { else if(printTemperature) {
Serial.print(F("Temperature: ")); Serial.print(F("\r\nTemperature: "));
Serial.println(PS3.getTemperature()); Serial.print(PS3.getTemperature());
} }
} }
} }

View file

@ -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 //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; boolean firstMessage = true;
String output; // We will store the data in these string so we doesn't overflow the dongle
String analogOutput; // We will store the data in these string so we doesn't overflow the dongle
String digitalOutput;
void setup() { void setup() {
Serial.begin(115200); // This wil lprint the debugging from the libraries Serial.begin(115200); // This wil lprint the debugging from the libraries
@ -51,116 +49,94 @@ void loop() {
firstMessage = true; firstMessage = true;
if(PS3.PS3Connected || PS3.PS3NavigationConnected) { if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
analogOutput = ""; // Reset analog output string 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 || 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) { output += "LeftHatX: ";
analogOutput += "LeftHatX: "; output += PS3.getAnalogHat(LeftHatX);
analogOutput += PS3.getAnalogHat(LeftHatX); output += "\tLeftHatY: ";
analogOutput += "\t"; output += PS3.getAnalogHat(LeftHatY);
} output += "\tRightHatX: ";
if(PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117) { output += PS3.getAnalogHat(RightHatX);
analogOutput += "LeftHatY: "; output += "\tRightHatY: ";
analogOutput += PS3.getAnalogHat(LeftHatY); output += PS3.getAnalogHat(RightHatY);
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";
}
} }
//Analog button values can be read from almost all buttons //Analog button values can be read from almost all buttons
if(PS3.getAnalogButton(L2_ANALOG) || PS3.getAnalogButton(R2_ANALOG)) { if(PS3.getAnalogButton(L2_ANALOG) || PS3.getAnalogButton(R2_ANALOG)) {
if(analogOutput != "") if(output != "")
analogOutput += "\r\n"; output += "\r\n";
if(PS3.getAnalogButton(L2_ANALOG)) { output += "L2: ";
analogOutput += "L2: "; output += PS3.getAnalogButton(L2_ANALOG);
analogOutput += PS3.getAnalogButton(L2_ANALOG); output += "\tR2: ";
analogOutput += "\t"; output += PS3.getAnalogButton(R2_ANALOG);
} }
if(PS3.getAnalogButton(R2_ANALOG)) { if(output != "") {
analogOutput += "R2: "; Serial.println(output);
analogOutput += PS3.getAnalogButton(R2_ANALOG);
analogOutput += "\t";
}
}
if(analogOutput != "") {
Serial.println(analogOutput);
if(SerialBT.connected) if(SerialBT.connected)
SerialBT.println(analogOutput); SerialBT.println(output);
output = "";
} }
if(PS3.getButtonClick(PS)) {
if(PS3.buttonPressed) { output += " - PS";
digitalOutput = "PS3 Controller";
if(PS3.getButton(PS)) {
digitalOutput += " - PS";
PS3.disconnect(); PS3.disconnect();
} }
else { else {
if(PS3.getButton(TRIANGLE)) if(PS3.getButtonClick(TRIANGLE))
digitalOutput += " - Traingle"; output += " - Traingle";
if(PS3.getButton(CIRCLE)) if(PS3.getButtonClick(CIRCLE))
digitalOutput += " - Circle"; output += " - Circle";
if(PS3.getButton(CROSS)) if(PS3.getButtonClick(CROSS))
digitalOutput += " - Cross"; output += " - Cross";
if(PS3.getButton(SQUARE)) if(PS3.getButtonClick(SQUARE))
digitalOutput += " - Square"; output += " - Square";
if(PS3.getButton(UP)) { if(PS3.getButtonClick(UP)) {
digitalOutput += " - UP"; output += " - Up";
if(PS3.PS3Connected) { if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED4); PS3.setLedOn(LED4);
} }
} }
if(PS3.getButton(RIGHT)) { if(PS3.getButtonClick(RIGHT)) {
digitalOutput += " - Right"; output += " - Right";
if(PS3.PS3Connected) { if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED1); PS3.setLedOn(LED1);
} }
} }
if(PS3.getButton(DOWN)) { if(PS3.getButtonClick(DOWN)) {
digitalOutput += " - Down"; output += " - Down";
if(PS3.PS3Connected) { if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED2); PS3.setLedOn(LED2);
} }
} }
if(PS3.getButton(LEFT)) { if(PS3.getButtonClick(LEFT)) {
digitalOutput += " - Left"; output += " - Left";
if(PS3.PS3Connected) { if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED3); PS3.setLedOn(LED3);
} }
} }
if(PS3.getButton(L1)) if(PS3.getButtonClick(L1))
digitalOutput += " - L1"; output += " - L1";
//if(PS3.getButton(L2)) if(PS3.getButtonClick(L3))
//digitalOutput += " - L2"; output += " - L3";
if(PS3.getButton(L3)) if(PS3.getButtonClick(R1))
digitalOutput += " - L3"; output += " - R1";
if(PS3.getButton(R1)) if(PS3.getButtonClick(R3))
digitalOutput += " - R1"; output += " - R3";
//if(PS3.getButton(R2))
//digitalOutput += " - R2";
if(PS3.getButton(R3))
digitalOutput += " - R3";
if(PS3.getButton(SELECT)) if(PS3.getButtonClick(SELECT))
digitalOutput += " - Select"; output += " - Select";
if(PS3.getButton(START)) if(PS3.getButtonClick(START))
digitalOutput += " - Start"; output += " - Start";
Serial.println(digitalOutput); if(output != "") {
String string = "PS3 Controller" + output;
Serial.println(string);
if(SerialBT.connected) if(SerialBT.connected)
SerialBT.println(digitalOutput); SerialBT.println(string);
} }
} }
} }

View file

@ -15,7 +15,6 @@ uint8_t state = 0;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
if (Usb.Init() == -1) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while(1); //halt
@ -27,110 +26,78 @@ void loop() {
if(PS3.PS3Connected || PS3.PS3NavigationConnected) { 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 || 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("\r\nLeftHatX: "));
Serial.print(F("LeftHatX: "));
Serial.print(PS3.getAnalogHat(LeftHatX)); Serial.print(PS3.getAnalogHat(LeftHatX));
Serial.print("\t"); Serial.print(F("\tLeftHatY: "));
}
if(PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117) {
Serial.print(F("LeftHatY: "));
Serial.print(PS3.getAnalogHat(LeftHatY)); Serial.print(PS3.getAnalogHat(LeftHatY));
Serial.print("\t"); Serial.print(F("\tRightHatX: "));
}
if(PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117) {
Serial.print(F("RightHatX: "));
Serial.print(PS3.getAnalogHat(RightHatX)); Serial.print(PS3.getAnalogHat(RightHatX));
Serial.print("\t"); Serial.print(F("\tRightHatY: "));
}
if(PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) {
Serial.print(F("RightHatY: "));
Serial.print(PS3.getAnalogHat(RightHatY)); Serial.print(PS3.getAnalogHat(RightHatY));
} }
Serial.println("");
}
// Analog button values can be read from almost all buttons // 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 || PS3.getAnalogButton(R2_ANALOG) > 0) {
if(PS3.getAnalogButton(L2_ANALOG) > 0) { Serial.print(F("\r\nL2: "));
Serial.print(F("L2: "));
Serial.print(PS3.getAnalogButton(L2_ANALOG)); Serial.print(PS3.getAnalogButton(L2_ANALOG));
Serial.print("\t"); Serial.print(F("\tR2: "));
}
if(PS3.getAnalogButton(R2_ANALOG) > 0) {
Serial.print(F("R2: "));
Serial.print(PS3.getAnalogButton(R2_ANALOG)); Serial.print(PS3.getAnalogButton(R2_ANALOG));
} }
Serial.println(""); if(PS3.getButtonClick(PS))
} Serial.print(F("\r\nPS"));
if(PS3.buttonPressed) if(PS3.getButtonClick(TRIANGLE))
{ Serial.print(F("\r\nTraingle"));
Serial.print(F("PS3 Controller")); 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)) if(PS3.getButtonClick(UP)) {
Serial.print(F(" - PS")); Serial.print(F("\r\nUp"));
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.getButton(UP)) {
Serial.print(F(" - Up"));
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED4); PS3.setLedOn(LED4);
} }
if(PS3.getButton(RIGHT)) { if(PS3.getButtonClick(RIGHT)) {
Serial.print(F(" - Right")); Serial.print(F("\r\nRight"));
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED1); PS3.setLedOn(LED1);
} }
if(PS3.getButton(DOWN)) { if(PS3.getButtonClick(DOWN)) {
Serial.print(F(" - Down")); Serial.print(F("\r\nDown"));
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED2); PS3.setLedOn(LED2);
} }
if(PS3.getButton(LEFT)) { if(PS3.getButtonClick(LEFT)) {
Serial.print(F(" - Left")); Serial.print(F("\r\nLeft"));
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED3); PS3.setLedOn(LED3);
} }
if(PS3.getButton(L1)) if(PS3.getButtonClick(L1))
Serial.print(F(" - L1")); Serial.print(F("\r\nL1"));
//if(PS3.getButton(L2)) if(PS3.getButtonClick(L3))
//Serial.print(F(" - L2")); Serial.print(F("\r\nL3"));
if(PS3.getButton(L3)) if(PS3.getButtonClick(R1))
Serial.print(F(" - L3")); Serial.print(F("\r\nR1"));
if(PS3.getButton(R1)) if(PS3.getButtonClick(R3))
Serial.print(F(" - R1")); Serial.print(F("\r\nR3"));
//if(PS3.getButton(R2))
//Serial.print(F(" - R2"));
if(PS3.getButton(R3))
Serial.print(F(" - R3"));
if(PS3.getButton(SELECT)) { if(PS3.getButtonClick(SELECT)) {
Serial.print(F(" - Select - ")); Serial.print(F("\r\nSelect - "));
Serial.print(PS3.getStatusString()); Serial.print(PS3.getStatusString());
} }
if(PS3.getButton(START)) { if(PS3.getButtonClick(START)) {
Serial.print(F(" - Start")); Serial.print(F("\r\nStart"));
printAngle = !printAngle; printAngle = !printAngle;
while(PS3.getButton(START))
Usb.Task();
} }
Serial.println("");
} }
if(printAngle) { if(printAngle) {
Serial.print(F("Pitch: ")); Serial.print(F("\r\nPitch: "));
Serial.print(PS3.getAngle(Pitch)); Serial.print(PS3.getAngle(Pitch));
Serial.print(F("\tRoll: ")); Serial.print(F("\tRoll: "));
Serial.println(PS3.getAngle(Roll)); 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 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) { switch(state) {
@ -185,4 +152,3 @@ void loop() {
delay(1000); delay(1000);
} }
} }

View file

@ -15,7 +15,8 @@ PS3USB KEYWORD1
setBdaddr KEYWORD2 setBdaddr KEYWORD2
setMoveBdaddr KEYWORD2 setMoveBdaddr KEYWORD2
getButton KEYWORD2 getButtonPress KEYWORD2
getButtonClick KEYWORD2
getAnalogButton KEYWORD2 getAnalogButton KEYWORD2
getAnalogHat KEYWORD2 getAnalogHat KEYWORD2
getSensor KEYWORD2 getSensor KEYWORD2
@ -37,9 +38,6 @@ moveSetRumble KEYWORD2
PS3Connected KEYWORD2 PS3Connected KEYWORD2
PS3MoveConnected KEYWORD2 PS3MoveConnected KEYWORD2
PS3NavigationConnected KEYWORD2 PS3NavigationConnected KEYWORD2
buttonChanged KEYWORD2
buttonPressed KEYWORD2
buttonReleased KEYWORD2
watingForConnection KEYWORD2 watingForConnection KEYWORD2
@ -220,8 +218,6 @@ WII KEYWORD1
wiimoteConnected KEYWORD2 wiimoteConnected KEYWORD2
nunchuckConnected KEYWORD2 nunchuckConnected KEYWORD2
motionPlusConnected KEYWORD2 motionPlusConnected KEYWORD2
getButtonPress KEYWORD2
getButtonClick KEYWORD2
setRumbleToggle KEYWORD2 setRumbleToggle KEYWORD2
getPitch KEYWORD2 getPitch KEYWORD2
getRoll KEYWORD2 getRoll KEYWORD2