This commit is contained in:
Oleg Mazurov 2013-04-30 14:07:55 -06:00
commit 9813e7a565
11 changed files with 135 additions and 171 deletions

12
BTD.cpp
View file

@ -373,7 +373,7 @@ void BTD::HCI_event_task() {
if (hcibuf[2]) { // Check that there is more than zero responses if (hcibuf[2]) { // Check that there is more than zero responses
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
Notify(PSTR("\r\nNumber of responses: "), 0x80); Notify(PSTR("\r\nNumber of responses: "), 0x80);
Serial.print(hcibuf[2]); Notify(hcibuf[2], 0x80);
#endif #endif
for (uint8_t i = 0; i < hcibuf[2]; i++) { for (uint8_t i = 0; i < hcibuf[2]; i++) {
if ((hcibuf[4 + 8 * hcibuf[2] + 3 * i] == 0x04 && hcibuf[5 + 8 * hcibuf[2] + 3 * i] == 0x25 && hcibuf[6 + 8 * hcibuf[2] + 3 * i] == 0x00) || (hcibuf[4 + 8 * hcibuf[2] + 3 * i] == 0x08 && hcibuf[5 + 8 * hcibuf[2] + 3 * i] == 0x05 && hcibuf[6 + 8 * hcibuf[2] + 3 * i] == 0x00)) { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html and http://wiibrew.org/wiki/Wiimote#SDP_information if ((hcibuf[4 + 8 * hcibuf[2] + 3 * i] == 0x04 && hcibuf[5 + 8 * hcibuf[2] + 3 * i] == 0x25 && hcibuf[6 + 8 * hcibuf[2] + 3 * i] == 0x00) || (hcibuf[4 + 8 * hcibuf[2] + 3 * i] == 0x08 && hcibuf[5 + 8 * hcibuf[2] + 3 * i] == 0x05 && hcibuf[6 + 8 * hcibuf[2] + 3 * i] == 0x00)) { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html and http://wiibrew.org/wiki/Wiimote#SDP_information
@ -460,7 +460,7 @@ void BTD::HCI_event_task() {
} else if (btdPin != NULL) { } else if (btdPin != NULL) {
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80); Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80);
Serial.print(btdPin); NotifyStr(btdPin, 0x80);
#endif #endif
hci_pin_code_request_reply(); hci_pin_code_request_reply();
} else { } else {
@ -590,7 +590,7 @@ void BTD::HCI_task() {
if (hci_cmd_complete) { if (hci_cmd_complete) {
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nThe name is set to: "), 0x80); Notify(PSTR("\r\nThe name is set to: "), 0x80);
Serial.print(btdName); NotifyStr(btdName, 0x80);
#endif #endif
hci_state = HCI_CHECK_WII_SERVICE; hci_state = HCI_CHECK_WII_SERVICE;
} }
@ -681,7 +681,7 @@ void BTD::HCI_task() {
for (uint8_t i = 0; i < 30; i++) { for (uint8_t i = 0; i < 30; i++) {
if (remote_name[i] == NULL) if (remote_name[i] == NULL)
break; break;
Serial.write(remote_name[i]); Notifyc(remote_name[i], 0x80);
} }
#endif #endif
if (strncmp((const char*)remote_name, "Nintendo", 8) == 0) { if (strncmp((const char*)remote_name, "Nintendo", 8) == 0) {
@ -1073,9 +1073,9 @@ void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t
Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80); Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80);
PrintHex<uint8_t > (rcode, 0x80); PrintHex<uint8_t > (rcode, 0x80);
Notify(PSTR(" - Channel ID: "), 0x80); Notify(PSTR(" - Channel ID: "), 0x80);
Serial.print(channelHigh); PrintHex<uint8_t > (channelHigh, 0x80);
Notify(PSTR(" "), 0x80); Notify(PSTR(" "), 0x80);
Serial.print(channelLow); PrintHex<uint8_t > (channelLow, 0x80);
#endif #endif
} }
} }

View file

@ -258,7 +258,7 @@ void PS3BT::ACLData(uint8_t* ACLData) {
#ifdef DEBUG #ifdef DEBUG
if (pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle if (pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle
Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80); Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80);
Serial.print(pBtd->hci_version); Notify(pBtd->hci_version, 0x80);
Notify(PSTR("\r\nBut should be at least 3\r\nThis means that it doesn't support Bluetooth Version 2.0+EDR"), 0x80); Notify(PSTR("\r\nBut should be at least 3\r\nThis means that it doesn't support Bluetooth Version 2.0+EDR"), 0x80);
} }
#endif #endif
@ -273,15 +273,15 @@ void PS3BT::ACLData(uint8_t* ACLData) {
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
PrintHex<uint8_t > (l2capinbuf[13], 0x80); PrintHex<uint8_t > (l2capinbuf[13], 0x80);
Serial.print(" "); Notify(PSTR(" "), 0x80);
PrintHex<uint8_t > (l2capinbuf[12], 0x80); PrintHex<uint8_t > (l2capinbuf[12], 0x80);
Serial.print(" Data: "); Notify(PSTR(" Data: "), 0x80);
PrintHex<uint8_t > (l2capinbuf[17], 0x80); PrintHex<uint8_t > (l2capinbuf[17], 0x80);
Serial.print(" "); Notify(PSTR(" "), 0x80);
PrintHex<uint8_t > (l2capinbuf[16], 0x80); PrintHex<uint8_t > (l2capinbuf[16], 0x80);
Serial.print(" "); Notify(PSTR(" "), 0x80);
PrintHex<uint8_t > (l2capinbuf[15], 0x80); PrintHex<uint8_t > (l2capinbuf[15], 0x80);
Serial.print(" "); Notify(PSTR(" "), 0x80);
PrintHex<uint8_t > (l2capinbuf[14], 0x80); PrintHex<uint8_t > (l2capinbuf[14], 0x80);
#endif #endif
} else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) { } else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
@ -311,20 +311,20 @@ void PS3BT::ACLData(uint8_t* ACLData) {
} else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) { } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
//Serial.print("\r\nHID Control Configuration Complete"); //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_SUCCESS; l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_SUCCESS;
} else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
//Serial.print("\r\nHID Interrupt Configuration Complete"); //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS; l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS;
} }
} }
} else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) { } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
//Serial.print("\r\nHID Control Configuration Request"); //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_REQUEST; l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_REQUEST;
} else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
//Serial.print("\r\nHID Interrupt Configuration Request"); //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST; l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST;
} }
@ -346,11 +346,11 @@ void PS3BT::ACLData(uint8_t* ACLData) {
} }
} else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) { } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
if (l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) { if (l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
//Serial.print("\r\nDisconnect Response: Control Channel"); //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE;
} else if (l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) { } else if (l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
//Serial.print("\r\nDisconnect Response: Interrupt Channel"); //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE;
} }
@ -362,7 +362,7 @@ void PS3BT::ACLData(uint8_t* ACLData) {
} }
#endif #endif
} else if (l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt } else if (l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
//Serial.print("\r\nL2CAP Interrupt"); //Notify(PSTR("\r\nL2CAP Interrupt"), 0x80);
if (PS3Connected || PS3MoveConnected || PS3NavigationConnected) { if (PS3Connected || PS3MoveConnected || PS3NavigationConnected) {
/* Read Report */ /* Read Report */
if (l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT if (l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
@ -382,9 +382,9 @@ void PS3BT::ACLData(uint8_t* ACLData) {
#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++) {
PrintHex<uint8_t > (l2capinbuf[i], 0x80); PrintHex<uint8_t > (l2capinbuf[i], 0x80);
Serial.print(" "); Notify(PSTR(" "), 0x80);
} }
Serial.println(); Notify(PSTR("\r\n"), 0x80);
#endif #endif
} }
} }

