diff --git a/BTD.cpp b/BTD.cpp index 9d0ea3ec..fdcaf249 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -373,7 +373,7 @@ void BTD::HCI_event_task() { if (hcibuf[2]) { // Check that there is more than zero responses #ifdef EXTRADEBUG Notify(PSTR("\r\nNumber of responses: "), 0x80); - Serial.print(hcibuf[2]); + Notify(hcibuf[2], 0x80); #endif 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 @@ -460,7 +460,7 @@ void BTD::HCI_event_task() { } else if (btdPin != NULL) { #ifdef DEBUG Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80); - Serial.print(btdPin); + NotifyStr(btdPin, 0x80); #endif hci_pin_code_request_reply(); } else { @@ -590,7 +590,7 @@ void BTD::HCI_task() { if (hci_cmd_complete) { #ifdef DEBUG Notify(PSTR("\r\nThe name is set to: "), 0x80); - Serial.print(btdName); + NotifyStr(btdName, 0x80); #endif hci_state = HCI_CHECK_WII_SERVICE; } @@ -681,7 +681,7 @@ void BTD::HCI_task() { for (uint8_t i = 0; i < 30; i++) { if (remote_name[i] == NULL) break; - Serial.write(remote_name[i]); + Notifyc(remote_name[i], 0x80); } #endif 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); PrintHex (rcode, 0x80); Notify(PSTR(" - Channel ID: "), 0x80); - Serial.print(channelHigh); + PrintHex (channelHigh, 0x80); Notify(PSTR(" "), 0x80); - Serial.print(channelLow); + PrintHex (channelLow, 0x80); #endif } } diff --git a/PS3BT.cpp b/PS3BT.cpp index d04433d3..ed2c98c9 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -258,7 +258,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { #ifdef DEBUG 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); - 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); } #endif @@ -271,17 +271,17 @@ void PS3BT::ACLData(uint8_t* ACLData) { if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { #ifdef DEBUG - Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); + Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); PrintHex (l2capinbuf[13], 0x80); - Serial.print(" "); + Notify(PSTR(" "), 0x80); PrintHex (l2capinbuf[12], 0x80); - Serial.print(" Data: "); + Notify(PSTR(" Data: "), 0x80); PrintHex (l2capinbuf[17], 0x80); - Serial.print(" "); + Notify(PSTR(" "), 0x80); PrintHex (l2capinbuf[16], 0x80); - Serial.print(" "); + Notify(PSTR(" "), 0x80); PrintHex (l2capinbuf[15], 0x80); - Serial.print(" "); + Notify(PSTR(" "), 0x80); PrintHex (l2capinbuf[14], 0x80); #endif } 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) { if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success 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; } 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; } } } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) { 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]; l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_REQUEST; } 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]; 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) { 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]; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE; } 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]; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE; } @@ -362,7 +362,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { } #endif } 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) { /* Read Report */ 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 for (uint8_t i = 10; i < 58; i++) { PrintHex (l2capinbuf[i], 0x80); - Serial.print(" "); + Notify(PSTR(" "), 0x80); } - Serial.println(); + Notify(PSTR("\r\n"), 0x80); #endif } } diff --git a/PS3USB.cpp b/PS3USB.cpp index 7d0430d5..a14c14c3 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -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 } +#ifdef DEBUG + Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80); + for (int8_t i = 5; i > 0; i--) { + PrintHex (my_bdaddr[i], 0x80); + Notify(PSTR(":"), 0x80); + } + PrintHex (my_bdaddr[0], 0x80); +#endif + bPollEnable = true; Notify(PSTR("\r\n"), 0x80); timer = millis(); @@ -290,9 +299,9 @@ void PS3USB::printReport() { //Uncomment "#define PRINTREPORT" to print the repo return; for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++) { PrintHex (readBuf[i], 0x80); - Serial.print(" "); + Notify(PSTR(" "), 0x80); } - Serial.println(); + Notify(PSTR("\r\n"), 0x80); #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) 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 (my_bdaddr[i], 0x80); - Serial.print(":"); - } - PrintHex (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 @@ -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) 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 (my_bdaddr[i], 0x80); - Serial.print(":"); - } - PrintHex (my_bdaddr[0], 0x80); -#endif - return; } diff --git a/SPP.cpp b/SPP.cpp index a2415011..80b5a8f6 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -139,20 +139,20 @@ void SPP::ACLData(uint8_t* l2capinbuf) { } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) { if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success 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; } 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; } } } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) { 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]; l2cap_event_flag |= L2CAP_FLAG_CONFIG_SDP_REQUEST; } 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]; 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) { 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]; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE; } 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]; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE; } @@ -207,27 +207,26 @@ void SPP::ACLData(uint8_t* l2capinbuf) { l2capResponse2(l2capinbuf[9], l2capinbuf[10]); // L2CAP continuation state firstMessage = true; } - } else { -#ifdef EXTRADEBUG - Notify(PSTR("\r\nUUID: "), 0x80); - uint16_t uuid; - if((l2capinbuf[16] << 8 | l2capinbuf[17]) == 0x0000) // Check if it's sending the UUID as a 128-bit UUID - uuid = (l2capinbuf[18] << 8 | l2capinbuf[19]); - else // Short UUID - uuid = (l2capinbuf[16] << 8 | l2capinbuf[17]); - PrintHex (uuid, 0x80); - - Notify(PSTR("\r\nLength: "), 0x80); - uint16_t length = l2capinbuf[11] << 8 | l2capinbuf[12]; - PrintHex (length, 0x80); - Notify(PSTR("\r\nData: "), 0x80); - for (uint8_t i = 0; i < length; i++) { - PrintHex (l2capinbuf[13+i], 0x80); - Notify(PSTR(" "), 0x80); - } -#endif + } else serviceNotSupported(l2capinbuf[9], l2capinbuf[10]); // The service is not supported +#ifdef EXTRADEBUG + Notify(PSTR("\r\nUUID: "), 0x80); + uint16_t uuid; + if((l2capinbuf[16] << 8 | l2capinbuf[17]) == 0x0000) // Check if it's sending the UUID as a 128-bit UUID + uuid = (l2capinbuf[18] << 8 | l2capinbuf[19]); + else // Short UUID + uuid = (l2capinbuf[16] << 8 | l2capinbuf[17]); + PrintHex (uuid, 0x80); + + Notify(PSTR("\r\nLength: "), 0x80); + uint16_t length = l2capinbuf[11] << 8 | l2capinbuf[12]; + PrintHex (length, 0x80); + Notify(PSTR("\r\nData: "), 0x80); + for (uint8_t i = 0; i < length; i++) { + PrintHex (l2capinbuf[13+i], 0x80); + Notify(PSTR(" "), 0x80); } +#endif } } else if (l2capinbuf[6] == rfcomm_dcid[0] && l2capinbuf[7] == rfcomm_dcid[1]) { // RFCOMM rfcommChannel = l2capinbuf[8] & 0xF8; @@ -241,20 +240,20 @@ void SPP::ACLData(uint8_t* l2capinbuf) { #ifdef EXTRADEBUG Notify(PSTR("\r\nRFCOMM Channel: "), 0x80); - Serial.print(rfcommChannel >> 3, HEX); + PrintHex (rfcommChannel >> 3, 0x80); Notify(PSTR(" Direction: "), 0x80); - Serial.print(rfcommDirection >> 2, HEX); + PrintHex (rfcommDirection >> 2, 0x80); Notify(PSTR(" CommandResponse: "), 0x80); - Serial.print(rfcommCommandResponse >> 1, HEX); + PrintHex (rfcommCommandResponse >> 1, 0x80); Notify(PSTR(" ChannelType: "), 0x80); - Serial.print(rfcommChannelType, HEX); + PrintHex (rfcommChannelType, 0x80); Notify(PSTR(" PF_BIT: "), 0x80); - Serial.print(rfcommPfBit, HEX); + PrintHex (rfcommPfBit, 0x80); #endif if (rfcommChannelType == RFCOMM_DISC) { #ifdef DEBUG Notify(PSTR("\r\nReceived Disconnect RFCOMM Command on channel: "), 0x80); - Serial.print(rfcommChannel >> 3, HEX); + PrintHex (rfcommChannel >> 3, 0x80); #endif connected = false; sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command @@ -271,15 +270,15 @@ void SPP::ACLData(uint8_t* l2capinbuf) { } #ifdef EXTRADEBUG Notify(PSTR("\r\nRFCOMM Data Available: "), 0x80); - Serial.print(rfcommAvailable); + Notify(rfcommAvailable, 0x80); if (offset) { Notify(PSTR(" - Credit: 0x"), 0x80); - Serial.print(l2capinbuf[11], HEX); + PrintHex (l2capinbuf[11], 0x80); } #endif #ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send to the Arduino via Bluetooth for (uint8_t i = 0; i < length; i++) - Serial.write(l2capinbuf[i + 11 + offset]); + Notifyc(l2capinbuf[i + 11 + offset], 0x80); #endif } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command #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) { l2capoutbuf[0] = channel | direction | CR | extendAddress; // RFCOMM Address 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; for (; i < length; 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 Notify(PSTR(" - RFCOMM Data: "), 0x80); for (i = 0; i < length + 4; i++) { - Serial.print(l2capoutbuf[i], HEX); + PrintHex (l2capoutbuf[i], 0x80); Notify(PSTR(" "), 0x80); } #endif @@ -705,7 +704,7 @@ void SPP::sendRfcommCredit(uint8_t channel, uint8_t direction, uint8_t CR, uint8 #ifdef EXTRADEBUG Notify(PSTR(" - RFCOMM Credit Data: "), 0x80); for (uint8_t i = 0; i < 5; i++) { - Serial.print(l2capoutbuf[i], HEX); + PrintHex (l2capoutbuf[i], 0x80); Notify(PSTR(" "), 0x80); } #endif @@ -727,64 +726,20 @@ uint8_t SPP::calcFcs(uint8_t *data) { /* Serial commands */ void SPP::print(const String &str) { - if (!connected) - return; - 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 + uint8_t length = str.length(); // Get the length of the string + uint8_t buf[length]; - 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; + for(uint8_t i = 0; i < length; i++) + buf[i] = str[i]; - 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 + print(buf,length); } void SPP::print(const char* str) { - if (!connected) - 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 + print((uint8_t*) str, strlen(str)); } -void SPP::print(uint8_t* array, int16_t stringLength) { +void SPP::print(uint8_t* array, uint8_t stringLength) { if (!connected) return; 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[1] = RFCOMM_UIH; // RFCOMM Control - do { - if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing puffer + 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 buffer length = sizeof (l2capoutbuf) - 4; else length = stringLength; @@ -809,7 +764,7 @@ void SPP::print(uint8_t* array, int16_t stringLength) { stringLength -= length; 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) { @@ -974,7 +929,7 @@ uint8_t SPP::read() { sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send more credit #ifdef EXTRADEBUG Notify(PSTR("\r\nSent "), 0x80); - Serial.print(sizeof (rfcommDataBuffer)); + Notify((uint8_t)sizeof (rfcommDataBuffer), 0x80); Notify(PSTR(" more credit"), 0x80); #endif } diff --git a/SPP.h b/SPP.h index 9dbbad8b..92cb51b0 100644 --- a/SPP.h +++ b/SPP.h @@ -68,7 +68,7 @@ //#define RFCOMM_DM 0x0F #define RFCOMM_DISC 0x43 -#define extendAddress 0x01 // Allways 1 +#define extendAddress 0x01 // Always 1 // Multiplexer message types #define BT_RFCOMM_PN_CMD 0x83 @@ -158,7 +158,7 @@ public: * @param array Array 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. * @param array Array to send. @@ -341,10 +341,10 @@ private: 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_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 rfcommbuf[10]; // Buffer for RFCOMM Commands @@ -358,7 +358,7 @@ private: /* RFCOMM Variables */ 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 rfcommCommandResponse; uint8_t rfcommChannelType; diff --git a/Wii.cpp b/Wii.cpp index 01571d8e..15bc58ed 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -161,13 +161,13 @@ void WII::ACLData(uint8_t* l2capinbuf) { } else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_RESPONSE) { 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 - //Serial.print("\r\nHID Control Connection Complete"); + //Notify(PSTR("\r\nHID Control Connection Complete"), 0x80); identifier = l2capinbuf[9]; control_scid[0] = l2capinbuf[12]; control_scid[1] = l2capinbuf[13]; l2cap_event_flag |= L2CAP_FLAG_CONTROL_CONNECTED; } 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]; interrupt_scid[0] = l2capinbuf[12]; interrupt_scid[1] = l2capinbuf[13]; @@ -201,21 +201,21 @@ void WII::ACLData(uint8_t* l2capinbuf) { } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) { if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success 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]; l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_SUCCESS; } 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]; l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS; } } } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) { 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); } 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); } } 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) { 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]; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE; } 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]; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE; } @@ -253,7 +253,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { } #endif } 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 (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 @@ -481,19 +481,19 @@ void WII::ACLData(uint8_t* l2capinbuf) { timer = micros(); /* // Uncomment these lines to tune the gyro scale variabels - Serial.print("\r\ngyroYaw: "); - Serial.print(gyroYaw); - Serial.print("\tgyroRoll: "); - Serial.print(gyroRoll); - Serial.print("\tgyroPitch: "); - Serial.print(gyroPitch); - */ + Notify(PSTR("\r\ngyroYaw: "), 0x80); + Notify(gyroYaw, 0x80); + Notify(PSTR("\tgyroRoll: "), 0x80); + Notify(gyroRoll, 0x80); + Notify(PSTR("\tgyroPitch: "), 0x80); + Notify(gyroPitch, 0x80); + */ /* - Serial.print("\twiimoteRoll: "); - Serial.print(wiimoteRoll); - Serial.print("\twiimotePitch: "); - Serial.print(wiimotePitch); - */ + Notify(PSTR("\twiimoteRoll: "), 0x80); + Notify(wiimoteRoll, 0x80); + Notify(PSTR("\twiimotePitch: "), 0x80); + Notify(wiimotePitch, 0x80); + */ } else { if ((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values #ifdef DEBUG @@ -567,7 +567,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { #ifdef DEBUG default: Notify(PSTR("\r\nUnknown Report type: "), 0x80); - Serial.print(l2capinbuf[9], HEX); + PrintHex (l2capinbuf[9], 0x80); break; #endif } diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index 572cde76..9231ef88 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -278,7 +278,7 @@ uint8_t XBOXRECV::Poll() { if (bufferSize > 0) { // The number of received bytes #ifdef EXTRADEBUG Notify(PSTR("Bytes Received: "), 0x80); - Serial.print(bufferSize); + PrintHex (bufferSize, 0x80); Notify(PSTR("\r\n"), 0x80); #endif readReport(i); @@ -298,7 +298,7 @@ void XBOXRECV::readReport(uint8_t controller) { Xbox360Connected[controller] = readBuf[1]; #ifdef DEBUG Notify(PSTR("Controller "), 0x80); - Serial.print(controller); + Notify(controller, 0x80); #endif if (Xbox360Connected[controller]) { #ifdef DEBUG @@ -371,13 +371,13 @@ void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) { //Uncomment "#d if (readBuf == NULL) return; Notify(PSTR("Controller "), 0x80); - Serial.print(controller); + Notify(controller, 0x80); Notify(PSTR(": "), 0x80); for (uint8_t i = 0; i < nBytes; i++) { PrintHex (readBuf[i], 0x80); - Serial.print(" "); + Notify(PSTR(" "), 0x80); } - Serial.println(); + Notify(PSTR("\r\n"), 0x80); #endif } @@ -386,7 +386,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)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) { diff --git a/XBOXUSB.cpp b/XBOXUSB.cpp index 33f9bc5b..5c14844a 100644 --- a/XBOXUSB.cpp +++ b/XBOXUSB.cpp @@ -260,9 +260,9 @@ void XBOXUSB::printReport() { //Uncomment "#define PRINTREPORT" to print the rep return; for (uint8_t i = 0; i < XBOX_REPORT_BUFFER_SIZE; i++) { PrintHex (readBuf[i], 0x80); - Serial.print(" "); + Notify(PSTR(" "), 0x80); } - Serial.println(); + Notify(PSTR("\r\n"), 0x80); #endif } diff --git a/examples/Xbox/XBOXRECV/XBOXRECV.ino b/examples/Xbox/XBOXRECV/XBOXRECV.ino index b6ae3b23..e49dee37 100644 --- a/examples/Xbox/XBOXRECV/XBOXRECV.ino +++ b/examples/Xbox/XBOXRECV/XBOXRECV.ino @@ -89,8 +89,8 @@ void loop() { if(Xbox.getButtonClick(i,XBOX)) { Xbox.setLedMode(i,ROTATING); Serial.print(F("Xbox (Battery: ")); - Serial.print(Xbox.getBatteryLevel(i)); - Serial.println(F("%)")); + Serial.print(Xbox.getBatteryLevel(i)); // The battery level in the range 0-3 + Serial.println(F(")")); } if(Xbox.getButtonClick(i,SYNC)) Serial.println(F("Sync")); diff --git a/message.cpp b/message.cpp index 9a5395ea..ecbc0d40 100644 --- a/message.cpp +++ b/message.cpp @@ -48,6 +48,22 @@ void NotifyStr(char const * msg, int 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) { Notify(PSTR("\r\ngetDevDescr"), 0x80); } diff --git a/message.h b/message.h index 02a503ac..8d62513e 100644 --- a/message.h +++ b/message.h @@ -24,6 +24,8 @@ extern int UsbDEBUGlvl; #include "printhex.h" +void Notify(uint8_t b, int lvl); +void Notify(double d, int lvl); void Notify(char const * msg, int lvl); void NotifyStr(char const * msg, int lvl); #ifdef DEBUG