mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Now the XBOXRECV doesn't conflict as well
Also hci_handle is reset when you disconnect
This commit is contained in:
parent
d2bb7b8338
commit
a96c3c4633
8 changed files with 85 additions and 76 deletions
|
@ -77,7 +77,7 @@ uint8_t PS3BT::getAnalogButton(Button a) {
|
|||
uint8_t PS3BT::getAnalogHat(AnalogHat a) {
|
||||
if (l2capinbuf == NULL)
|
||||
return 0;
|
||||
return (uint8_t)(l2capinbuf[(uint16_t)a]);
|
||||
return (uint8_t)(l2capinbuf[(uint8_t)a+15]);
|
||||
}
|
||||
int16_t PS3BT::getSensor(Sensor a) {
|
||||
if (l2capinbuf == NULL)
|
||||
|
@ -496,6 +496,7 @@ void PS3BT::L2CAP_task() {
|
|||
Notify(PSTR("\r\nDisconnected Control Channel"));
|
||||
#endif
|
||||
pBtd->hci_disconnect(hci_handle);
|
||||
hci_handle = -1; // Reset handle
|
||||
l2cap_event_flag = 0; // Reset flags
|
||||
l2cap_state = L2CAP_WAIT;
|
||||
}
|
||||
|
|
17
PS3Enums.h
17
PS3Enums.h
|
@ -42,19 +42,19 @@ const uint32_t BUTTONS[] PROGMEM = {
|
|||
0x01, // SELECT
|
||||
0x02, // L3
|
||||
0x04, // R3
|
||||
0x08, // START
|
||||
0x08, // START
|
||||
|
||||
0x0100, // L2
|
||||
0x0200, // R2
|
||||
0x0400, // L1
|
||||
0x0800, // R1
|
||||
|
||||
0x1000, // TRIANGLE
|
||||
0x2000, // CIRCLE
|
||||
0x4000, // CROSS
|
||||
0x8000, // SQUARE
|
||||
|
||||
0x010000, // PS
|
||||
|
||||
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
|
||||
};
|
||||
|
@ -78,7 +78,7 @@ const uint8_t ANALOGBUTTONS[] PROGMEM = {
|
|||
34, // SQUARE_ANALOG
|
||||
0,0, // Skip PS and MOVE
|
||||
|
||||
//Playstation Move Controller
|
||||
// Playstation Move Controller
|
||||
15 // T_ANALOG - Both at byte 14 (last reading) and byte 15 (current reading)
|
||||
};
|
||||
|
||||
|
@ -95,13 +95,6 @@ enum Colors {
|
|||
White = 0xFFFFFF, // r = 255, g = 255, b = 255
|
||||
Off = 0x00, // r = 0, g = 0, b = 0
|
||||
};
|
||||
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
|
||||
|
@ -162,4 +155,4 @@ enum Rumble {
|
|||
RumbleLow = 0x20,
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -343,7 +343,7 @@ uint8_t PS3USB::getAnalogButton(Button a) {
|
|||
uint8_t PS3USB::getAnalogHat(AnalogHat a) {
|
||||
if (readBuf == NULL)
|
||||
return 0;
|
||||
return (uint8_t)(readBuf[((uint16_t)a)-9]);
|
||||
return (uint8_t)(readBuf[((uint8_t)a+6)]);
|
||||
}
|
||||
uint16_t PS3USB::getSensor(Sensor a) {
|
||||
if (readBuf == NULL)
|
||||
|
|
1
SPP.cpp
1
SPP.cpp
|
@ -432,6 +432,7 @@ void SPP::SDP_task() {
|
|||
RFCOMMConnected = false;
|
||||
SDPConnected = false;
|
||||
pBtd->hci_disconnect(hci_handle);
|
||||
hci_handle = -1; // Reset handle
|
||||
l2cap_event_flag = 0; // Reset flags
|
||||
l2cap_sdp_state = L2CAP_SDP_WAIT;
|
||||
l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
|
||||
|
|
17
Wii.cpp
17
Wii.cpp
|
@ -44,17 +44,18 @@ const uint32_t BUTTONS[] PROGMEM = {
|
|||
0x00004, // DOWN
|
||||
0x00001, // LEFT
|
||||
|
||||
0, // Skip
|
||||
0x00010, // PLUS
|
||||
|
||||
0x00100, // TWO
|
||||
0x00200, // ONE
|
||||
0x00400, // B
|
||||
0x00800, // A
|
||||
|
||||
0x01000, // MINUS
|
||||
0x08000, // HOME
|
||||
|
||||
0x10000, // Z
|
||||
0x20000 // C
|
||||
0x20000, // C
|
||||
|
||||
0x00400, // B
|
||||
0x00800 // A
|
||||
};
|
||||
|
||||
WII::WII(BTD *p, bool pair):
|
||||
|
@ -82,6 +83,7 @@ void WII::Reset() {
|
|||
activateNunchuck = false;
|
||||
motionValuesReset = false;
|
||||
activeConnection = false;
|
||||
pBtd->motionPlusInside = false;
|
||||
l2cap_event_flag = 0; // Reset flags
|
||||
l2cap_state = L2CAP_WAIT;
|
||||
}
|
||||
|
@ -91,13 +93,10 @@ void WII::disconnect() { // Use this void to disconnect any of the controllers
|
|||
pBtd->l2cap_disconnection_request(hci_handle,0x0A, interrupt_scid, interrupt_dcid);
|
||||
Reset();
|
||||
l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
|
||||
pBtd->motionPlusInside = false;
|
||||
}
|
||||
|
||||
void WII::ACLData(uint8_t* l2capinbuf) {
|
||||
if (((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) || (pBtd->incomingWii && !wiimoteConnected && !activeConnection)) { // acl_handle_ok or it's a new connection
|
||||
pBtd->incomingWii = false;
|
||||
activeConnection = true;
|
||||
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
|
||||
if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
|
||||
#ifdef DEBUG
|
||||
|
@ -626,6 +625,7 @@ void WII::L2CAP_task() {
|
|||
Notify(PSTR("\r\nDisconnected Control Channel"));
|
||||
#endif
|
||||
pBtd->hci_disconnect(hci_handle);
|
||||
hci_handle = -1; // Reset handle
|
||||
l2cap_event_flag = 0; // Reset flags
|
||||
l2cap_state = L2CAP_WAIT;
|
||||
}
|
||||
|
@ -649,6 +649,7 @@ void WII::Run() {
|
|||
} else if (l2cap_connection_request_control_flag) {
|
||||
hci_handle = pBtd->hci_handle;
|
||||
pBtd->incomingWii = false;
|
||||
activeConnection = true;
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nHID Control Incoming Connection Request"));
|
||||
#endif
|
||||
|
|
44
XBOXRECV.cpp
44
XBOXRECV.cpp
|
@ -22,6 +22,37 @@
|
|||
//#define EXTRADEBUG // Uncomment to get even more debugging data
|
||||
//#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller
|
||||
|
||||
const uint8_t LEDS[] PROGMEM = {
|
||||
0x02, // LED1
|
||||
0x03, // LED2
|
||||
0x04, // LED3
|
||||
0x05, // LED4
|
||||
0x01 // ALL - Used to blink all LEDs
|
||||
};
|
||||
const uint16_t BUTTONS[] PROGMEM = {
|
||||
0x0100, // UP
|
||||
0x0800, // RIGHT
|
||||
0x0200, // DOWN
|
||||
0x0400, // LEFT
|
||||
|
||||
0x2000, // BACK
|
||||
0x4000, // L3
|
||||
0x8000, // R3
|
||||
0x1000, // START
|
||||
|
||||
0,0, // Skip L2 and R2 as these are analog buttons
|
||||
0x0001, // L1
|
||||
0x0002, // R1
|
||||
|
||||
0x0020, // B
|
||||
0x0010, // A
|
||||
0x0040, // X
|
||||
0x0080, // Y
|
||||
|
||||
0x0004, // XBOX
|
||||
0x0008 // SYNC
|
||||
};
|
||||
|
||||
XBOXRECV::XBOXRECV(USB *p):
|
||||
pUsb(p), // pointer to USB class instance - mandatory
|
||||
bAddress(0), // device address - mandatory
|
||||
|
@ -381,7 +412,7 @@ uint8_t XBOXRECV::getButtonPress(uint8_t controller, Button b) {
|
|||
return (uint8_t)(ButtonState[controller] >> 8);
|
||||
else if(b == R2)
|
||||
return (uint8_t)ButtonState[controller];
|
||||
return (ButtonState[controller] & ((uint32_t)b << 16));
|
||||
return (ButtonState[controller] & ((uint32_t)pgm_read_word(&BUTTONS[(uint8_t)b]) << 16));
|
||||
}
|
||||
bool XBOXRECV::getButtonClick(uint8_t controller, Button b) {
|
||||
if(b == L2) {
|
||||
|
@ -391,15 +422,16 @@ bool XBOXRECV::getButtonClick(uint8_t controller, Button b) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
else if(b== R2) {
|
||||
else if(b == R2) {
|
||||
if(R2Clicked[controller]) {
|
||||
R2Clicked[controller] = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool click = (ButtonClickState[controller] & (uint16_t)b);
|
||||
ButtonClickState[controller] &= ~((uint16_t)b); // clear "click" event
|
||||
uint16_t button = pgm_read_word(&BUTTONS[(uint8_t)b]);
|
||||
bool click = (ButtonClickState[controller] & button);
|
||||
ButtonClickState[controller] &= ~button; // clear "click" event
|
||||
return click;
|
||||
}
|
||||
int16_t XBOXRECV::getAnalogHat(uint8_t controller, AnalogHat a) {
|
||||
|
@ -461,10 +493,10 @@ void XBOXRECV::setLedRaw(uint8_t controller, uint8_t value) {
|
|||
}
|
||||
void XBOXRECV::setLedOn(uint8_t controller, LED led) {
|
||||
if(led != ALL) // All LEDs can't be on a the same time
|
||||
setLedRaw(controller,((uint8_t)led)+4);
|
||||
setLedRaw(controller,(pgm_read_byte(&LEDS[(uint8_t)led]))+4);
|
||||
}
|
||||
void XBOXRECV::setLedBlink(uint8_t controller, LED led) {
|
||||
setLedRaw(controller,(uint8_t)led);
|
||||
setLedRaw(controller,pgm_read_byte(&LEDS[(uint8_t)led]));
|
||||
}
|
||||
void XBOXRECV::setLedMode(uint8_t controller, LEDMode ledMode) { // This function is used to do some speciel LED stuff the controller supports
|
||||
setLedRaw(controller,(uint8_t)ledMode);
|
||||
|
|
40
XBOXRECV.h
40
XBOXRECV.h
|
@ -27,6 +27,7 @@
|
|||
#endif
|
||||
|
||||
#include "Usb.h"
|
||||
#include "controllerEnums.h"
|
||||
|
||||
/* Data Xbox 360 taken from descriptors */
|
||||
#define EP_MAXPKTSIZE 32 // max size for data via USB
|
||||
|
@ -54,13 +55,6 @@
|
|||
|
||||
#define XBOX_MAX_ENDPOINTS 9
|
||||
|
||||
enum LED {
|
||||
ALL = 0x01, // Used to blink all LEDs
|
||||
LED1 = 0x02,
|
||||
LED2 = 0x03,
|
||||
LED3 = 0x04,
|
||||
LED4 = 0x05,
|
||||
};
|
||||
enum LEDMode {
|
||||
ROTATING = 0x0A,
|
||||
FASTBLINK = 0x0B,
|
||||
|
@ -68,38 +62,6 @@ enum LEDMode {
|
|||
ALTERNATING = 0x0D,
|
||||
};
|
||||
|
||||
enum Button {
|
||||
L1 = 0x0001,
|
||||
R1 = 0x0002,
|
||||
XBOX = 0x0004,
|
||||
SYNC = 0x0008,
|
||||
|
||||
A = 0x0010,
|
||||
B = 0x0020,
|
||||
X = 0x0040,
|
||||
Y = 0x0080,
|
||||
|
||||
UP = 0x0100,
|
||||
DOWN = 0x0200,
|
||||
LEFT = 0x0400,
|
||||
RIGHT = 0x0800,
|
||||
|
||||
START = 0x1000,
|
||||
BACK = 0x2000,
|
||||
L3 = 0x4000,
|
||||
R3 = 0x8000,
|
||||
|
||||
// These buttons are analog buttons
|
||||
L2,
|
||||
R2,
|
||||
};
|
||||
enum AnalogHat {
|
||||
LeftHatX = 0,
|
||||
LeftHatY = 1,
|
||||
RightHatX = 2,
|
||||
RightHatY = 3,
|
||||
};
|
||||
|
||||
class XBOXRECV : public USBDeviceConfig {
|
||||
public:
|
||||
XBOXRECV(USB *pUsb);
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
#ifndef _controllerenums_h
|
||||
#define _controllerenums_h
|
||||
|
||||
/*
|
||||
This header file is used to store different enums for the controllers,
|
||||
This is necessary so all the different libraries can be used at once
|
||||
*/
|
||||
|
||||
enum LED {
|
||||
/* Enum used to turn on the LEDs on the different controllers */
|
||||
|
@ -32,6 +36,7 @@ enum LED {
|
|||
LED8 = 7,
|
||||
LED9 = 8,
|
||||
LED10 = 9,
|
||||
ALL = 4, // Used to blink all LEDs on the Xbox controller
|
||||
};
|
||||
enum Button {
|
||||
UP = 0,
|
||||
|
@ -40,15 +45,15 @@ enum Button {
|
|||
LEFT = 3,
|
||||
|
||||
/* Wii buttons */
|
||||
PLUS = 4,
|
||||
TWO = 5,
|
||||
ONE = 6,
|
||||
B = 7,
|
||||
A = 8,
|
||||
MINUS = 9,
|
||||
HOME = 10,
|
||||
Z = 11,
|
||||
C = 12,
|
||||
PLUS = 5,
|
||||
TWO = 6,
|
||||
ONE = 7,
|
||||
MINUS = 8,
|
||||
HOME = 9,
|
||||
Z = 10,
|
||||
C = 11,
|
||||
B = 12,
|
||||
A = 13,
|
||||
|
||||
/* PS3 controllers buttons */
|
||||
SELECT = 4,
|
||||
|
@ -69,6 +74,20 @@ enum Button {
|
|||
|
||||
MOVE = 17, // covers 12 bits - we only need to read the top 8
|
||||
T = 18, // covers 12 bits - we only need to read the top 8
|
||||
|
||||
/* Xbox buttons */
|
||||
BACK = 4,
|
||||
X = 14,
|
||||
Y = 15,
|
||||
XBOX = 16,
|
||||
SYNC = 17,
|
||||
};
|
||||
enum AnalogHat {
|
||||
/* Joysticks on the PS3 and Xbox controllers */
|
||||
LeftHatX = 0,
|
||||
LeftHatY = 1,
|
||||
RightHatX = 2,
|
||||
RightHatY = 3,
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue