mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
The Wii and PS3 libaries can now be used at the same time
This commit is contained in:
parent
6caac1319b
commit
8ed3fcd3b8
6 changed files with 179 additions and 93 deletions
19
PS3BT.cpp
19
PS3BT.cpp
|
@ -61,11 +61,12 @@ pBtd(p) // pointer to USB class instance - mandatory
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
bool PS3BT::getButtonPress(Button b) {
|
bool PS3BT::getButtonPress(Button b) {
|
||||||
return (ButtonState & (uint32_t)b);
|
return (ButtonState & pgm_read_dword(&BUTTONS[(uint8_t)b]));
|
||||||
}
|
}
|
||||||
bool PS3BT::getButtonClick(Button b) {
|
bool PS3BT::getButtonClick(Button b) {
|
||||||
bool click = (ButtonClickState & (uint32_t)b);
|
uint32_t button = pgm_read_dword(&BUTTONS[(uint8_t)b]);
|
||||||
ButtonClickState &= ~((uint32_t)b); // clear "click" event
|
bool click = (ButtonClickState & button);
|
||||||
|
ButtonClickState &= ~button; // clear "click" event
|
||||||
return click;
|
return click;
|
||||||
}
|
}
|
||||||
uint8_t PS3BT::getAnalogButton(AnalogButton a) {
|
uint8_t PS3BT::getAnalogButton(AnalogButton a) {
|
||||||
|
@ -602,16 +603,16 @@ void PS3BT::setRumbleOn(Rumble mode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void PS3BT::setLedOff(LED a) {
|
void PS3BT::setLedOff(LED a) {
|
||||||
HIDBuffer[11] &= ~((uint8_t)(((uint16_t)a & 0x0f) << 1));
|
HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1));
|
||||||
HID_Command(HIDBuffer, HID_BUFFERSIZE);
|
HID_Command(HIDBuffer, HID_BUFFERSIZE);
|
||||||
}
|
}
|
||||||
void PS3BT::setLedOn(LED a) {
|
void PS3BT::setLedOn(LED a) {
|
||||||
HIDBuffer[11] |= (uint8_t)(((uint16_t)a & 0x0f) << 1);
|
HIDBuffer[11] |= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
|
||||||
HID_Command(HIDBuffer, HID_BUFFERSIZE);
|
HID_Command(HIDBuffer, HID_BUFFERSIZE);
|
||||||
}
|
}
|
||||||
void PS3BT::setLedToggle(LED a) {
|
void PS3BT::setLedToggle(LED a) {
|
||||||
HIDBuffer[11] ^= (uint8_t)(((uint16_t)a & 0x0f) << 1);
|
HIDBuffer[11] ^= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
|
||||||
HID_Command(HIDBuffer, HID_BUFFERSIZE);
|
HID_Command(HIDBuffer, HID_BUFFERSIZE);
|
||||||
}
|
}
|
||||||
void PS3BT::enable_sixaxis() { //Command used to enable the Dualshock 3 and Navigation controller to send data via USB
|
void PS3BT::enable_sixaxis() { //Command used to enable the Dualshock 3 and Navigation controller to send data via USB
|
||||||
uint8_t cmd_buf[6];
|
uint8_t cmd_buf[6];
|
||||||
|
|
75
PS3Enums.h
75
PS3Enums.h
|
@ -18,19 +18,48 @@
|
||||||
#ifndef _ps3enums_h
|
#ifndef _ps3enums_h
|
||||||
#define _ps3enums_h
|
#define _ps3enums_h
|
||||||
|
|
||||||
enum LED {
|
#include "controllerEnums.h"
|
||||||
LED1 = 0x01,
|
|
||||||
LED2 = 0x02,
|
const uint8_t LEDS[] PROGMEM = {
|
||||||
LED3 = 0x04,
|
0x01, // LED1
|
||||||
LED4 = 0x08,
|
0x02, // LED2
|
||||||
|
0x04, // LED3
|
||||||
|
0x08, // LED4
|
||||||
|
|
||||||
LED5 = 0x09,
|
0x09, // LED5
|
||||||
LED6 = 0x0A,
|
0x0A, // LED6
|
||||||
LED7 = 0x0C,
|
0x0C, // LED7
|
||||||
LED8 = 0x0D,
|
0x0D, // LED8
|
||||||
LED9 = 0x0E,
|
0x0E, // LED9
|
||||||
LED10 = 0x0F,
|
0x0F // LED10
|
||||||
};
|
};
|
||||||
|
const uint32_t BUTTONS[] PROGMEM = {
|
||||||
|
0x10, // UP
|
||||||
|
0x20, // RIGHT
|
||||||
|
0x40, // DOWN
|
||||||
|
0x80, // LEFT
|
||||||
|
0,0,0,0,0,0,0,0,0, // Skip buttons used by Wii library
|
||||||
|
|
||||||
|
0x01, // SELECT
|
||||||
|
0x02, // L3
|
||||||
|
0x04, // R3
|
||||||
|
0x08, // START
|
||||||
|
|
||||||
|
0x0100, // L2
|
||||||
|
0x0200, // R2
|
||||||
|
0x0400, // L1
|
||||||
|
0x0800, // R1
|
||||||
|
0x1000, // TRIANGLE
|
||||||
|
0x2000, // CIRCLE
|
||||||
|
0x4000, // CROSS
|
||||||
|
0x8000, // SQUARE
|
||||||
|
|
||||||
|
0x010000, // PS
|
||||||
|
|
||||||
|
0x080000, // MOVE - covers 12 bits - we only need to read the top 8
|
||||||
|
0x100000 // T - covers 12 bits - we only need to read the top 8
|
||||||
|
};
|
||||||
|
|
||||||
enum Colors {
|
enum Colors {
|
||||||
// Used to set the colors of the move controller
|
// Used to set the colors of the move controller
|
||||||
Red = 0xFF0000, // r = 255, g = 0, b = 0
|
Red = 0xFF0000, // r = 255, g = 0, b = 0
|
||||||
|
@ -44,30 +73,6 @@ enum Colors {
|
||||||
White = 0xFFFFFF, // r = 255, g = 255, b = 255
|
White = 0xFFFFFF, // r = 255, g = 255, b = 255
|
||||||
Off = 0x00, // r = 0, g = 0, b = 0
|
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 {
|
enum AnalogButton {
|
||||||
// Note that the location is shiftet 9 when it's connected via USB
|
// Note that the location is shiftet 9 when it's connected via USB
|
||||||
// Sixaxis Dualshcock 3 & Navigation controller
|
// Sixaxis Dualshcock 3 & Navigation controller
|
||||||
|
|
19
PS3USB.cpp
19
PS3USB.cpp
|
@ -327,11 +327,12 @@ void PS3USB::printReport() { //Uncomment "#define PRINTREPORT" to print the repo
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PS3USB::getButtonPress(Button b) {
|
bool PS3USB::getButtonPress(Button b) {
|
||||||
return (ButtonState & (uint32_t)b);
|
return (ButtonState & pgm_read_dword(&BUTTONS[(uint8_t)b]));
|
||||||
}
|
}
|
||||||
bool PS3USB::getButtonClick(Button b) {
|
bool PS3USB::getButtonClick(Button b) {
|
||||||
bool click = (ButtonClickState & (uint32_t)b);
|
uint32_t button = pgm_read_dword(&BUTTONS[(uint8_t)b]);
|
||||||
ButtonClickState &= ~((uint32_t)b); // clear "click" event
|
bool click = (ButtonClickState & button);
|
||||||
|
ButtonClickState &= ~button; // clear "click" event
|
||||||
return click;
|
return click;
|
||||||
}
|
}
|
||||||
uint8_t PS3USB::getAnalogButton(AnalogButton a) {
|
uint8_t PS3USB::getAnalogButton(AnalogButton a) {
|
||||||
|
@ -456,16 +457,16 @@ void PS3USB::setRumbleOn(Rumble mode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void PS3USB::setLedOff(LED a) {
|
void PS3USB::setLedOff(LED a) {
|
||||||
writeBuf[9] &= ~((uint8_t)(((uint16_t)a & 0x0f) << 1));
|
writeBuf[9] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1));
|
||||||
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
|
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
void PS3USB::setLedOn(LED a) {
|
void PS3USB::setLedOn(LED a) {
|
||||||
writeBuf[9] |= (uint8_t)(((uint16_t)a & 0x0f) << 1);
|
writeBuf[9] |= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
|
||||||
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
|
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
void PS3USB::setLedToggle(LED a) {
|
void PS3USB::setLedToggle(LED a) {
|
||||||
writeBuf[9] ^= (uint8_t)(((uint16_t)a & 0x0f) << 1);
|
writeBuf[9] ^= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
|
||||||
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
|
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
void PS3USB::setBdaddr(uint8_t* BDADDR) {
|
void PS3USB::setBdaddr(uint8_t* BDADDR) {
|
||||||
/* Set the internal bluetooth address */
|
/* Set the internal bluetooth address */
|
||||||
|
|
49
Wii.cpp
49
Wii.cpp
|
@ -24,6 +24,40 @@
|
||||||
//#define EXTRADEBUG // Uncomment to get even more debugging data
|
//#define EXTRADEBUG // Uncomment to get even more debugging data
|
||||||
//#define PRINTREPORT // Uncomment to print the report send by the Wii controllers
|
//#define PRINTREPORT // Uncomment to print the report send by the Wii controllers
|
||||||
|
|
||||||
|
const uint8_t LEDS[] PROGMEM = {
|
||||||
|
0x10, // LED1
|
||||||
|
0x20, // LED2
|
||||||
|
0x40, // LED3
|
||||||
|
0x80, // LED4
|
||||||
|
|
||||||
|
0x90, // LED5
|
||||||
|
0xA0, // LED6
|
||||||
|
0xC0, // LED7
|
||||||
|
0xD0, // LED8
|
||||||
|
0xE0, // LED9
|
||||||
|
0xF0 // LED10
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint32_t BUTTONS[] PROGMEM = {
|
||||||
|
0x00008, // UP
|
||||||
|
0x00002, // RIGHT
|
||||||
|
0x00004, // DOWN
|
||||||
|
0x00001, // LEFT
|
||||||
|
|
||||||
|
|
||||||
|
0x00010, // PLUS
|
||||||
|
|
||||||
|
0x00100, // TWO
|
||||||
|
0x00200, // ONE
|
||||||
|
0x00400, // B
|
||||||
|
0x00800, // A
|
||||||
|
0x01000, // MINUS
|
||||||
|
0x08000, // HOME
|
||||||
|
|
||||||
|
0x10000, // Z
|
||||||
|
0x20000 // C
|
||||||
|
};
|
||||||
|
|
||||||
WII::WII(BTD *p, bool pair):
|
WII::WII(BTD *p, bool pair):
|
||||||
pBtd(p) // pointer to USB class instance - mandatory
|
pBtd(p) // pointer to USB class instance - mandatory
|
||||||
{
|
{
|
||||||
|
@ -789,17 +823,17 @@ void WII::setRumbleToggle() {
|
||||||
}
|
}
|
||||||
void WII::setLedOff(LED a) {
|
void WII::setLedOff(LED a) {
|
||||||
HIDBuffer[1] = 0x11;
|
HIDBuffer[1] = 0x11;
|
||||||
HIDBuffer[2] &= ~((uint8_t)a);
|
HIDBuffer[2] &= ~(pgm_read_byte(&LEDS[(uint8_t)a]));
|
||||||
HID_Command(HIDBuffer, 3);
|
HID_Command(HIDBuffer, 3);
|
||||||
}
|
}
|
||||||
void WII::setLedOn(LED a) {
|
void WII::setLedOn(LED a) {
|
||||||
HIDBuffer[1] = 0x11;
|
HIDBuffer[1] = 0x11;
|
||||||
HIDBuffer[2] |= (uint8_t)a;
|
HIDBuffer[2] |= pgm_read_byte(&LEDS[(uint8_t)a]);
|
||||||
HID_Command(HIDBuffer, 3);
|
HID_Command(HIDBuffer, 3);
|
||||||
}
|
}
|
||||||
void WII::setLedToggle(LED a) {
|
void WII::setLedToggle(LED a) {
|
||||||
HIDBuffer[1] = 0x11;
|
HIDBuffer[1] = 0x11;
|
||||||
HIDBuffer[2] ^= (uint8_t)a;
|
HIDBuffer[2] ^= pgm_read_byte(&LEDS[(uint8_t)a]);
|
||||||
HID_Command(HIDBuffer, 3);
|
HID_Command(HIDBuffer, 3);
|
||||||
}
|
}
|
||||||
void WII::setLedStatus() {
|
void WII::setLedStatus() {
|
||||||
|
@ -916,14 +950,15 @@ void WII::checkMotionPresent() {
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
|
|
||||||
bool WII::getButtonPress(Button b) { // Return true when a button is pressed
|
bool WII::getButtonPress(Button b) { // Return true when a button is pressed
|
||||||
return (ButtonState & (uint32_t)b);
|
return (ButtonState & pgm_read_dword(&BUTTONS[(uint8_t)b]));
|
||||||
}
|
}
|
||||||
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);
|
uint32_t button = pgm_read_dword(&BUTTONS[(uint8_t)b]);
|
||||||
ButtonClickState &= ~((uint32_t)b); // clear "click" event
|
bool click = (ButtonClickState & button);
|
||||||
|
ButtonClickState &= ~button; // clear "click" event
|
||||||
return click;
|
return click;
|
||||||
}
|
}
|
||||||
uint8_t WII::getAnalogHat(AnalogHat a) {
|
uint8_t WII::getAnalogHat(Hat a) {
|
||||||
if(!nunchuckConnected)
|
if(!nunchuckConnected)
|
||||||
return 127; // Return center position
|
return 127; // Return center position
|
||||||
else {
|
else {
|
||||||
|
|
36
Wii.h
36
Wii.h
|
@ -23,6 +23,7 @@
|
||||||
#define _wii_h_
|
#define _wii_h_
|
||||||
|
|
||||||
#include "BTD.h"
|
#include "BTD.h"
|
||||||
|
#include "controllerEnums.h"
|
||||||
|
|
||||||
//#define WIICAMERA //uncomment to enable IR camera
|
//#define WIICAMERA //uncomment to enable IR camera
|
||||||
|
|
||||||
|
@ -78,38 +79,7 @@
|
||||||
|
|
||||||
#define PAIR 1
|
#define PAIR 1
|
||||||
|
|
||||||
enum LED {
|
enum Hat {
|
||||||
LED1 = 0x10,
|
|
||||||
LED2 = 0x20,
|
|
||||||
LED3 = 0x40,
|
|
||||||
LED4 = 0x80,
|
|
||||||
|
|
||||||
LED5 = 0x90,
|
|
||||||
LED6 = 0xA0,
|
|
||||||
LED7 = 0xC0,
|
|
||||||
LED8 = 0xD0,
|
|
||||||
LED9 = 0xE0,
|
|
||||||
LED10 = 0xF0,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Button {
|
|
||||||
LEFT = 0x00001,
|
|
||||||
RIGHT = 0x00002,
|
|
||||||
DOWN = 0x00004,
|
|
||||||
UP = 0x00008,
|
|
||||||
PLUS = 0x00010,
|
|
||||||
|
|
||||||
TWO = 0x00100,
|
|
||||||
ONE = 0x00200,
|
|
||||||
B = 0x00400,
|
|
||||||
A = 0x00800,
|
|
||||||
MINUS = 0x01000,
|
|
||||||
HOME = 0x08000,
|
|
||||||
|
|
||||||
Z = 0x10000,
|
|
||||||
C = 0x20000,
|
|
||||||
};
|
|
||||||
enum AnalogHat {
|
|
||||||
HatX = 0,
|
HatX = 0,
|
||||||
HatY = 1,
|
HatY = 1,
|
||||||
};
|
};
|
||||||
|
@ -133,7 +103,7 @@ public:
|
||||||
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(Hat 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
|
||||||
double getRoll() { return roll; }; // Fusioned angle using a complimentary filter if the Motion Plus is connected
|
double getRoll() { return roll; }; // Fusioned angle using a complimentary filter if the Motion Plus is connected
|
||||||
|
|
74
controllerEnums.h
Normal file
74
controllerEnums.h
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/* 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 _controllerenums_h
|
||||||
|
#define _controllerenums_h
|
||||||
|
|
||||||
|
|
||||||
|
enum LED {
|
||||||
|
/* Enum used to turn on the LEDs on the different controllers */
|
||||||
|
LED1 = 0,
|
||||||
|
LED2 = 1,
|
||||||
|
LED3 = 2,
|
||||||
|
LED4 = 3,
|
||||||
|
|
||||||
|
LED5 = 4,
|
||||||
|
LED6 = 5,
|
||||||
|
LED7 = 6,
|
||||||
|
LED8 = 7,
|
||||||
|
LED9 = 8,
|
||||||
|
LED10 = 9,
|
||||||
|
};
|
||||||
|
enum Button {
|
||||||
|
UP = 0,
|
||||||
|
RIGHT = 1,
|
||||||
|
DOWN = 2,
|
||||||
|
LEFT = 3,
|
||||||
|
|
||||||
|
/* Wii buttons */
|
||||||
|
PLUS = 4,
|
||||||
|
TWO = 5,
|
||||||
|
ONE = 6,
|
||||||
|
B = 7,
|
||||||
|
A = 8,
|
||||||
|
MINUS = 9,
|
||||||
|
HOME = 10,
|
||||||
|
Z = 11,
|
||||||
|
C = 12,
|
||||||
|
|
||||||
|
/* PS3 controllers buttons */
|
||||||
|
SELECT = 13,
|
||||||
|
L3 = 14,
|
||||||
|
R3 = 15,
|
||||||
|
START = 16,
|
||||||
|
|
||||||
|
L2 = 17,
|
||||||
|
R2 = 18,
|
||||||
|
L1 = 19,
|
||||||
|
R1 = 20,
|
||||||
|
TRIANGLE = 21,
|
||||||
|
CIRCLE = 22,
|
||||||
|
CROSS = 23,
|
||||||
|
SQUARE = 24,
|
||||||
|
|
||||||
|
PS = 25,
|
||||||
|
|
||||||
|
MOVE = 26, // covers 12 bits - we only need to read the top 8
|
||||||
|
T = 27, // covers 12 bits - we only need to read the top 8
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue