mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Fixed support for multiple Wiimotes
This commit is contained in:
parent
ca0c34135d
commit
86a3392f6a
2 changed files with 17 additions and 4 deletions
20
Wii.cpp
20
Wii.cpp
|
@ -96,7 +96,18 @@ void WII::disconnect() { // Use this void to disconnect any of the controllers
|
|||
}
|
||||
|
||||
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[8] == L2CAP_CMD_COMMAND_REJECT) {
|
||||
#ifdef DEBUG
|
||||
|
@ -469,6 +480,10 @@ void WII::ACLData(uint8_t* l2capinbuf) {
|
|||
pitchGyroScale = 400;
|
||||
yawGyroScale = 415;
|
||||
|
||||
gyroYaw = 0;
|
||||
gyroRoll = 0;
|
||||
gyroPitch = 0;
|
||||
|
||||
motionValuesReset = true;
|
||||
timer = micros();
|
||||
}
|
||||
|
@ -647,9 +662,6 @@ void WII::Run() {
|
|||
pBtd->l2cap_connection_request(hci_handle,identifier,control_dcid,HID_CTRL_PSM);
|
||||
l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST;
|
||||
} 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
|
||||
|
|
|
@ -38,6 +38,7 @@ void loop() {
|
|||
if(Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
|
||||
Serial.print(F("\r\nHOME"));
|
||||
Wii[i]->disconnect();
|
||||
delay(1000); // This delay is needed for some Wiimotes, so it doesn't try to reconnect right away
|
||||
}
|
||||
else {
|
||||
if(Wii[i]->getButtonClick(LEFT)) {
|
||||
|
|
Loading…
Reference in a new issue