mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge branch 'master' of https://github.com/felis/USB_Host_Shield_2.0
This commit is contained in:
commit
2d3b73f9a7
3 changed files with 72 additions and 32 deletions
90
SPP.cpp
90
SPP.cpp
|
@ -729,51 +729,87 @@ uint8_t SPP::calcFcs(uint8_t *data) {
|
|||
void SPP::print(const String &str) {
|
||||
if (!connected)
|
||||
return;
|
||||
uint8_t length = str.length();
|
||||
if (length > (sizeof (l2capoutbuf) - 4))
|
||||
length = sizeof (l2capoutbuf) - 4;
|
||||
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
|
||||
l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control
|
||||
l2capoutbuf[2] = length << 1 | 1; // Length
|
||||
uint8_t i = 0;
|
||||
for (; i < length; i++)
|
||||
l2capoutbuf[i + 3] = str[i];
|
||||
l2capoutbuf[i + 3] = calcFcs(l2capoutbuf);
|
||||
|
||||
do {
|
||||
if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing puffer
|
||||
length = sizeof (l2capoutbuf) - 4;
|
||||
else
|
||||
length = stringLength;
|
||||
|
||||
RFCOMM_Command(l2capoutbuf, length + 4);
|
||||
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) {
|
||||
if (!connected)
|
||||
return;
|
||||
uint8_t length = strlen(str);
|
||||
if (length > (sizeof (l2capoutbuf) - 4))
|
||||
length = sizeof (l2capoutbuf) - 4;
|
||||
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
|
||||
l2capoutbuf[2] = length << 1 | 1; // Length
|
||||
uint8_t i = 0;
|
||||
for (; i < length; i++)
|
||||
l2capoutbuf[i + 3] = str[i];
|
||||
l2capoutbuf[i + 3] = calcFcs(l2capoutbuf);
|
||||
|
||||
RFCOMM_Command(l2capoutbuf, length + 4);
|
||||
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, uint8_t length) {
|
||||
void SPP::print(uint8_t* array, int16_t stringLength) {
|
||||
if (!connected)
|
||||
return;
|
||||
if (length > (sizeof (l2capoutbuf) - 4))
|
||||
length = sizeof (l2capoutbuf) - 4;
|
||||
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
|
||||
l2capoutbuf[2] = length << 1 | 1; // Length
|
||||
uint8_t i = 0;
|
||||
for (; i < length; i++)
|
||||
l2capoutbuf[i + 3] = array[i];
|
||||
l2capoutbuf[i + 3] = calcFcs(l2capoutbuf);
|
||||
|
||||
RFCOMM_Command(l2capoutbuf, length + 4);
|
||||
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] = array[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::println(const String &str) {
|
||||
|
|
2
SPP.h
2
SPP.h
|
@ -158,7 +158,7 @@ public:
|
|||
* @param array Array to send.
|
||||
* @param length Number of bytes to send.
|
||||
*/
|
||||
void print(uint8_t* array, uint8_t length);
|
||||
void print(uint8_t* array, int16_t length);
|
||||
/**
|
||||
* Same as print(uint8_t* array, uint8_t length), but will include newline and carriage return.
|
||||
* @param array Array to send.
|
||||
|
|
|
@ -21,7 +21,7 @@ PS3BT PS3(&Btd); // This will just create the instance
|
|||
//PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
|
||||
|
||||
boolean firstMessage = true;
|
||||
String output; // We will store the data in these string so we doesn't overflow the dongle
|
||||
String output = ""; // We will store the data in this string so we doesn't overflow the dongle
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200); // This wil lprint the debugging from the libraries
|
||||
|
@ -30,6 +30,7 @@ void setup() {
|
|||
while(1); //halt
|
||||
}
|
||||
Serial.print(F("\r\nBluetooth Library Started"));
|
||||
output.reserve(200); // Reserve 200 bytes for the output string
|
||||
}
|
||||
void loop() {
|
||||
Usb.Task();
|
||||
|
@ -130,8 +131,10 @@ void loop() {
|
|||
if(PS3.getButtonClick(R3))
|
||||
output += " - R3";
|
||||
|
||||
if(PS3.getButtonClick(SELECT))
|
||||
output += " - Select";
|
||||
if(PS3.getButtonClick(SELECT)) {
|
||||
output += " - Select - ";
|
||||
output += PS3.getStatusString();
|
||||
}
|
||||
if(PS3.getButtonClick(START))
|
||||
output += " - Start";
|
||||
|
||||
|
@ -141,6 +144,7 @@ void loop() {
|
|||
if(SerialBT.connected)
|
||||
SerialBT.println(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue