Fixed support for multiple Wiimotes

This commit is contained in:
Kristian Sloth Lauszus 2013-01-31 21:58:13 +01:00
parent ca0c34135d
commit 86a3392f6a
2 changed files with 17 additions and 4 deletions

20
Wii.cpp
View file

@ -96,7 +96,18 @@ void WII::disconnect() { // Use this void to disconnect any of the controllers
} }
void WII::ACLData(uint8_t* l2capinbuf) { 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 if(!pBtd->l2capConnectionClaimed && pBtd->incomingWii && !wiimoteConnected && !activeConnection) {
if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
pBtd->incomingWii = false;
pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
activeConnection = true;
hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
l2cap_state = L2CAP_WAIT;
}
}
}
if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) { // acl_handle_ok or it's a new connection
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG #ifdef DEBUG
@ -468,6 +479,10 @@ void WII::ACLData(uint8_t* l2capinbuf) {
rollGyroScale = 500; // You might need to adjust these rollGyroScale = 500; // You might need to adjust these
pitchGyroScale = 400; pitchGyroScale = 400;
yawGyroScale = 415; yawGyroScale = 415;
gyroYaw = 0;
gyroRoll = 0;
gyroPitch = 0;
motionValuesReset = true; motionValuesReset = true;
timer = micros(); timer = micros();
@ -647,9 +662,6 @@ void WII::Run() {
pBtd->l2cap_connection_request(hci_handle,identifier,control_dcid,HID_CTRL_PSM); pBtd->l2cap_connection_request(hci_handle,identifier,control_dcid,HID_CTRL_PSM);
l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST; l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST;
} else if (l2cap_connection_request_control_flag) { } else if (l2cap_connection_request_control_flag) {
hci_handle = pBtd->hci_handle;
pBtd->incomingWii = false;
activeConnection = true;
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nHID Control Incoming Connection Request")); Notify(PSTR("\r\nHID Control Incoming Connection Request"));
#endif #endif

View file

@ -38,6 +38,7 @@ void loop() {
if(Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down if(Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
Serial.print(F("\r\nHOME")); Serial.print(F("\r\nHOME"));
Wii[i]->disconnect(); Wii[i]->disconnect();
delay(1000); // This delay is needed for some Wiimotes, so it doesn't try to reconnect right away
} }
else { else {
if(Wii[i]->getButtonClick(LEFT)) { if(Wii[i]->getButtonClick(LEFT)) {