diff options
author | tmk <hasu@tmk-kbd.com> | 2015-05-13 04:13:10 +0200 |
---|---|---|
committer | tmk <hasu@tmk-kbd.com> | 2015-05-13 04:13:10 +0200 |
commit | f6d56675f9f981c5464f0ca7a1fbb0162154e8c5 (patch) | |
tree | 57c9d4b3808a26116ae0ee7956fc00b84841aa2b /protocol/usb_hid/USB_Host_Shield_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino | |
parent | 4d116a04e94cf0d19317d5b44e4fa9f34a3e5594 (diff) | |
download | qmk_firmware-f6d56675f9f981c5464f0ca7a1fbb0162154e8c5.tar.gz qmk_firmware-f6d56675f9f981c5464f0ca7a1fbb0162154e8c5.tar.xz |
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
dc0e46e Rename LUFA to LUFA-git
3bfa7fa Remove LUFA-120730
215b764 Merge commit 'afa0f22a9299686fd88f58ce09c5b521ac917e8f' as 'protocol/lufa/LUFA'
afa0f22 Squashed 'protocol/lufa/LUFA/' content from commit def7fca
c0c42fa Remove submodule of LUFA
30f897d Merge commit '87ced33feb74e79c3281dda36eb6d6d153399b41' as 'protocol/usb_hid/USB_Host_Shield_2.0'
87ced33 Squashed 'protocol/usb_hid/USB_Host_Shield_2.0/' content from commit aab4a69
14f6d49 Remove submodule of USB_Host_Shield_2.0
git-subtree-dir: tmk_core
git-subtree-split: dc0e46eaa4367d4e218f8816e3c117895820f07c
Diffstat (limited to 'protocol/usb_hid/USB_Host_Shield_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino')
-rw-r--r-- | protocol/usb_hid/USB_Host_Shield_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/protocol/usb_hid/USB_Host_Shield_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino b/protocol/usb_hid/USB_Host_Shield_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino new file mode 100644 index 000000000..df521d8e1 --- /dev/null +++ b/protocol/usb_hid/USB_Host_Shield_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino @@ -0,0 +1,67 @@ +/* + Example sketch for the RFCOMM/SPP Bluetooth library - developed by Kristian Lauszus + For more information visit my blog: http://blog.tkjelectronics.dk/ or + send me an e-mail: kristianl@tkjelectronics.com + */ + +#include <SPP.h> +#include <usbhub.h> + +// Satisfy IDE, which only needs to see the include statment in the ino. +#ifdef dobogusinclude +#include <spi4teensy3.h> +#include <SPI.h> +#endif + +USB Usb; +//USBHub Hub1(&Usb); // Some dongles have a hub inside + +BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so + +const uint8_t length = 2; // Set the number of instances here +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! + +bool firstMessage[length] = { true }; // Set all to true + +void setup() { + for (uint8_t i = 0; i < length; i++) + SerialBT[i] = new SPP(&Btd); // This will set the name to the default: "Arduino" and the pin to "0000" for all connections + + Serial.begin(115200); +#if !defined(__MIPSEL__) + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection +#endif + if (Usb.Init() == -1) { + Serial.print(F("\r\nOSC did not start")); + while (1); // Halt + } + Serial.print(F("\r\nSPP Bluetooth Library Started")); +} + +void loop() { + Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well + + for (uint8_t i = 0; i < length; i++) { + if (SerialBT[i]->connected) { + if (firstMessage[i]) { + firstMessage[i] = false; + SerialBT[i]->println(F("Hello from Arduino")); // Send welcome message + } + if (SerialBT[i]->available()) + Serial.write(SerialBT[i]->read()); + } + else + firstMessage[i] = true; + } + + // Set the connection you want to send to using the first character + // For instance "0Hello World" would send "Hello World" to connection 0 + if (Serial.available()) { + delay(10); // Wait for the rest of the data to arrive + uint8_t id = Serial.read() - '0'; // Convert from ASCII + if (id < length && SerialBT[id]->connected) { // Make sure that the id is valid and make sure that a device is actually connected + while (Serial.available()) // Check if data is available + SerialBT[id]->write(Serial.read()); // Send the data + } + } +} |