summaryrefslogtreecommitdiffstats
path: root/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-08-18 18:20:25 +1000
committerGitHub <noreply@github.com>2021-08-18 18:20:25 +1000
commitb16091659cc9a724a8800f77e631643b4ab089ad (patch)
treee44933472c6d100bd4fc5d8a693d9d21e3c32f6f /lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth
parentcf5e40c25139ff64ff246f1c6280e983ef75551c (diff)
Move USB Host Shield and Arduino core to `lib/` (#13973)
Diffstat (limited to 'lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth')
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/BTHID.ino55
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/KeyboardParser.h105
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/MouseParser.h46
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3BT/PS3BT.ino188
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3Multi/PS3Multi.ino149
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3SPP/PS3SPP.ino162
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS4BT/PS4BT.ino146
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/SPP/SPP.ino52
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino67
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/Wii/Wii.ino118
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino51
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino133
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiMulti/WiiMulti.ino132
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiUProController/WiiUProController.ino104
14 files changed, 1508 insertions, 0 deletions
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/BTHID.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/BTHID.ino
new file mode 100644
index 0000000000..919a56468b
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/BTHID.ino
@@ -0,0 +1,55 @@
+/*
+ Example sketch for the HID 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 <BTHID.h>
+#include <usbhub.h>
+#include "KeyboardParser.h"
+#include "MouseParser.h"
+
+// Satisfy the IDE, which needs to see the include statment in the ino too.
+#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
+
+/* You can create the instance of the class in two ways */
+// This will start an inquiry and then pair with your device - you only have to do this once
+// If you are using a Bluetooth keyboard, then you should type in the password on the keypad and then press enter
+BTHID bthid(&Btd, PAIR, "0000");
+
+// After that you can simply create the instance like so and then press any button on the device
+//BTHID hid(&Btd);
+
+KbdRptParser keyboardPrs;
+MouseRptParser mousePrs;
+
+void setup() {
+ 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
+ }
+
+ bthid.SetReportParser(KEYBOARD_PARSER_ID, (HIDReportParser*)&keyboardPrs);
+ bthid.SetReportParser(MOUSE_PARSER_ID, (HIDReportParser*)&mousePrs);
+
+ // If "Boot Protocol Mode" does not work, then try "Report Protocol Mode"
+ // If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report
+ bthid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode
+ //bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode
+
+ Serial.print(F("\r\nHID Bluetooth Library Started"));
+}
+void loop() {
+ Usb.Task();
+}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/KeyboardParser.h b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/KeyboardParser.h
new file mode 100644
index 0000000000..c5394331da
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/KeyboardParser.h
@@ -0,0 +1,105 @@
+#ifndef __kbdrptparser_h_
+#define __kbdrptparser_h_
+
+class KbdRptParser : public KeyboardReportParser {
+ protected:
+ virtual uint8_t HandleLockingKeys(HID *hid, uint8_t key);
+ virtual void OnControlKeysChanged(uint8_t before, uint8_t after);
+ virtual void OnKeyDown(uint8_t mod, uint8_t key);
+ virtual void OnKeyUp(uint8_t mod, uint8_t key);
+ virtual void OnKeyPressed(uint8_t key);
+
+ private:
+ void PrintKey(uint8_t mod, uint8_t key);
+};
+
+uint8_t KbdRptParser::HandleLockingKeys(HID *hid, uint8_t key) {
+ uint8_t old_keys = kbdLockingKeys.bLeds;
+
+ switch (key) {
+ case UHS_HID_BOOT_KEY_NUM_LOCK:
+ Serial.println(F("Num lock"));
+ kbdLockingKeys.kbdLeds.bmNumLock = ~kbdLockingKeys.kbdLeds.bmNumLock;
+ break;
+ case UHS_HID_BOOT_KEY_CAPS_LOCK:
+ Serial.println(F("Caps lock"));
+ kbdLockingKeys.kbdLeds.bmCapsLock = ~kbdLockingKeys.kbdLeds.bmCapsLock;
+ break;
+ case UHS_HID_BOOT_KEY_SCROLL_LOCK:
+ Serial.println(F("Scroll lock"));
+ kbdLockingKeys.kbdLeds.bmScrollLock = ~kbdLockingKeys.kbdLeds.bmScrollLock;
+ break;
+ }
+
+ if (old_keys != kbdLockingKeys.bLeds && hid) {
+ BTHID *pBTHID = reinterpret_cast<BTHID *> (hid); // A cast the other way around is done in BTHID.cpp
+ pBTHID->setLeds(kbdLockingKeys.bLeds); // Update the LEDs on the keyboard
+ }
+
+ return 0;
+};
+
+void KbdRptParser::PrintKey(uint8_t m, uint8_t key) {
+ MODIFIERKEYS mod;
+ *((uint8_t*)&mod) = m;
+ Serial.print((mod.bmLeftCtrl == 1) ? F("C") : F(" "));
+ Serial.print((mod.bmLeftShift == 1) ? F("S") : F(" "));
+ Serial.print((mod.bmLeftAlt == 1) ? F("A") : F(" "));
+ Serial.print((mod.bmLeftGUI == 1) ? F("G") : F(" "));
+
+ Serial.print(F(" >"));
+ PrintHex<uint8_t>(key, 0x80);
+ Serial.print(F("< "));
+
+ Serial.print((mod.bmRightCtrl == 1) ? F("C") : F(" "));
+ Serial.print((mod.bmRightShift == 1) ? F("S") : F(" "));
+ Serial.print((mod.bmRightAlt == 1) ? F("A") : F(" "));
+ Serial.println((mod.bmRightGUI == 1) ? F("G") : F(" "));
+};
+
+void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) {
+ Serial.print(F("DN "));
+ PrintKey(mod, key);
+ uint8_t c = OemToAscii(mod, key);
+
+ if (c)
+ OnKeyPressed(c);
+};
+
+void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {
+ MODIFIERKEYS beforeMod;
+ *((uint8_t*)&beforeMod) = before;
+
+ MODIFIERKEYS afterMod;
+ *((uint8_t*)&afterMod) = after;
+
+ if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl)
+ Serial.println(F("LeftCtrl changed"));
+ if (beforeMod.bmLeftShift != afterMod.bmLeftShift)
+ Serial.println(F("LeftShift changed"));
+ if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt)
+ Serial.println(F("LeftAlt changed"));
+ if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI)
+ Serial.println(F("LeftGUI changed"));
+
+ if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl)
+ Serial.println(F("RightCtrl changed"));
+ if (beforeMod.bmRightShift != afterMod.bmRightShift)
+ Serial.println(F("RightShift changed"));
+ if (beforeMod.bmRightAlt != afterMod.bmRightAlt)
+ Serial.println(F("RightAlt changed"));
+ if (beforeMod.bmRightGUI != afterMod.bmRightGUI)
+ Serial.println(F("RightGUI changed"));
+};
+
+void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key) {
+ Serial.print(F("UP "));
+ PrintKey(mod, key);
+};
+
+void KbdRptParser::OnKeyPressed(uint8_t key) {
+ Serial.print(F("ASCII: "));
+ Serial.println((char)key);
+};
+
+#endif
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/MouseParser.h b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/MouseParser.h
new file mode 100644
index 0000000000..a9245ded99
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/MouseParser.h
@@ -0,0 +1,46 @@
+#ifndef __mouserptparser_h__
+#define __mouserptparser_h__
+
+class MouseRptParser : public MouseReportParser {
+ protected:
+ virtual void OnMouseMove(MOUSEINFO *mi);
+ virtual void OnLeftButtonUp(MOUSEINFO *mi);
+ virtual void OnLeftButtonDown(MOUSEINFO *mi);
+ virtual void OnRightButtonUp(MOUSEINFO *mi);
+ virtual void OnRightButtonDown(MOUSEINFO *mi);
+ virtual void OnMiddleButtonUp(MOUSEINFO *mi);
+ virtual void OnMiddleButtonDown(MOUSEINFO *mi);
+};
+
+void MouseRptParser::OnMouseMove(MOUSEINFO *mi) {
+ Serial.print(F("dx="));
+ Serial.print(mi->dX, DEC);
+ Serial.print(F(" dy="));
+ Serial.println(mi->dY, DEC);
+};
+
+void MouseRptParser::OnLeftButtonUp(MOUSEINFO *mi) {
+ Serial.println(F("L Butt Up"));
+};
+
+void MouseRptParser::OnLeftButtonDown(MOUSEINFO *mi) {
+ Serial.println(F("L Butt Dn"));
+};
+
+void MouseRptParser::OnRightButtonUp(MOUSEINFO *mi) {
+ Serial.println(F("R Butt Up"));
+};
+
+void MouseRptParser::OnRightButtonDown(MOUSEINFO *mi) {
+ Serial.println(F("R Butt Dn"));
+};
+
+void MouseRptParser::OnMiddleButtonUp(MOUSEINFO *mi) {
+ Serial.println(F("M Butt Up"));
+};
+
+void MouseRptParser::OnMiddleButtonDown(MOUSEINFO *mi) {
+ Serial.println(F("M Butt Dn"));
+};
+
+#endif
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3BT/PS3BT.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3BT/PS3BT.ino
new file mode 100644
index 0000000000..b896734405
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3BT/PS3BT.ino
@@ -0,0 +1,188 @@
+/*
+ Example sketch for the PS3 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 <PS3BT.h>
+#include <usbhub.h>
+
+// Satisfy the IDE, which needs to see the include statment in the ino too.
+#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
+/* You can create the instance of the class in two ways */
+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
+
+bool printTemperature;
+bool printAngle;
+
+void setup() {
+ 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\nPS3 Bluetooth Library Started"));
+}
+void loop() {
+ Usb.Task();
+
+ if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
+ if (PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) {
+ Serial.print(F("\r\nLeftHatX: "));
+ Serial.print(PS3.getAnalogHat(LeftHatX));
+ Serial.print(F("\tLeftHatY: "));
+ Serial.print(PS3.getAnalogHat(LeftHatY));
+ if (PS3.PS3Connected) { // The Navigation controller only have one joystick
+ Serial.print(F("\tRightHatX: "));
+ Serial.print(PS3.getAnalogHat(RightHatX));
+ Serial.print(F("\tRightHatY: "));
+ Serial.print(PS3.getAnalogHat(RightHatY));
+ }
+ }
+
+ // Analog button values can be read from almost all buttons
+ if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
+ Serial.print(F("\r\nL2: "));
+ Serial.print(PS3.getAnalogButton(L2));
+ if (PS3.PS3Connected) {
+ Serial.print(F("\tR2: "));
+ Serial.print(PS3.getAnalogButton(R2));
+ }
+ }
+ if (PS3.getButtonClick(PS)) {
+ Serial.print(F("\r\nPS"));
+ PS3.disconnect();
+ }
+ else {
+ if (PS3.getButtonClick(TRIANGLE))
+ Serial.print(F("\r\nTraingle"));
+ if (PS3.getButtonClick(CIRCLE))
+ Serial.print(F("\r\nCircle"));
+ if (PS3.getButtonClick(CROSS))
+ Serial.print(F("\r\nCross"));
+ if (PS3.getButtonClick(SQUARE))
+ Serial.print(F("\r\nSquare"));
+
+ if (PS3.getButtonClick(UP)) {
+ Serial.print(F("\r\nUp"));
+ if (PS3.PS3Connected) {
+ PS3.setLedOff();
+ PS3.setLedOn(LED4);
+ }
+ }
+ if (PS3.getButtonClick(RIGHT)) {
+ Serial.print(F("\r\nRight"));
+ if (PS3.PS3Connected) {
+ PS3.setLedOff();
+ PS3.setLedOn(LED1);
+ }
+ }
+ if (PS3.getButtonClick(DOWN)) {
+ Serial.print(F("\r\nDown"));
+ if (PS3.PS3Connected) {
+ PS3.setLedOff();
+ PS3.setLedOn(LED2);
+ }
+ }
+ if (PS3.getButtonClick(LEFT)) {
+ Serial.print(F("\r\nLeft"));
+ if (PS3.PS3Connected) {
+ PS3.setLedOff();
+ PS3.setLedOn(LED3);
+ }
+ }
+
+ if (PS3.getButtonClick(L1))
+ Serial.print(F("\r\nL1"));
+ if (PS3.getButtonClick(L3))
+ Serial.print(F("\r\nL3"));
+ if (PS3.getButtonClick(R1))
+ Serial.print(F("\r\nR1"));
+ if (PS3.getButtonClick(R3))
+ Serial.print(F("\r\nR3"));
+
+ if (PS3.getButtonClick(SELECT)) {
+ Serial.print(F("\r\nSelect - "));
+ PS3.printStatusString();
+ }
+ if (PS3.getButtonClick(START)) {
+ Serial.print(F("\r\nStart"));
+ printAngle = !printAngle;
+ }
+ }
+#if 0 // Set this to 1 in order to see the angle of the controller
+ if (printAngle) {
+ Serial.print(F("\r\nPitch: "));
+ Serial.print(PS3.getAngle(Pitch));
+ Serial.print(F("\tRoll: "));
+ Serial.print(PS3.getAngle(Roll));
+ }
+#endif
+ }
+#if 0 // Set this to 1 in order to enable support for the Playstation Move controller
+ else if (PS3.PS3MoveConnected) {
+ if (PS3.getAnalogButton(T)) {
+ Serial.print(F("\r\nT: "));
+ Serial.print(PS3.getAnalogButton(T));
+ }
+ if (PS3.getButtonClick(PS)) {
+ Serial.print(F("\r\nPS"));
+ PS3.disconnect();
+ }
+ else {
+ if (PS3.getButtonClick(SELECT)) {
+ Serial.print(F("\r\nSelect"));
+ printTemperature = !printTemperature;
+ }
+ if (PS3.getButtonClick(START)) {
+ Serial.print(F("\r\nStart"));
+ printAngle = !printAngle;
+ }
+ if (PS3.getButtonClick(TRIANGLE)) {
+ Serial.print(F("\r\nTriangle"));
+ PS3.moveSetBulb(Red);
+ }
+ if (PS3.getButtonClick(CIRCLE)) {
+ Serial.print(F("\r\nCircle"));
+ PS3.moveSetBulb(Green);
+ }
+ if (PS3.getButtonClick(SQUARE)) {
+ Serial.print(F("\r\nSquare"));
+ PS3.moveSetBulb(Blue);
+ }
+ if (PS3.getButtonClick(CROSS)) {
+ Serial.print(F("\r\nCross"));
+ PS3.moveSetBulb(Yellow);
+ }
+ if (PS3.getButtonClick(MOVE)) {
+ PS3.moveSetBulb(Off);
+ Serial.print(F("\r\nMove"));
+ Serial.print(F(" - "));
+ PS3.printStatusString();
+ }
+ }
+ if (printAngle) {
+ Serial.print(F("\r\nPitch: "));
+ Serial.print(PS3.getAngle(Pitch));
+ Serial.print(F("\tRoll: "));
+ Serial.print(PS3.getAngle(Roll));
+ }
+ else if (printTemperature) {
+ Serial.print(F("\r\nTemperature: "));
+ Serial.print(PS3.getTemperature());
+ }
+ }
+#endif
+}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3Multi/PS3Multi.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3Multi/PS3Multi.ino
new file mode 100644
index 0000000000..5ebfd7819c
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3Multi/PS3Multi.ino
@@ -0,0 +1,149 @@
+/*
+ Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus
+ This example show how one can use multiple controllers with the library
+ For more information visit my blog: http://blog.tkjelectronics.dk/ or
+ send me an e-mail: kristianl@tkjelectronics.com
+ */
+
+#include <PS3BT.h>
+#include <usbhub.h>
+
+// Satisfy the IDE, which needs to see the include statment in the ino too.
+#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
+PS3BT *PS3[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!
+const uint8_t length = sizeof(PS3) / sizeof(PS3[0]); // Get the lenght of the array
+bool printAngle[length];
+bool oldControllerState[length];
+
+void setup() {
+ for (uint8_t i = 0; i < length; i++) {
+ PS3[i] = new PS3BT(&Btd); // Create the instances
+ PS3[i]->attachOnInit(onInit); // onInit() is called upon a new connection - you can call the function whatever you like
+ }
+
+ 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\nPS3 Bluetooth Library Started"));
+}
+void loop() {
+ Usb.Task();
+
+ for (uint8_t i = 0; i < length; i++) {
+ if (PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) {
+ if (PS3[i]->getAnalogHat(LeftHatX) > 137 || PS3[i]->getAnalogHat(LeftHatX) < 117 || PS3[i]->getAnalogHat(LeftHatY) > 137 || PS3[i]->getAnalogHat(LeftHatY) < 117 || PS3[i]->getAnalogHat(RightHatX) > 137 || PS3[i]->getAnalogHat(RightHatX) < 117 || PS3[i]->getAnalogHat(RightHatY) > 137 || PS3[i]->getAnalogHat(RightHatY) < 117) {
+ Serial.print(F("\r\nLeftHatX: "));
+ Serial.print(PS3[i]->getAnalogHat(LeftHatX));
+ Serial.print(F("\tLeftHatY: "));
+ Serial.print(PS3[i]->getAnalogHat(LeftHatY));
+ if (PS3[i]->PS3Connected) { // The Navigation controller only have one joystick
+ Serial.print(F("\tRightHatX: "));
+ Serial.print(PS3[i]->getAnalogHat(RightHatX));
+ Serial.print(F("\tRightHatY: "));
+ Serial.print(PS3[i]->getAnalogHat(RightHatY));
+ }
+ }
+ //Analog button values can be read from almost all buttons
+ if (PS3[i]->getAnalogButton(L2) || PS3[i]->getAnalogButton(R2)) {
+ Serial.print(F("\r\nL2: "));
+ Serial.print(PS3[i]->getAnalogButton(L2));
+ if (PS3[i]->PS3Connected) {
+ Serial.print(F("\tR2: "));
+ Serial.print(PS3[i]->getAnalogButton(R2));
+ }
+ }
+ if (PS3[i]->getButtonClick(PS)) {
+ Serial.print(F("\r\nPS"));
+ PS3[i]->disconnect();
+ oldControllerState[i] = false; // Reset value
+ }
+ else {
+ if (PS3[i]->getButtonClick(TRIANGLE))
+ Serial.print(F("\r\nTraingle"));
+ if (PS3[i]->getButtonClick(CIRCLE))
+ Serial.print(F("\r\nCircle"));
+ if (PS3[i]->getButtonClick(CROSS))
+ Serial.print(F("\r\nCross"));
+ if (PS3[i]->getButtonClick(SQUARE))
+ Serial.print(F("\r\nSquare"));
+
+ if (PS3[i]->getButtonClick(UP)) {
+ Serial.print(F("\r\nUp"));
+ if (PS3[i]->PS3Connected) {
+ PS3[i]->setLedOff();
+ PS3[i]->setLedOn(LED4);
+ }
+ }
+ if (PS3[i]->getButtonClick(RIGHT)) {
+ Serial.print(F("\r\nRight"));
+ if (PS3[i]->PS3Connected) {
+ PS3[i]->setLedOff();
+ PS3[i]->setLedOn(LED1);
+ }
+ }
+ if (PS3[i]->getButtonClick(DOWN)) {
+ Serial.print(F("\r\nDown"));
+ if (PS3[i]->PS3Connected) {
+ PS3[i]->setLedOff();
+ PS3[i]->setLedOn(LED2);
+ }
+ }
+ if (PS3[i]->getButtonClick(LEFT)) {
+ Serial.print(F("\r\nLeft"));
+ if (PS3[i]->PS3Connected) {
+ PS3[i]->setLedOff();
+ PS3[i]->setLedOn(LED3);
+ }
+ }
+
+ if (PS3[i]->getButtonClick(L1))
+ Serial.print(F("\r\nL1"));
+ if (PS3[i]->getButtonClick(L3))
+ Serial.print(F("\r\nL3"));
+ if (PS3[i]->getButtonClick(R1))
+ Serial.print(F("\r\nR1"));
+ if (PS3[i]->getButtonClick(R3))
+ Serial.print(F("\r\nR3"));
+
+ if (PS3[i]->getButtonClick(SELECT)) {
+ Serial.print(F("\r\nSelect - "));
+ PS3[i]->printStatusString();
+ }
+ if (PS3[i]->getButtonClick(START)) {
+ Serial.print(F("\r\nStart"));
+ printAngle[i] = !printAngle[i];
+ }
+ }
+ if (printAngle[i]) {
+ Serial.print(F("\r\nPitch: "));
+ Serial.print(PS3[i]->getAngle(Pitch));
+ Serial.print(F("\tRoll: "));
+ Serial.print(PS3[i]->getAngle(Roll));
+ }
+ }
+ /* I have removed the PS3 Move code as an Uno will run out of RAM if it's included */
+ //else if(PS3[i]->PS3MoveConnected) {
+ }
+}
+
+void onInit() {
+ for (uint8_t i = 0; i < length; i++) {
+ if ((PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) && !oldControllerState[i]) {
+ oldControllerState[i] = true; // Used to check which is the new controller
+ PS3[i]->setLedOn((LEDEnum)(i + 1)); // Cast directly to LEDEnum - see: "controllerEnums.h"
+ }
+ }
+}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3SPP/PS3SPP.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3SPP/PS3SPP.ino
new file mode 100644
index 0000000000..8f234cbd8d
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3SPP/PS3SPP.ino
@@ -0,0 +1,162 @@
+/*
+ Example sketch for the 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
+
+ This example show how one can combine all the difference Bluetooth services in one single code.
+ Note:
+ You will need a Arduino Mega 1280/2560 to run this sketch,
+ as a normal Arduino (Uno, Duemilanove etc.) doesn't have enough SRAM and FLASH
+ */
+
+#include <PS3BT.h>
+#include <SPP.h>
+#include <usbhub.h>
+
+// Satisfy the IDE, which needs to see the include statment in the ino too.
+#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
+
+/* You can create the instances of the bluetooth services in two ways */
+SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000"
+//SPP SerialBTBT(&Btd,"Lauszus's Arduino","0000"); // You can also set the name and pin like so
+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
+
+bool firstMessage = true;
+String output = ""; // We will store the data in this string
+
+void setup() {
+ Serial.begin(115200); // This wil lprint the debugging from the libraries
+#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\nBluetooth Library Started"));
+ output.reserve(200); // Reserve 200 bytes for the output string
+}
+void loop() {
+ Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well
+
+ if (SerialBT.connected) {
+ if (firstMessage) {
+ firstMessage = false;
+ SerialBT.println(F("Hello from Arduino")); // Send welcome message
+ }
+ if (Serial.available())
+ SerialBT.write(Serial.read());
+ if (SerialBT.available())
+ Serial.write(SerialBT.read());
+ }
+ else
+ firstMessage = true;
+
+ if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
+ output = ""; // Reset output string
+ if (PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) {
+ output += "LeftHatX: ";
+ output += PS3.getAnalogHat(LeftHatX);
+ output += "\tLeftHatY: ";
+ output += PS3.getAnalogHat(LeftHatY);
+ if (PS3.PS3Connected) { // The Navigation controller only have one joystick
+ output += "\tRightHatX: ";
+ output += PS3.getAnalogHat(RightHatX);
+ output += "\tRightHatY: ";
+ output += PS3.getAnalogHat(RightHatY);
+ }
+ }
+ //Analog button values can be read from almost all buttons
+ if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
+ if (output != "")
+ output += "\r\n";
+ output += "L2: ";
+ output += PS3.getAnalogButton(L2);
+ if (PS3.PS3Connected) {
+ output += "\tR2: ";
+ output += PS3.getAnalogButton(R2);
+ }
+ }
+ if (output != "") {
+ Serial.println(output);
+ if (SerialBT.connected)
+ SerialBT.println(output);
+ output = ""; // Reset output string
+ }
+ if (PS3.getButtonClick(PS)) {
+ output += " - PS";
+ PS3.disconnect();
+ }
+ else {
+ if (PS3.getButtonClick(TRIANGLE))
+ output += " - Traingle";
+ if (PS3.getButtonClick(CIRCLE))
+ output += " - Circle";
+ if (PS3.getButtonClick(CROSS))
+ output += " - Cross";
+ if (PS3.getButtonClick(SQUARE))
+ output += " - Square";
+
+ if (PS3.getButtonClick(UP)) {
+ output += " - Up";
+ if (PS3.PS3Connected) {
+ PS3.setLedOff();
+ PS3.setLedOn(LED4);
+ }
+ }
+ if (PS3.getButtonClick(RIGHT)) {
+ output += " - Right";
+ if (PS3.PS3Connected) {
+ PS3.setLedOff();
+ PS3.setLedOn(LED1);
+ }
+ }
+ if (PS3.getButtonClick(DOWN)) {
+ output += " - Down";
+ if (PS3.PS3Connected) {
+ PS3.setLedOff();
+ PS3.setLedOn(LED2);
+ }
+ }
+ if (PS3.getButtonClick(LEFT)) {
+ output += " - Left";
+ if (PS3.PS3Connected) {
+ PS3.setLedOff();
+ PS3.setLedOn(LED3);
+ }
+ }
+
+ if (PS3.getButtonClick(L1))
+ output += " - L1";
+ if (PS3.getButtonClick(L3))
+ output += " - L3";
+ if (PS3.getButtonClick(R1))
+ output += " - R1";
+ if (PS3.getButtonClick(R3))
+ output += " - R3";
+
+ if (PS3.getButtonClick(SELECT)) {
+ output += " - Select";
+ }
+ if (PS3.getButtonClick(START))
+ output += " - Start";
+
+ if (output != "") {
+ String string = "PS3 Controller" + output;
+ Serial.println(string);
+ if (SerialBT.connected)
+ SerialBT.println(string);
+ }
+ }
+ delay(10);
+ }
+}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS4BT/PS4BT.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS4BT/PS4BT.ino
new file mode 100644
index 0000000000..c3ba696bd1
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS4BT/PS4BT.ino
@@ -0,0 +1,146 @@
+/*
+ Example sketch for the PS4 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 <PS4BT.h>
+#include <usbhub.h>
+
+// Satisfy the IDE, which needs to see the include statment in the ino too.
+#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
+
+/* You can create the instance of the PS4BT class in two ways */
+// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
+// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in paring mode
+PS4BT PS4(&Btd, PAIR);
+
+// After that you can simply create the instance like so and then press the PS button on the device
+//PS4BT PS4(&Btd);
+
+bool printAngle, printTouch;
+uint8_t oldL2Value, oldR2Value;
+
+void setup() {
+ 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\nPS4 Bluetooth Library Started"));
+}
+void loop() {
+ Usb.Task();
+
+ if (PS4.connected()) {
+ if (PS4.getAnalogHat(LeftHatX) > 137 || PS4.getAnalogHat(LeftHatX) < 117 || PS4.getAnalogHat(LeftHatY) > 137 || PS4.getAnalogHat(LeftHatY) < 117 || PS4.getAnalogHat(RightHatX) > 137 || PS4.getAnalogHat(RightHatX) < 117 || PS4.getAnalogHat(RightHatY) > 137 || PS4.getAnalogHat(RightHatY) < 117) {
+ Serial.print(F("\r\nLeftHatX: "));
+ Serial.print(PS4.getAnalogHat(LeftHatX));
+ Serial.print(F("\tLeftHatY: "));
+ Serial.print(PS4.getAnalogHat(LeftHatY));
+ Serial.print(F("\tRightHatX: "));
+ Serial.print(PS4.getAnalogHat(RightHatX));
+ Serial.print(F("\tRightHatY: "));
+ Serial.print(PS4.getAnalogHat(RightHatY));
+ }
+
+ if (PS4.getAnalogButton(L2) || PS4.getAnalogButton(R2)) { // These are the only analog buttons on the PS4 controller
+ Serial.print(F("\r\nL2: "));
+ Serial.print(PS4.getAnalogButton(L2));
+ Serial.print(F("\tR2: "));
+ Serial.print(PS4.getAnalogButton(R2));
+ }
+ if (PS4.getAnalogButton(L2) != oldL2Value || PS4.getAnalogButton(R2) != oldR2Value) // Only write value if it's different
+ PS4.setRumbleOn(PS4.getAnalogButton(L2), PS4.getAnalogButton(R2));
+ oldL2Value = PS4.getAnalogButton(L2);
+ oldR2Value = PS4.getAnalogButton(R2);
+
+ if (PS4.getButtonClick(PS)) {
+ Serial.print(F("\r\nPS"));
+ PS4.disconnect();
+ }
+ else {
+ if (PS4.getButtonClick(TRIANGLE)) {
+ Serial.print(F("\r\nTraingle"));
+ PS4.setRumbleOn(RumbleLow);
+ }
+ if (PS4.getButtonClick(CIRCLE)) {
+ Serial.print(F("\r\nCircle"));
+ PS4.setRumbleOn(RumbleHigh);
+ }
+ if (PS4.getButtonClick(CROSS)) {
+ Serial.print(F("\r\nCross"));
+ PS4.setLedFlash(10, 10); // Set it to blink rapidly
+ }
+ if (PS4.getButtonClick(SQUARE)) {
+ Serial.print(F("\r\nSquare"));
+ PS4.setLedFlash(0, 0); // Turn off blinking
+ }
+
+ if (PS4.getButtonClick(UP)) {
+ Serial.print(F("\r\nUp"));
+ PS4.setLed(Red);
+ } if (PS4.getButtonClick(RIGHT)) {
+ Serial.print(F("\r\nRight"));
+ PS4.setLed(Blue);
+ } if (PS4.getButtonClick(DOWN)) {
+ Serial.print(F("\r\nDown"));
+ PS4.setLed(Yellow);
+ } if (PS4.getButtonClick(LEFT)) {
+ Serial.print(F("\r\nLeft"));
+ PS4.setLed(Green);
+ }
+
+ if (PS4.getButtonClick(L1))
+ Serial.print(F("\r\nL1"));
+ if (PS4.getButtonClick(L3))
+ Serial.print(F("\r\nL3"));
+ if (PS4.getButtonClick(R1))
+ Serial.print(F("\r\nR1"));
+ if (PS4.getButtonClick(R3))
+ Serial.print(F("\r\nR3"));
+
+ if (PS4.getButtonClick(SHARE))
+ Serial.print(F("\r\nShare"));
+ if (PS4.getButtonClick(OPTIONS)) {
+ Serial.print(F("\r\nOptions"));
+ printAngle = !printAngle;
+ }
+ if (PS4.getButtonClick(TOUCHPAD)) {
+ Serial.print(F("\r\nTouchpad"));
+ printTouch = !printTouch;
+ }
+
+ if (printAngle) { // Print angle calculated using the accelerometer only
+ Serial.print(F("\r\nPitch: "));
+ Serial.print(PS4.getAngle(Pitch));
+ Serial.print(F("\tRoll: "));
+ Serial.print(PS4.getAngle(Roll));
+ }
+
+ if (printTouch) { // Print the x, y coordinates of the touchpad
+ if (PS4.isTouching(0) || PS4.isTouching(1)) // Print newline and carriage return if any of the fingers are touching the touchpad
+ Serial.print(F("\r\n"));
+ for (uint8_t i = 0; i < 2; i++) { // The touchpad track two fingers
+ if (PS4.isTouching(i)) { // Print the position of the finger if it is touching the touchpad
+ Serial.prin