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) { bool PS3BT::getButtonClick(Button b) {
if((l2capinbuf[((uint16_t)b >> 8)-1] & ((uint8_t)b & 0xff))) // All the buttons locations are shifted one back on the Move controller bool click = (ButtonClickState & (uint32_t)b);
return true; ButtonClickState &= ~((uint32_t)b); // clear "click" event
else return click;
return false;
} else {
if((l2capinbuf[(uint16_t)b >> 8] & ((uint8_t)b & 0xff)))
return true;
else
return false;
}
} }
uint8_t PS3BT::getAnalogButton(AnalogButton a) { uint8_t PS3BT::getAnalogButton(AnalogButton a) {
if (l2capinbuf == NULL) 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) { void PS3BT::ACLData(uint8_t* ACLData) {
if(!pBtd->l2capConnectionClaimed && !PS3Connected && !PS3MoveConnected && !PS3NavigationConnected) { if(!pBtd->l2capConnectionClaimed && !PS3Connected && !PS3MoveConnected && !PS3NavigationConnected) {
if (ACLData[8] == L2CAP_CMD_CONNECTION_REQUEST) { 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 pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
l2cap_state = L2CAP_WAIT; l2cap_state = L2CAP_WAIT;
@ -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) {
@ -384,19 +369,17 @@ double PS3USB::getAngle(Angle a) {
return angle; return angle;
} }
} 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(":");
} }

119
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 */
@ -214,7 +106,8 @@ private:
uint32_t timer; // used to continuously set PS3 Move controller Bulb and rumble values uint32_t timer; // used to continuously set PS3 Move controller Bulb and rumble values
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
@ -225,7 +118,7 @@ private:
/* Private commands */ /* Private commands */
void PS3_Command(uint8_t* data, uint16_t nbytes); 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); void Move_Command(uint8_t* data, uint16_t nbytes);
}; };
#endif #endif

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(F("\tLeftHatY: "));
Serial.print("\t"); Serial.print(PS3.getAnalogHat(LeftHatY));
} if(PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117) { Serial.print(F("\tRightHatX: "));
Serial.print(F("LeftHatY: ")); Serial.print(PS3.getAnalogHat(RightHatX));
Serial.print(PS3.getAnalogHat(LeftHatY)); Serial.print(F("\tRightHatY: "));
Serial.print("\t"); Serial.print(PS3.getAnalogHat(RightHatY));
} 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("");
} }
//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(F("\tR2: "));
Serial.print("\t"); Serial.print(PS3.getAnalogButton(R2_ANALOG));
} if(PS3.getAnalogButton(R2_ANALOG) > 0) {
Serial.print(F("R2: "));
Serial.print(PS3.getAnalogButton(R2_ANALOG));
}
Serial.println("");
} }
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) if(PS3.getButtonClick(UP)) {
{ Serial.print(F("\r\nUp"));
Serial.print(F("PS3 Controller")); 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)) { if(PS3.getButtonClick(L1))
Serial.print(F(" - PS")); Serial.print(F("\r\nL1"));
PS3.disconnect(); if(PS3.getButtonClick(L3))
} else { Serial.print(F("\r\nL3"));
if(PS3.getButton(TRIANGLE)) if(PS3.getButtonClick(R1))
Serial.print(F(" - Traingle")); Serial.print(F("\r\nR1"));
if(PS3.getButton(CIRCLE)) if(PS3.getButtonClick(R3))
Serial.print(F(" - Circle")); Serial.print(F("\r\nR3"));
if(PS3.getButton(CROSS))
Serial.print(F(" - Cross"));
if(PS3.getButton(SQUARE))
Serial.print(F(" - Square"));
if(PS3.getButton(UP)) { if(PS3.getButtonClick(SELECT)) {
Serial.print(F(" - Up")); Serial.print(F("\r\nSelect - "));
if(PS3.PS3Connected) { Serial.print(PS3.getStatusString());
PS3.setAllOff(); }
PS3.setLedOn(LED4); if(PS3.getButtonClick(START)) {
} Serial.print(F("\r\nStart"));
} if(PS3.getButton(RIGHT)) { printAngle = !printAngle;
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(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)) { PS3.disconnect();
Serial.print(F(" - PS")); }
PS3.disconnect(); else {
} else { if(PS3.getButtonClick(SELECT)) {
if(PS3.getButton(SELECT)) { Serial.print(F("\r\nSelect"));
Serial.print(F(" - Select")); printTemperature = !printTemperature;
printTemperature = !printTemperature; }
while(PS3.getButton(SELECT)) if(PS3.getButtonClick(START)) {
Usb.Task(); Serial.print(F("\r\nStart"));
} if(PS3.getButton(START)) { printAngle = !printAngle;
Serial.print(F(" - Start")); }
printAngle = !printAngle; if(PS3.getButtonClick(TRIANGLE)) {
while(PS3.getButton(START)) Serial.print(F("\r\nTriangle"));
Usb.Task(); PS3.moveSetBulb(Red);
} if(PS3.getButton(TRIANGLE)) { }
Serial.print(F(" - Triangle")); if(PS3.getButtonClick(CIRCLE)) {
PS3.moveSetBulb(Red); Serial.print(F("\r\nCircle"));
} if(PS3.getButton(CIRCLE)) { PS3.moveSetBulb(Green);
Serial.print(F(" - Circle")); }
PS3.moveSetBulb(Green); if(PS3.getButtonClick(SQUARE)) {
} if(PS3.getButton(SQUARE)) { Serial.print(F("\r\nSquare"));
Serial.print(F(" - Square")); PS3.moveSetBulb(Blue);
PS3.moveSetBulb(Blue); }
} if(PS3.getButton(CROSS)) { if(PS3.getButtonClick(CROSS)) {
Serial.print(F(" - Cross")); Serial.print(F("\r\nCross"));
PS3.moveSetBulb(Yellow); PS3.moveSetBulb(Yellow);
} if(PS3.getButton(MOVE)) { }
PS3.moveSetBulb(Off); if(PS3.getButtonClick(MOVE)) {
Serial.print(F(" - Move")); PS3.moveSetBulb(Off);
Serial.print(F(" - ")); Serial.print(F("\r\nMove"));
Serial.print(PS3.getStatusString()); Serial.print(F(" - "));
} 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

@ -3,7 +3,7 @@
For more information visit my blog: http://blog.tkjelectronics.dk/ or For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com send me an e-mail: kristianl@tkjelectronics.com
*/ */
/* /*
Note: Note:
You will need a Arduino Mega 1280/2560 to run this sketch, 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 //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
@ -50,118 +48,96 @@ void loop() {
else else
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)) {
analogOutput += "R2: ";
analogOutput += PS3.getAnalogButton(R2_ANALOG);
analogOutput += "\t";
}
} }
if(analogOutput != "") { if(output != "") {
Serial.println(analogOutput); Serial.println(output);
if(SerialBT.connected) 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) { if(PS3.getButtonClick(UP)) {
digitalOutput = "PS3 Controller"; output += " - Up";
if(PS3.getButton(PS)) { if(PS3.PS3Connected) {
digitalOutput += " - PS"; PS3.setAllOff();
PS3.disconnect(); 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)) { if(PS3.getButtonClick(L1))
digitalOutput += " - UP"; output += " - L1";
if(PS3.PS3Connected) { if(PS3.getButtonClick(L3))
PS3.setAllOff(); output += " - L3";
PS3.setLedOn(LED4); if(PS3.getButtonClick(R1))
} output += " - R1";
} if(PS3.getButtonClick(R3))
if(PS3.getButton(RIGHT)) { output += " - R3";
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.getButton(L1)) if(PS3.getButtonClick(SELECT))
digitalOutput += " - L1"; output += " - Select";
//if(PS3.getButton(L2)) if(PS3.getButtonClick(START))
//digitalOutput += " - L2"; output += " - Start";
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.getButton(SELECT)) if(output != "") {
digitalOutput += " - Select"; String string = "PS3 Controller" + output;
if(PS3.getButton(START)) Serial.println(string);
digitalOutput += " - Start";
Serial.println(digitalOutput);
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,156 +26,124 @@ 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(F("\tLeftHatY: "));
Serial.print("\t"); Serial.print(PS3.getAnalogHat(LeftHatY));
} Serial.print(F("\tRightHatX: "));
if(PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117) { Serial.print(PS3.getAnalogHat(RightHatX));
Serial.print(F("LeftHatY: ")); Serial.print(F("\tRightHatY: "));
Serial.print(PS3.getAnalogHat(LeftHatY)); Serial.print(PS3.getAnalogHat(RightHatY));
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("");
} }
// 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(F("\tR2: "));
Serial.print("\t"); Serial.print(PS3.getAnalogButton(R2_ANALOG));
}
if(PS3.getAnalogButton(R2_ANALOG) > 0) {
Serial.print(F("R2: "));
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"));
PS3.setAllOff();
if(PS3.getButton(TRIANGLE)) PS3.setLedOn(LED4);
Serial.print(F(" - Traingle")); }
if(PS3.getButton(CIRCLE)) if(PS3.getButtonClick(RIGHT)) {
Serial.print(F(" - Circle")); Serial.print(F("\r\nRight"));
if(PS3.getButton(CROSS)) PS3.setAllOff();
Serial.print(F(" - Cross")); PS3.setLedOn(LED1);
if(PS3.getButton(SQUARE)) }
Serial.print(F(" - Square")); 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)) { if(PS3.getButtonClick(L1))
Serial.print(F(" - Up")); Serial.print(F("\r\nL1"));
PS3.setAllOff(); if(PS3.getButtonClick(L3))
PS3.setLedOn(LED4); Serial.print(F("\r\nL3"));
} if(PS3.getButtonClick(R1))
if(PS3.getButton(RIGHT)) { Serial.print(F("\r\nR1"));
Serial.print(F(" - Right")); if(PS3.getButtonClick(R3))
PS3.setAllOff(); Serial.print(F("\r\nR3"));
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.getButton(L1)) if(PS3.getButtonClick(SELECT)) {
Serial.print(F(" - L1")); Serial.print(F("\r\nSelect - "));
//if(PS3.getButton(L2)) Serial.print(PS3.getStatusString());
//Serial.print(F(" - L2")); }
if(PS3.getButton(L3)) if(PS3.getButtonClick(START)) {
Serial.print(F(" - L3")); Serial.print(F("\r\nStart"));
if(PS3.getButton(R1)) printAngle = !printAngle;
Serial.print(F(" - R1")); }
//if(PS3.getButton(R2)) }
//Serial.print(F(" - R2")); if(printAngle) {
if(PS3.getButton(R3)) Serial.print(F("\r\nPitch: "));
Serial.print(F(" - R3")); Serial.print(PS3.getAngle(Pitch));
Serial.print(F("\tRoll: "));
if(PS3.getButton(SELECT)) { Serial.print(PS3.getAngle(Roll));
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));
}
} }
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) {
case 0: case 0:
PS3.moveSetRumble(0); PS3.moveSetRumble(0);
PS3.moveSetBulb(Off); PS3.moveSetBulb(Off);
state = 1; state = 1;
break; break;
case 1: case 1:
PS3.moveSetRumble(75); PS3.moveSetRumble(75);
PS3.moveSetBulb(Red); PS3.moveSetBulb(Red);
state = 2; state = 2;
break; break;
case 2: case 2:
PS3.moveSetRumble(125); PS3.moveSetRumble(125);
PS3.moveSetBulb(Green); PS3.moveSetBulb(Green);
state = 3; state = 3;
break; break;
case 3: case 3:
PS3.moveSetRumble(150); PS3.moveSetRumble(150);
PS3.moveSetBulb(Blue); PS3.moveSetBulb(Blue);
state = 4; state = 4;
break; break;
case 4: case 4:
PS3.moveSetRumble(175); PS3.moveSetRumble(175);
PS3.moveSetBulb(Yellow); PS3.moveSetBulb(Yellow);
state = 5; state = 5;
break; break;
case 5: case 5:
PS3.moveSetRumble(200); PS3.moveSetRumble(200);
PS3.moveSetBulb(Lightblue); PS3.moveSetBulb(Lightblue);
state = 6; state = 6;
break; break;
case 6: case 6:
PS3.moveSetRumble(225); PS3.moveSetRumble(225);
PS3.moveSetBulb(Purble); PS3.moveSetBulb(Purble);
state = 7; state = 7;
break; break;
case 7: case 7:
PS3.moveSetRumble(250); PS3.moveSetRumble(250);
PS3.moveSetBulb(White); PS3.moveSetBulb(White);
state = 0; state = 0;
@ -185,4 +152,3 @@ void loop() {
delay(1000); delay(1000);
} }
} }

View file

@ -6,40 +6,38 @@
# Datatypes (KEYWORD1) # Datatypes (KEYWORD1)
#################################################### ####################################################
PS3BT KEYWORD1 PS3BT KEYWORD1
PS3USB KEYWORD1 PS3USB KEYWORD1
#################################################### ####################################################
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
#################################################### ####################################################
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
getAngle KEYWORD2 getAngle KEYWORD2
getStatus KEYWORD2 getStatus KEYWORD2
getStatusString KEYWORD2 getStatusString KEYWORD2
getTemperature KEYWORD2 getTemperature KEYWORD2
disconnect KEYWORD2 disconnect KEYWORD2
setAllOff KEYWORD2 setAllOff KEYWORD2
setRumbleOff KEYWORD2 setRumbleOff KEYWORD2
setRumbleOn KEYWORD2 setRumbleOn KEYWORD2
setLedOff KEYWORD2 setLedOff KEYWORD2
setLedOn KEYWORD2 setLedOn KEYWORD2
setLedToggle KEYWORD2 setLedToggle KEYWORD2
moveSetBulb KEYWORD2 moveSetBulb KEYWORD2
moveSetRumble KEYWORD2 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