View file

@ -205,6 +205,15 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work
} }
#ifdef DEBUG
Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
for (int8_t i = 5; i > 0; i--) {
PrintHex<uint8_t > (my_bdaddr[i], 0x80);
Notify(PSTR(":"), 0x80);
}
PrintHex<uint8_t > (my_bdaddr[0], 0x80);
#endif
bPollEnable = true; bPollEnable = true;
Notify(PSTR("\r\n"), 0x80); Notify(PSTR("\r\n"), 0x80);
timer = millis(); timer = millis();
@ -290,9 +299,9 @@ void PS3USB::printReport() { //Uncomment "#define PRINTREPORT" to print the repo
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], 0x80); PrintHex<uint8_t > (readBuf[i], 0x80);
Serial.print(" "); Notify(PSTR(" "), 0x80);
} }
Serial.println(); Notify(PSTR("\r\n"), 0x80);
#endif #endif
} }
@ -462,15 +471,6 @@ void PS3USB::setBdaddr(uint8_t* BDADDR) {
//bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data) //bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data)
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
Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
for (int8_t i = 5; i > 0; i--) {
PrintHex<uint8_t > (my_bdaddr[i], 0x80);
Serial.print(":");
}
PrintHex<uint8_t > (my_bdaddr[0], 0x80);
#endif
return;
} }
void PS3USB::enable_sixaxis() { //Command used to enable the Dualshock 3 and Navigation controller to send data via USB void PS3USB::enable_sixaxis() { //Command used to enable the Dualshock 3 and Navigation controller to send data via USB
@ -527,13 +527,4 @@ void PS3USB::setMoveBdaddr(uint8_t* BDADDR) {
//bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x05), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data) //bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x05), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data)
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
Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
for (int8_t i = 5; i > 0; i--) {
PrintHex<uint8_t > (my_bdaddr[i], 0x80);
Serial.print(":");
}
PrintHex<uint8_t > (my_bdaddr[0], 0x80);
#endif
return;
} }

