6
6
7
7
#include < SPP.h>
8
8
#include < usbhub.h>
9
- // Satisfy IDE, which only needs to see the include statment in the ino.
9
+ // Satisfy IDE, which only needs to see the include statement in the ino.
10
10
#ifdef dobogusinclude
11
11
#include < spi4teensy3.h>
12
12
#endif
@@ -15,10 +15,11 @@ USB Usb;
15
15
// USBHub Hub1(&Usb); // Some dongles have a hub inside
16
16
17
17
BTD Btd (&Usb); // You have to create the Bluetooth Dongle instance like so
18
- SPP *SerialBT[2 ]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
19
- const uint8_t length = sizeof (SerialBT) / sizeof (SerialBT[0 ]); // Get the lenght of the array
18
+
19
+ const uint8_t length = 2 ; // Set the number of instances here
20
+ SPP *SerialBT[length]; // We will use this pointer to store the instances, you can easily make it larger if you like, but it will use a lot of RAM!
21
+
20
22
boolean firstMessage[length] = { true }; // Set all to true
21
- uint8_t buffer[50 ];
22
23
23
24
void setup () {
24
25
for (uint8_t i = 0 ; i < length; i++)
@@ -28,10 +29,11 @@ void setup() {
28
29
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
29
30
if (Usb.Init () == -1 ) {
30
31
Serial.print (F (" \r\n OSC did not start" ));
31
- while (1 ); // halt
32
+ while (1 ); // Halt
32
33
}
33
34
Serial.print (F (" \r\n SPP Bluetooth Library Started" ));
34
35
}
36
+
35
37
void loop () {
36
38
Usb.Task (); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well
37
39
@@ -47,22 +49,15 @@ void loop() {
47
49
else
48
50
firstMessage[i] = true ;
49
51
}
52
+
53
+ // Set the connection you want to send to using the first character
54
+ // For instance "0Hello World" would send "Hello World" to connection 0
50
55
if (Serial.available ()) {
51
56
delay (10 ); // Wait for the rest of the data to arrive
52
- uint8_t i = 0 ;
53
- while (Serial.available () && i < sizeof (buffer)) // Read the data
54
- buffer[i++] = Serial.read ();
55
- /*
56
- Set the connection you want to send to using the first character
57
- For instace "0Hello World" would send "Hello World" to connection 0
58
- */
59
- uint8_t id = buffer[0 ] - ' 0' ; // Convert from ASCII
60
- if (id < length && i > 1 ) { // And then compare to length and make sure there is any text
61
- if (SerialBT[id]->connected ) { // Check if a device is actually connected
62
- for (uint8_t i2 = 0 ; i2 < i - 1 ; i2++) // Don't include the first character
63
- buffer[i2] = buffer[i2 + 1 ];
64
- SerialBT[id]->write (buffer, i - 1 ); // Send the data
65
- }
57
+ uint8_t id = Serial.read () - ' 0' ; // Convert from ASCII
58
+ if (id < length && SerialBT[id]->connected ) { // Make sure that the id is valid and make sure that a device is actually connected
59
+ while (Serial.available ()) // Check if data is available
60
+ SerialBT[id]->write (Serial.read ()); // Send the data
66
61
}
67
62
}
68
63
}
0 commit comments