Merge pull request #28 from felis/PS3-Multi

PS3BT and PS3USB don't conflict anymore and some other small changes
This commit is contained in:
Kristian Lauszus 2012-10-03 13:13:20 -07:00
commit ae082b1860
13 changed files with 578 additions and 799 deletions

16
BTD.cpp
View file

@ -497,6 +497,7 @@ void BTD::HCI_task() {
case HCI_RESET_STATE: case HCI_RESET_STATE:
hci_counter++; hci_counter++;
if (hci_cmd_complete) { if (hci_cmd_complete) {
hci_counter = 0;
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nHCI Reset complete")); Notify(PSTR("\r\nHCI Reset complete"));
#endif #endif
@ -661,16 +662,7 @@ void BTD::HCI_task() {
} }
PrintHex<uint8_t>(disc_bdaddr[0]); PrintHex<uint8_t>(disc_bdaddr[0]);
#endif #endif
hci_write_scan_disable(); l2capConnectionClaimed = false;
hci_state = HCI_DISABLE_SCAN_STATE;
}
break;
case HCI_DISABLE_SCAN_STATE:
if (hci_cmd_complete) {
#ifdef DEBUG
Notify(PSTR("\r\nScan Disabled"));
#endif
hci_event_flag = 0; hci_event_flag = 0;
hci_state = HCI_DONE_STATE; hci_state = HCI_DONE_STATE;
} }
@ -678,9 +670,9 @@ void BTD::HCI_task() {
case HCI_DONE_STATE: case HCI_DONE_STATE:
hci_counter++; hci_counter++;
if (hci_counter > 250) { // Wait until we have looped 250 times to make sure that the L2CAP connection has been started if (hci_counter > 1000) { // Wait until we have looped 1000 times to make sure that the L2CAP connection has been started
hci_counter = 0;
hci_state = HCI_SCANNING_STATE; hci_state = HCI_SCANNING_STATE;
l2capConnectionClaimed = false;
} }
break; break;

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)
@ -90,20 +83,11 @@ int16_t PS3BT::getSensor(Sensor a) {
return 0; return 0;
if (a == aX || a == aY || a == aZ || a == gZ) if (a == aX || a == aY || a == aZ || a == gZ)
return ((l2capinbuf[(uint16_t)a] << 8) | l2capinbuf[(uint16_t)a + 1]); return ((l2capinbuf[(uint16_t)a] << 8) | l2capinbuf[(uint16_t)a + 1]);
else if (a == mXmove || a == mYmove || a == mZmove) // These are all 12-bits long else if (a == mXmove || a == mYmove || a == mZmove) { // These are all 12-bits long
{
// Might not be correct, haven't tested it yet
/*if (a == mXmove)
return ((l2capinbuf[(uint16_t)a + 1] << 0x04) | (l2capinbuf[(uint16_t)a] << 0x0C));
else if (a == mYmove)
return ((l2capinbuf[(uint16_t)a + 1] & 0xF0) | (l2capinbuf[(uint16_t)a] << 0x08));
else if (a == mZmove)
return ((l2capinbuf[(uint16_t)a + 1] << 0x0F) | (l2capinbuf[(uint16_t)a] << 0x0C));
*/
if (a == mXmove || a == mYmove) if (a == mXmove || a == mYmove)
return (((l2capinbuf[(uint16_t)a] & 0x0F) << 8) | (l2capinbuf[(uint16_t)a + 1])); return (((l2capinbuf[(uint16_t)a] & 0x0F) << 8) | (l2capinbuf[(uint16_t)a + 1]));
else // mZmove else // mZmove
return ((l2capinbuf[(uint16_t)a] << 4) | (l2capinbuf[(uint16_t)a + 1] >> 4)); return ((l2capinbuf[(uint16_t)a] << 4) | (l2capinbuf[(uint16_t)a + 1] & 0xF0 ) >> 4);
} }
else if (a == tempMove) // The tempearature is 12 bits long too else if (a == tempMove) // The tempearature is 12 bits long too
return ((l2capinbuf[(uint16_t)a] << 4) | ((l2capinbuf[(uint16_t)a + 1] & 0xF0) >> 4)); return ((l2capinbuf[(uint16_t)a] << 4) | ((l2capinbuf[(uint16_t)a + 1] & 0xF0) >> 4));
@ -140,6 +124,30 @@ double PS3BT::getAngle(Angle a) {
return angle; return angle;
} }
} }
double PS3BT::get9DOFValues(Sensor a) { // Thanks to Manfred Piendl
int16_t value = getSensor(a);
if (a == mXmove || a == mYmove || a == mZmove) {
if (value > 2047)
value -= 0x1000;
return (double)value/3.2; // unit: muT = 10^(-6) Tesla
}
else if (a == aXmove || a == aYmove || a == aZmove) {
if (value < 0)
value += 0x8000;
else
value -= 0x8000;
return (double)value/442.0; // unit: m/(s^2)
}
else if (a == gXmove || a == gYmove || a == gZmove) {
if (value < 0)
value += 0x8000;
else
value -= 0x8000;
return (double)value/9.6; // unit: deg/s
}
else
return 0;
}
String PS3BT::getTemperature() { String PS3BT::getTemperature() {
if(PS3MoveConnected) { if(PS3MoveConnected) {
int16_t input = getSensor(tempMove); int16_t input = getSensor(tempMove);
@ -367,21 +375,9 @@ void PS3BT::ACLData(uint8_t* ACLData) {
//PrintHex<uint32_t>(ButtonState); //PrintHex<uint32_t>(ButtonState);
if(ButtonState != OldButtonState) { if(ButtonState != OldButtonState) {
buttonChanged = true; ButtonClickState = ButtonState & ~OldButtonState; // 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;
}
#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
for(uint8_t i = 10; i < 58;i++) { for(uint8_t i = 10; i < 58;i++) {
@ -583,22 +579,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);
} }
} }

170
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,11 +68,20 @@ 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); /*
getButtonPress will return true as long as the button is held down
While getButtonClick will only return it once
So you instance if you need to increase a variable once you would use getButtonClick,
but if you need to drive a robot forward you would use getButtonPress
*/
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);
double getAngle(Angle a); double getAngle(Angle a);
double get9DOFValues(Sensor a);
bool getStatus(Status c); bool getStatus(Status c);
String getStatusString(); String getStatusString();
String getTemperature(); String getTemperature();
@ -246,9 +103,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 +122,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

@ -309,57 +309,43 @@ void PS3USB::readReport() {
//PrintHex<uint32_t>(ButtonState); //PrintHex<uint32_t>(ButtonState);
if(ButtonState != OldButtonState) { if(ButtonState != OldButtonState) {
buttonChanged = true; ButtonClickState = ButtonState & ~OldButtonState; // 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 +371,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 +439,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 +477,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 +538,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(":");
} }

122
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,15 @@ public:
void setMoveBdaddr(uint8_t* BDADDR); void setMoveBdaddr(uint8_t* BDADDR);
/* PS3 Controller Commands */ /* PS3 Controller Commands */
bool getButton(Button b); /*
getButtonPress will return true as long as the button is held down
While getButtonClick will only return it once
So you instance if you need to increase a variable once you would use getButtonClick,
but if you need to drive a robot forward you would use getButtonPress
*/
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 +100,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 +114,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

16
SPP.cpp
View file

@ -379,6 +379,7 @@ void SPP::SDP_task() {
{ {
case L2CAP_SDP_WAIT: case L2CAP_SDP_WAIT:
if (l2cap_connection_request_sdp_flag) { if (l2cap_connection_request_sdp_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_SDP_REQUEST; // Clear flag
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nSDP Incoming Connection Request")); Notify(PSTR("\r\nSDP Incoming Connection Request"));
#endif #endif
@ -393,6 +394,7 @@ void SPP::SDP_task() {
break; break;
case L2CAP_SDP_REQUEST: case L2CAP_SDP_REQUEST:
if (l2cap_config_request_sdp_flag) { if (l2cap_config_request_sdp_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_REQUEST; // Clear flag
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nSDP Configuration Request")); Notify(PSTR("\r\nSDP Configuration Request"));
#endif #endif
@ -402,6 +404,7 @@ void SPP::SDP_task() {
break; break;
case L2CAP_SDP_SUCCESS: case L2CAP_SDP_SUCCESS:
if (l2cap_config_success_sdp_flag) { if (l2cap_config_success_sdp_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_SUCCESS; // Clear flag
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nSDP Successfully Configured")); Notify(PSTR("\r\nSDP Successfully Configured"));
#endif #endif
@ -412,12 +415,12 @@ void SPP::SDP_task() {
break; break;
case L2CAP_SDP_DONE: case L2CAP_SDP_DONE:
if(l2cap_disconnect_request_sdp_flag) { if(l2cap_disconnect_request_sdp_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_SDP_REQUEST; // Clear flag
SDPConnected = false; SDPConnected = false;
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nDisconnected SDP Channel")); Notify(PSTR("\r\nDisconnected SDP Channel"));
#endif #endif
pBtd->l2cap_disconnection_response(hci_handle,identifier,sdp_dcid,sdp_scid); pBtd->l2cap_disconnection_response(hci_handle,identifier,sdp_dcid,sdp_scid);
l2cap_event_flag = 0; // Reset flags
l2cap_sdp_state = L2CAP_SDP_WAIT; l2cap_sdp_state = L2CAP_SDP_WAIT;
} }
break; break;
@ -442,6 +445,7 @@ void SPP::RFCOMM_task()
{ {
case L2CAP_RFCOMM_WAIT: case L2CAP_RFCOMM_WAIT:
if(l2cap_connection_request_rfcomm_flag) { if(l2cap_connection_request_rfcomm_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST; // Clear flag
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nRFCOMM Incoming Connection Request")); Notify(PSTR("\r\nRFCOMM Incoming Connection Request"));
#endif #endif
@ -456,6 +460,7 @@ void SPP::RFCOMM_task()
break; break;
case L2CAP_RFCOMM_REQUEST: case L2CAP_RFCOMM_REQUEST:
if (l2cap_config_request_rfcomm_flag) { if (l2cap_config_request_rfcomm_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_REQUEST; // Clear flag
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nRFCOMM Configuration Request")); Notify(PSTR("\r\nRFCOMM Configuration Request"));
#endif #endif
@ -465,6 +470,7 @@ void SPP::RFCOMM_task()
break; break;
case L2CAP_RFCOMM_SUCCESS: case L2CAP_RFCOMM_SUCCESS:
if (l2cap_config_success_rfcomm_flag) { if (l2cap_config_success_rfcomm_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS; // Clear flag
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nRFCOMM Successfully Configured")); Notify(PSTR("\r\nRFCOMM Successfully Configured"));
#endif #endif
@ -476,13 +482,13 @@ void SPP::RFCOMM_task()
break; break;
case L2CAP_RFCOMM_DONE: case L2CAP_RFCOMM_DONE:
if(l2cap_disconnect_request_rfcomm_flag) { if(l2cap_disconnect_request_rfcomm_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST; // Clear flag
RFCOMMConnected = false; RFCOMMConnected = false;
connected = false; connected = false;
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nDisconnected RFCOMM Channel")); Notify(PSTR("\r\nDisconnected RFCOMM Channel"));
#endif #endif
pBtd->l2cap_disconnection_response(hci_handle,identifier,rfcomm_dcid,rfcomm_scid); pBtd->l2cap_disconnection_response(hci_handle,identifier,rfcomm_dcid,rfcomm_scid);
l2cap_event_flag = 0; // Reset flags
l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT; l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
} }
break; break;
@ -789,8 +795,7 @@ void SPP::printNumber(uint16_t n) {
else { else {
uint8_t buf[digits]; uint8_t buf[digits];
for(uint8_t i = 1; i < digits+1; i++) { for(uint8_t i = 1; i < digits+1; i++) {
buf[digits-i] = n%10; // Get number and convert to ASCII Character buf[digits-i] = n%10 + '0'; // Get number and convert to ASCII Character
buf[digits-i] += 48;
n /= 10; n /= 10;
} }
print(buf,digits); print(buf,digits);
@ -808,8 +813,7 @@ void SPP::printNumberln(uint16_t n) {
else { else {
uint8_t buf[digits+2]; uint8_t buf[digits+2];
for(uint8_t i = 1; i < digits+1; i++) { for(uint8_t i = 1; i < digits+1; i++) {
buf[digits-i] = n%10; // Get number and convert to ASCII Character buf[digits-i] = n%10 + '0'; // Get number and convert to ASCII Character
buf[digits-i] += 48;
n /= 10; n /= 10;
} }
buf[digits] = '\r'; buf[digits] = '\r';

29
Wii.cpp
View file

@ -165,11 +165,11 @@ void WII::ACLData(uint8_t* l2capinbuf) {
if(l2capinbuf[20] & 0x02) // Only update the wiimote buttons, since the extension bytes are from the Motion Plus if(l2capinbuf[20] & 0x02) // Only update the wiimote buttons, since the extension bytes are from the Motion Plus
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(ButtonState & 0xFFFF0000))); ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(ButtonState & 0xFFFF0000)));
else if (nunchuckConnected) // Update if it's a report from the Nunchuck else if (nunchuckConnected) // Update if it's a report from the Nunchuck
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(l2capinbuf[20] & 0x0C) << 14)); ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x0C) << 14));
//else if(classicControllerConnected) // Update if it's a report from the Classic Controller //else if(classicControllerConnected) // Update if it's a report from the Classic Controller
} }
else if(nunchuckConnected) // The Nunchuck is directly connected else if(nunchuckConnected) // The Nunchuck is directly connected
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(l2capinbuf[20] & 0x03) << 16)); ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x03) << 16));
//else if(classicControllerConnected) // The Classic Controller is directly connected //else if(classicControllerConnected) // The Classic Controller is directly connected
else if(!unknownExtensionConnected) else if(!unknownExtensionConnected)
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8)); ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8));
@ -178,10 +178,11 @@ void WII::ACLData(uint8_t* l2capinbuf) {
PrintHex<uint32_t>(ButtonState); PrintHex<uint32_t>(ButtonState);
Notify(PSTR("\r\n")); Notify(PSTR("\r\n"));
#endif #endif
if(ButtonState != OldButtonState) if(ButtonState != OldButtonState) {
ButtonClickState = ButtonState; // Update click state variable ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
OldButtonState = ButtonState; OldButtonState = ButtonState;
} }
}
if(l2capinbuf[9] == 0x31 || l2capinbuf[9] == 0x35) { // Read the accelerometer if(l2capinbuf[9] == 0x31 || l2capinbuf[9] == 0x35) { // Read the accelerometer
accX = ((l2capinbuf[12] << 2) | (l2capinbuf[10] & 0x60 >> 5))-500; accX = ((l2capinbuf[12] << 2) | (l2capinbuf[10] & 0x60 >> 5))-500;
accY = ((l2capinbuf[13] << 2) | (l2capinbuf[11] & 0x20 >> 4))-500; accY = ((l2capinbuf[13] << 2) | (l2capinbuf[11] & 0x20 >> 4))-500;
@ -249,11 +250,6 @@ void WII::ACLData(uint8_t* l2capinbuf) {
activateNunchuck = false; activateNunchuck = false;
motionPlusConnected = true; motionPlusConnected = true;
nunchuckConnected = true; nunchuckConnected = true;
ButtonState |= (Z | C);
ButtonState |= ((Z | C)<<2);
ButtonClickState = ButtonState;
OldButtonState = ButtonState;
} }
#ifdef DEBUG #ifdef DEBUG
else { else {
@ -571,13 +567,8 @@ void WII::Run() {
break; break;
case L2CAP_LED_STATE: case L2CAP_LED_STATE:
if(nunchuck_connected_flag) { if(nunchuck_connected_flag)
nunchuckConnected = true; nunchuckConnected = true;
ButtonState |= (Z | C); // Since the Nunchuck button are cleared when pressed we set the buttonstates like so
ButtonState |= ((Z | C)<<2); // And like this when it's connected since the bytes are shifter two to the left
ButtonClickState = ButtonState;
OldButtonState = ButtonState;
}
setLedOn(LED1); setLedOn(LED1);
l2cap_state = L2CAP_DONE; l2cap_state = L2CAP_DONE;
break; break;
@ -607,10 +598,6 @@ void WII::Run() {
#endif #endif
activateNunchuck = true; activateNunchuck = true;
nunchuckConnected = true; nunchuckConnected = true;
ButtonState |= (Z | C); // Since the Nunchuck button are cleared when pressed we set the buttonstates like so
ButtonState |= ((Z | C)<<2); // And like this when it's connected since the bytes are shifter two to the left
ButtonClickState = ButtonState;
OldButtonState = ButtonState;
} }
if(!motionPlusConnected) if(!motionPlusConnected)
stateCounter = 449; stateCounter = 449;
@ -793,10 +780,6 @@ bool WII::getButtonPress(Button b) { // Return true when a button is pressed
} }
bool WII::getButtonClick(Button b) { // Only return true when a button is clicked bool WII::getButtonClick(Button b) { // Only return true when a button is clicked
bool click = (ButtonClickState & (uint32_t)b); bool click = (ButtonClickState & (uint32_t)b);
if(b == Z || b == C) {
click = !click; // The nunchuck buttons are cleared when pressed
ButtonClickState |= (uint32_t)b; // clear "click" event
} else
ButtonClickState &= ~((uint32_t)b); // clear "click" event ButtonClickState &= ~((uint32_t)b); // clear "click" event
return click; return click;
} }

7
Wii.h
View file

@ -105,8 +105,15 @@ public:
virtual void Reset(); // Use this to reset the service virtual void Reset(); // Use this to reset the service
virtual void disconnect(); // Use this void to disconnect any of the controllers virtual void disconnect(); // Use this void to disconnect any of the controllers
/*
getButtonPress will return true as long as the button is held down
While getButtonClick will only return it once
So you instance if you need to increase a variable once you would use getButtonClick,
but if you need to drive a robot forward you would use getButtonPress
*/
bool getButtonPress(Button b); // This will read true as long as the button is held down bool getButtonPress(Button b); // This will read true as long as the button is held down
bool getButtonClick(Button b); // This will only be true when the button is clicked the first time bool getButtonClick(Button b); // This will only be true when the button is clicked the first time
uint8_t getAnalogHat(AnalogHat a); // Used to read the joystick of the Nunchuck uint8_t getAnalogHat(AnalogHat a); // Used to read the joystick of the Nunchuck
double getPitch() { return pitch; }; // Fusioned angle using a complimentary filter if the Motion Plus is connected double getPitch() { return pitch; }; // Fusioned angle using a complimentary filter if the Motion Plus is connected

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 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 = ""; // Reset output string
} }
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,11 +15,13 @@ 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
getAngle KEYWORD2 getAngle KEYWORD2
get9DOFValues KEYWORD2
getStatus KEYWORD2 getStatus KEYWORD2
getStatusString KEYWORD2 getStatusString KEYWORD2
getTemperature KEYWORD2 getTemperature KEYWORD2
@ -37,9 +39,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 +219,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