107
SPP.cpp
View file

@ -139,20 +139,20 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
} else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) { } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) { if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
//Serial.print("\r\nSDP Configuration Complete"); //Notify(PSTR("\r\nSDP Configuration Complete"), 0x80);
l2cap_event_flag |= L2CAP_FLAG_CONFIG_SDP_SUCCESS; l2cap_event_flag |= L2CAP_FLAG_CONFIG_SDP_SUCCESS;
} else if (l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) { } else if (l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) {
//Serial.print("\r\nRFCOMM Configuration Complete"); //Notify(PSTR("\r\nRFCOMM Configuration Complete"), 0x80);
l2cap_event_flag |= L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS; l2cap_event_flag |= L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS;
} }
} }
} else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) { } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) { if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
//Serial.print("\r\nSDP Configuration Request"); //Notify(PSTR("\r\nSDP Configuration Request"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_CONFIG_SDP_REQUEST; l2cap_event_flag |= L2CAP_FLAG_CONFIG_SDP_REQUEST;
} else if (l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) { } else if (l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) {
//Serial.print("\r\nRFCOMM Configuration Request"); //Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_CONFIG_RFCOMM_REQUEST; l2cap_event_flag |= L2CAP_FLAG_CONFIG_RFCOMM_REQUEST;
} }
@ -168,11 +168,11 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
} }
} else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) { } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
if (l2capinbuf[12] == sdp_scid[0] && l2capinbuf[13] == sdp_scid[1]) { if (l2capinbuf[12] == sdp_scid[0] && l2capinbuf[13] == sdp_scid[1]) {
//Serial.print("\r\nDisconnect Response: SDP Channel"); //Notify(PSTR("\r\nDisconnect Response: SDP Channel"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE;
} else if (l2capinbuf[12] == rfcomm_scid[0] && l2capinbuf[13] == rfcomm_scid[1]) { } else if (l2capinbuf[12] == rfcomm_scid[0] && l2capinbuf[13] == rfcomm_scid[1]) {
//Serial.print("\r\nDisconnect Response: RFCOMM Channel"); //Notify(PSTR("\r\nDisconnect Response: RFCOMM Channel"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE;
} }
@ -207,7 +207,8 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
l2capResponse2(l2capinbuf[9], l2capinbuf[10]); // L2CAP continuation state l2capResponse2(l2capinbuf[9], l2capinbuf[10]); // L2CAP continuation state
firstMessage = true; firstMessage = true;
} }
} else { } else
serviceNotSupported(l2capinbuf[9], l2capinbuf[10]); // The service is not supported
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
Notify(PSTR("\r\nUUID: "), 0x80); Notify(PSTR("\r\nUUID: "), 0x80);
uint16_t uuid; uint16_t uuid;
@ -226,8 +227,6 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
Notify(PSTR(" "), 0x80); Notify(PSTR(" "), 0x80);
} }
#endif #endif
serviceNotSupported(l2capinbuf[9], l2capinbuf[10]); // The service is not supported
}
} }
} else if (l2capinbuf[6] == rfcomm_dcid[0] && l2capinbuf[7] == rfcomm_dcid[1]) { // RFCOMM } else if (l2capinbuf[6] == rfcomm_dcid[0] && l2capinbuf[7] == rfcomm_dcid[1]) { // RFCOMM
rfcommChannel = l2capinbuf[8] & 0xF8; rfcommChannel = l2capinbuf[8] & 0xF8;
@ -241,20 +240,20 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
Notify(PSTR("\r\nRFCOMM Channel: "), 0x80); Notify(PSTR("\r\nRFCOMM Channel: "), 0x80);
Serial.print(rfcommChannel >> 3, HEX); PrintHex<uint8_t > (rfcommChannel >> 3, 0x80);
Notify(PSTR(" Direction: "), 0x80); Notify(PSTR(" Direction: "), 0x80);
Serial.print(rfcommDirection >> 2, HEX); PrintHex<uint8_t > (rfcommDirection >> 2, 0x80);
Notify(PSTR(" CommandResponse: "), 0x80); Notify(PSTR(" CommandResponse: "), 0x80);
Serial.print(rfcommCommandResponse >> 1, HEX); PrintHex<uint8_t > (rfcommCommandResponse >> 1, 0x80);
Notify(PSTR(" ChannelType: "), 0x80); Notify(PSTR(" ChannelType: "), 0x80);
Serial.print(rfcommChannelType, HEX); PrintHex<uint8_t > (rfcommChannelType, 0x80);
Notify(PSTR(" PF_BIT: "), 0x80); Notify(PSTR(" PF_BIT: "), 0x80);
Serial.print(rfcommPfBit, HEX); PrintHex<uint8_t > (rfcommPfBit, 0x80);
#endif #endif
if (rfcommChannelType == RFCOMM_DISC) { if (rfcommChannelType == RFCOMM_DISC) {
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nReceived Disconnect RFCOMM Command on channel: "), 0x80); Notify(PSTR("\r\nReceived Disconnect RFCOMM Command on channel: "), 0x80);
Serial.print(rfcommChannel >> 3, HEX); PrintHex<uint8_t > (rfcommChannel >> 3, 0x80);
#endif #endif
connected = false; connected = false;
sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command
@ -271,15 +270,15 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
} }
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
Notify(PSTR("\r\nRFCOMM Data Available: "), 0x80); Notify(PSTR("\r\nRFCOMM Data Available: "), 0x80);
Serial.print(rfcommAvailable); Notify(rfcommAvailable, 0x80);
if (offset) { if (offset) {
Notify(PSTR(" - Credit: 0x"), 0x80); Notify(PSTR(" - Credit: 0x"), 0x80);
Serial.print(l2capinbuf[11], HEX); PrintHex<uint8_t > (l2capinbuf[11], 0x80);
} }
#endif #endif
#ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send to the Arduino via Bluetooth #ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send to the Arduino via Bluetooth
for (uint8_t i = 0; i < length; i++) for (uint8_t i = 0; i < length; i++)
Serial.write(l2capinbuf[i + 11 + offset]); Notifyc(l2capinbuf[i + 11 + offset], 0x80);
#endif #endif
} else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command
#ifdef DEBUG #ifdef DEBUG
@ -681,7 +680,7 @@ void SPP::RFCOMM_Command(uint8_t* data, uint8_t nbytes) {
void SPP::sendRfcomm(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t* data, uint8_t length) { void SPP::sendRfcomm(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t* data, uint8_t length) {
l2capoutbuf[0] = channel | direction | CR | extendAddress; // RFCOMM Address l2capoutbuf[0] = channel | direction | CR | extendAddress; // RFCOMM Address
l2capoutbuf[1] = channelType | pfBit; // RFCOMM Control l2capoutbuf[1] = channelType | pfBit; // RFCOMM Control
l2capoutbuf[2] = length << 1 | 0x01; // Length and format (allways 0x01 bytes format) l2capoutbuf[2] = length << 1 | 0x01; // Length and format (always 0x01 bytes format)
uint8_t i = 0; uint8_t i = 0;
for (; i < length; i++) for (; i < length; i++)
l2capoutbuf[i + 3] = data[i]; l2capoutbuf[i + 3] = data[i];
@ -689,7 +688,7 @@ void SPP::sendRfcomm(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t cha
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
Notify(PSTR(" - RFCOMM Data: "), 0x80); Notify(PSTR(" - RFCOMM Data: "), 0x80);
for (i = 0; i < length + 4; i++) { for (i = 0; i < length + 4; i++) {
Serial.print(l2capoutbuf[i], HEX); PrintHex<uint8_t > (l2capoutbuf[i], 0x80);
Notify(PSTR(" "), 0x80); Notify(PSTR(" "), 0x80);
} }
#endif #endif
@ -705,7 +704,7 @@ void SPP::sendRfcommCredit(uint8_t channel, uint8_t direction, uint8_t CR, uint8
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
Notify(PSTR(" - RFCOMM Credit Data: "), 0x80); Notify(PSTR(" - RFCOMM Credit Data: "), 0x80);
for (uint8_t i = 0; i < 5; i++) { for (uint8_t i = 0; i < 5; i++) {
Serial.print(l2capoutbuf[i], HEX); PrintHex<uint8_t > (l2capoutbuf[i], 0x80);
Notify(PSTR(" "), 0x80); Notify(PSTR(" "), 0x80);
} }
#endif #endif
@ -727,64 +726,20 @@ uint8_t SPP::calcFcs(uint8_t *data) {
/* Serial commands */ /* Serial commands */
void SPP::print(const String &str) { void SPP::print(const String &str) {
if (!connected) uint8_t length = str.length(); // Get the length of the string
return; uint8_t buf[length];
int16_t stringLength = str.length(); // This will be used to store the characters that still needs to be sent
uint8_t length; // This is the length of the string we are sending
uint8_t offset = 0; // This is used to keep track of where we are in the string
l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address for(uint8_t i = 0; i < length; i++)
l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control buf[i] = str[i];
do { print(buf,length);
if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing puffer
length = sizeof (l2capoutbuf) - 4;
else
length = stringLength;
l2capoutbuf[2] = length << 1 | 1; // Length
uint8_t i = 0;
for (; i < length; i++)
l2capoutbuf[i + 3] = str[i + offset];
l2capoutbuf[i + 3] = calcFcs(l2capoutbuf); // Calculate checksum
RFCOMM_Command(l2capoutbuf, length + 4);
stringLength -= length;
offset += length; // Increment the offset
} while (stringLength); // We will run this loop until this variable is less than 0
} }
void SPP::print(const char* str) { void SPP::print(const char* str) {
if (!connected) print((uint8_t*) str, strlen(str));
return;
int16_t stringLength = strlen(str); // This will be used to store the characters that still needs to be sent
uint8_t length; // This is the length of the string we are sending
uint8_t offset = 0; // This is used to keep track of where we are in the string
l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address
l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control
do {
if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing puffer
length = sizeof (l2capoutbuf) - 4;
else
length = stringLength;
l2capoutbuf[2] = length << 1 | 1; // Length
uint8_t i = 0;
for (; i < length; i++)
l2capoutbuf[i + 3] = str[i + offset];
l2capoutbuf[i + 3] = calcFcs(l2capoutbuf); // Calculate checksum
RFCOMM_Command(l2capoutbuf, length + 4);
stringLength -= length;
offset += length; // Increment the offset
} while (stringLength); // We will run this loop until this variable is less than 0
} }
void SPP::print(uint8_t* array, int16_t stringLength) { void SPP::print(uint8_t* array, uint8_t stringLength) {
if (!connected) if (!connected)
return; return;
uint8_t length; // This is the length of the string we are sending uint8_t length; // This is the length of the string we are sending
@ -793,8 +748,8 @@ void SPP::print(uint8_t* array, int16_t stringLength) {
l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address
l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control
do { while (stringLength) { // We will run this while loop until this variable is 0
if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing puffer if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing buffer
length = sizeof (l2capoutbuf) - 4; length = sizeof (l2capoutbuf) - 4;
else else
length = stringLength; length = stringLength;
@ -809,7 +764,7 @@ void SPP::print(uint8_t* array, int16_t stringLength) {
stringLength -= length; stringLength -= length;
offset += length; // Increment the offset offset += length; // Increment the offset
} while (stringLength); // We will run this loop until this variable is less than 0 }
} }
void SPP::println(const String &str) { void SPP::println(const String &str) {
@ -974,7 +929,7 @@ uint8_t SPP::read() {
sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send more credit sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send more credit
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
Notify(PSTR("\r\nSent "), 0x80); Notify(PSTR("\r\nSent "), 0x80);
Serial.print(sizeof (rfcommDataBuffer)); Notify((uint8_t)sizeof (rfcommDataBuffer), 0x80);
Notify(PSTR(" more credit"), 0x80); Notify(PSTR(" more credit"), 0x80);
#endif #endif
} }

10
SPP.h
View file

@ -68,7 +68,7 @@
//#define RFCOMM_DM 0x0F //#define RFCOMM_DM 0x0F
#define RFCOMM_DISC 0x43 #define RFCOMM_DISC 0x43
#define extendAddress 0x01 // Allways 1 #define extendAddress 0x01 // Always 1
// Multiplexer message types // Multiplexer message types
#define BT_RFCOMM_PN_CMD 0x83 #define BT_RFCOMM_PN_CMD 0x83
@ -158,7 +158,7 @@ public:
* @param array Array to send. * @param array Array to send.
* @param length Number of bytes to send. * @param length Number of bytes to send.
*/ */
void print(uint8_t* array, int16_t length); void print(uint8_t* array, uint8_t length);
/** /**
* Same as print(uint8_t* array, uint8_t length), but will include newline and carriage return. * Same as print(uint8_t* array, uint8_t length), but will include newline and carriage return.
* @param array Array to send. * @param array Array to send.
@ -341,10 +341,10 @@ private:
uint16_t hci_handle; // The HCI Handle for the connection uint16_t hci_handle; // The HCI Handle for the connection
/* Variables used by L2CAP state maschines */ /* Variables used by L2CAP state machines */
uint8_t l2cap_sdp_state; uint8_t l2cap_sdp_state;
uint8_t l2cap_rfcomm_state; uint8_t l2cap_rfcomm_state;
uint16_t l2cap_event_flag; // l2cap flags of received bluetooth events uint16_t l2cap_event_flag; // l2cap flags of received Bluetooth events
uint8_t l2capoutbuf[BULK_MAXPKTSIZE]; // General purpose buffer for l2cap out data uint8_t l2capoutbuf[BULK_MAXPKTSIZE]; // General purpose buffer for l2cap out data
uint8_t rfcommbuf[10]; // Buffer for RFCOMM Commands uint8_t rfcommbuf[10]; // Buffer for RFCOMM Commands
@ -358,7 +358,7 @@ private:
/* RFCOMM Variables */ /* RFCOMM Variables */
uint8_t rfcommChannel; uint8_t rfcommChannel;
uint8_t rfcommChannelConnection; // This is the channel the SPP chanel will be running at uint8_t rfcommChannelConnection; // This is the channel the SPP channel will be running at
uint8_t rfcommDirection; uint8_t rfcommDirection;
uint8_t rfcommCommandResponse; uint8_t rfcommCommandResponse;
uint8_t rfcommChannelType; uint8_t rfcommChannelType;

40
Wii.cpp
View file

@ -161,13 +161,13 @@ void WII::ACLData(uint8_t* l2capinbuf) {
} else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_RESPONSE) { } else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_RESPONSE) {
if (((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) && ((l2capinbuf[18] | (l2capinbuf[19] << 8)) == SUCCESSFUL)) { // Success if (((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) && ((l2capinbuf[18] | (l2capinbuf[19] << 8)) == SUCCESSFUL)) { // Success
if (l2capinbuf[14] == control_dcid[0] && l2capinbuf[15] == control_dcid[1]) { // Success if (l2capinbuf[14] == control_dcid[0] && l2capinbuf[15] == control_dcid[1]) { // Success
//Serial.print("\r\nHID Control Connection Complete"); //Notify(PSTR("\r\nHID Control Connection Complete"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
control_scid[0] = l2capinbuf[12]; control_scid[0] = l2capinbuf[12];
control_scid[1] = l2capinbuf[13]; control_scid[1] = l2capinbuf[13];
l2cap_event_flag |= L2CAP_FLAG_CONTROL_CONNECTED; l2cap_event_flag |= L2CAP_FLAG_CONTROL_CONNECTED;
} else if (l2capinbuf[14] == interrupt_dcid[0] && l2capinbuf[15] == interrupt_dcid[1]) { } else if (l2capinbuf[14] == interrupt_dcid[0] && l2capinbuf[15] == interrupt_dcid[1]) {
//Serial.print("\r\nHID Interrupt Connection Complete"); //Notify(PSTR("\r\nHID Interrupt Connection Complete"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
interrupt_scid[0] = l2capinbuf[12]; interrupt_scid[0] = l2capinbuf[12];
interrupt_scid[1] = l2capinbuf[13]; interrupt_scid[1] = l2capinbuf[13];
@ -201,21 +201,21 @@ void WII::ACLData(uint8_t* l2capinbuf) {
} else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) { } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
//Serial.print("\r\nHID Control Configuration Complete"); //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_SUCCESS; l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_SUCCESS;
} else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
//Serial.print("\r\nHID Interrupt Configuration Complete"); //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS; l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS;
} }
} }
} else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) { } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
//Serial.print("\r\nHID Control Configuration Request"); //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], control_scid); pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], control_scid);
} else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
//Serial.print("\r\nHID Interrupt Configuration Request"); //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], interrupt_scid); pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], interrupt_scid);
} }
} else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) { } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
@ -236,11 +236,11 @@ void WII::ACLData(uint8_t* l2capinbuf) {
} }
} else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) { } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
if (l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) { if (l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
//Serial.print("\r\nDisconnect Response: Control Channel"); //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE;
} else if (l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) { } else if (l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
//Serial.print("\r\nDisconnect Response: Interrupt Channel"); //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE;
} }
@ -253,7 +253,7 @@ void WII::ACLData(uint8_t* l2capinbuf) {
} }
#endif #endif
} else if (l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt } else if (l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
//Serial.print("\r\nL2CAP Interrupt"); //Notify(PSTR("\r\nL2CAP Interrupt"), 0x80);
if (wiimoteConnected) { if (wiimoteConnected) {
if (l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT if (l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
if ((l2capinbuf[9] >= 0x20 && l2capinbuf[9] <= 0x22) || (l2capinbuf[9] >= 0x30 && l2capinbuf[9] <= 0x37) || l2capinbuf[9] == 0x3e || l2capinbuf[9] == 0x3f) { // These reports include the buttons if ((l2capinbuf[9] >= 0x20 && l2capinbuf[9] <= 0x22) || (l2capinbuf[9] >= 0x30 && l2capinbuf[9] <= 0x37) || l2capinbuf[9] == 0x3e || l2capinbuf[9] == 0x3f) { // These reports include the buttons
@ -481,18 +481,18 @@ void WII::ACLData(uint8_t* l2capinbuf) {
timer = micros(); timer = micros();
/* /*
// Uncomment these lines to tune the gyro scale variabels // Uncomment these lines to tune the gyro scale variabels
Serial.print("\r\ngyroYaw: "); Notify(PSTR("\r\ngyroYaw: "), 0x80);
Serial.print(gyroYaw); Notify(gyroYaw, 0x80);
Serial.print("\tgyroRoll: "); Notify(PSTR("\tgyroRoll: "), 0x80);
Serial.print(gyroRoll); Notify(gyroRoll, 0x80);
Serial.print("\tgyroPitch: "); Notify(PSTR("\tgyroPitch: "), 0x80);
Serial.print(gyroPitch); Notify(gyroPitch, 0x80);
*/ */
/* /*
Serial.print("\twiimoteRoll: "); Notify(PSTR("\twiimoteRoll: "), 0x80);
Serial.print(wiimoteRoll); Notify(wiimoteRoll, 0x80);
Serial.print("\twiimotePitch: "); Notify(PSTR("\twiimotePitch: "), 0x80);
Serial.print(wiimotePitch); Notify(wiimotePitch, 0x80);
*/ */
} else { } else {
if ((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values if ((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values
@ -567,7 +567,7 @@ void WII::ACLData(uint8_t* l2capinbuf) {
#ifdef DEBUG #ifdef DEBUG
default: default:
Notify(PSTR("\r\nUnknown Report type: "), 0x80); Notify(PSTR("\r\nUnknown Report type: "), 0x80);
Serial.print(l2capinbuf[9], HEX); PrintHex<uint8_t > (l2capinbuf[9], 0x80);
break; break;
#endif #endif
} }

View file

@ -278,7 +278,7 @@ uint8_t XBOXRECV::Poll() {
if (bufferSize > 0) { // The number of received bytes if (bufferSize > 0) { // The number of received bytes
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
Notify(PSTR("Bytes Received: "), 0x80); Notify(PSTR("Bytes Received: "), 0x80);
Serial.print(bufferSize); PrintHex<uint16_t > (bufferSize, 0x80);
Notify(PSTR("\r\n"), 0x80); Notify(PSTR("\r\n"), 0x80);
#endif #endif
readReport(i); readReport(i);
@ -298,7 +298,7 @@ void XBOXRECV::readReport(uint8_t controller) {
Xbox360Connected[controller] = readBuf[1]; Xbox360Connected[controller] = readBuf[1];
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("Controller "), 0x80); Notify(PSTR("Controller "), 0x80);
Serial.print(controller); Notify(controller, 0x80);
#endif #endif
if (Xbox360Connected[controller]) { if (Xbox360Connected[controller]) {
#ifdef DEBUG #ifdef DEBUG
@ -371,13 +371,13 @@ void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) { //Uncomment "#d
if (readBuf == NULL) if (readBuf == NULL)
return; return;
Notify(PSTR("Controller "), 0x80); Notify(PSTR("Controller "), 0x80);
Serial.print(controller); Notify(controller, 0x80);
Notify(PSTR(": "), 0x80); Notify(PSTR(": "), 0x80);
for (uint8_t i = 0; i < nBytes; i++) { for (uint8_t i = 0; i < nBytes; i++) {
PrintHex<uint8_t > (readBuf[i], 0x80); PrintHex<uint8_t > (readBuf[i], 0x80);
Serial.print(" "); Notify(PSTR(" "), 0x80);
} }
Serial.println(); Notify(PSTR("\r\n"), 0x80);
#endif #endif
} }
@ -386,7 +386,7 @@ uint8_t XBOXRECV::getButtonPress(uint8_t controller, Button b) {
return (uint8_t)(ButtonState[controller] >> 8); return (uint8_t)(ButtonState[controller] >> 8);
else if (b == R2) else if (b == R2)
return (uint8_t)ButtonState[controller]; return (uint8_t)ButtonState[controller];
return (ButtonState[controller] & ((uint32_t)pgm_read_word(&XBOXBUTTONS[(uint8_t)b]) << 16)); return (bool)(ButtonState[controller] & ((uint32_t)pgm_read_word(&XBOXBUTTONS[(uint8_t)b]) << 16));
} }
bool XBOXRECV::getButtonClick(uint8_t controller, Button b) { bool XBOXRECV::getButtonClick(uint8_t controller, Button b) {

View file

@ -260,9 +260,9 @@ void XBOXUSB::printReport() { //Uncomment "#define PRINTREPORT" to print the rep
return; return;
for (uint8_t i = 0; i < XBOX_REPORT_BUFFER_SIZE; i++) { for (uint8_t i = 0; i < XBOX_REPORT_BUFFER_SIZE; i++) {
PrintHex<uint8_t > (readBuf[i], 0x80); PrintHex<uint8_t > (readBuf[i], 0x80);
Serial.print(" "); Notify(PSTR(" "), 0x80);
} }
Serial.println(); Notify(PSTR("\r\n"), 0x80);
#endif #endif
} }

View file

@ -89,8 +89,8 @@ void loop() {
if(Xbox.getButtonClick(i,XBOX)) { if(Xbox.getButtonClick(i,XBOX)) {
Xbox.setLedMode(i,ROTATING); Xbox.setLedMode(i,ROTATING);
Serial.print(F("Xbox (Battery: ")); Serial.print(F("Xbox (Battery: "));
Serial.print(Xbox.getBatteryLevel(i)); Serial.print(Xbox.getBatteryLevel(i)); // The battery level in the range 0-3
Serial.println(F("%)")); Serial.println(F(")"));
} }
if(Xbox.getButtonClick(i,SYNC)) if(Xbox.getButtonClick(i,SYNC))
Serial.println(F("Sync")); Serial.println(F("Sync"));

View file

@ -48,6 +48,22 @@ void NotifyStr(char const * msg, int lvl) {
while (c = *msg++) Notifyc(c, lvl); while (c = *msg++) Notifyc(c, lvl);
} }
void Notify(uint8_t b, int lvl) {
if (UsbDEBUGlvl < lvl) return;
#if defined(ARDUINO) && ARDUINO >=100
Serial.print(b);
#else
Serial.print(b, DEC);
#endif
Serial.flush();
}
void Notify(double d, int lvl) {
if (UsbDEBUGlvl < lvl) return;
Serial.print(d);
Serial.flush();
}
void NotifyFailGetDevDescr(void) { void NotifyFailGetDevDescr(void) {
Notify(PSTR("\r\ngetDevDescr"), 0x80); Notify(PSTR("\r\ngetDevDescr"), 0x80);
} }

View file

@ -24,6 +24,8 @@ extern int UsbDEBUGlvl;
#include "printhex.h" #include "printhex.h"
void Notify(uint8_t b, int lvl);
void Notify(double d, int lvl);
void Notify(char const * msg, int lvl); void Notify(char const * msg, int lvl);
void NotifyStr(char const * msg, int lvl); void NotifyStr(char const * msg, int lvl);
#ifdef DEBUG #ifdef DEBUG