aboutsummaryrefslogtreecommitdiff
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)
downloadqmk_firmware-b16091659cc9a724a8800f77e631643b4ab089ad.tar.gz
qmk_firmware-b16091659cc9a724a8800f77e631643b4ab089ad.zip
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 000000000..919a56468
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/BTHID.ino
@@ -0,0 +1,55 @@
1/*
2 Example sketch for the HID Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5 */
6
7#include <BTHID.h>
8#include <usbhub.h>
9#include "KeyboardParser.h"
10#include "MouseParser.h"
11
12// Satisfy the IDE, which needs to see the include statment in the ino too.
13#ifdef dobogusinclude
14#include <spi4teensy3.h>
15#include <SPI.h>
16#endif
17
18USB Usb;
19//USBHub Hub1(&Usb); // Some dongles have a hub inside
20BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
21
22/* You can create the instance of the class in two ways */
23// This will start an inquiry and then pair with your device - you only have to do this once
24// If you are using a Bluetooth keyboard, then you should type in the password on the keypad and then press enter
25BTHID bthid(&Btd, PAIR, "0000");
26
27// After that you can simply create the instance like so and then press any button on the device
28//BTHID hid(&Btd);
29
30KbdRptParser keyboardPrs;
31MouseRptParser mousePrs;
32
33void setup() {
34 Serial.begin(115200);
35#if !defined(__MIPSEL__)
36 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
37#endif
38 if (Usb.Init() == -1) {
39 Serial.print(F("\r\nOSC did not start"));
40 while (1); // Halt
41 }
42
43 bthid.SetReportParser(KEYBOARD_PARSER_ID, (HIDReportParser*)&keyboardPrs);
44 bthid.SetReportParser(MOUSE_PARSER_ID, (HIDReportParser*)&mousePrs);
45
46 // If "Boot Protocol Mode" does not work, then try "Report Protocol Mode"
47 // If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report
48 bthid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode
49 //bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode
50
51 Serial.print(F("\r\nHID Bluetooth Library Started"));
52}
53void loop() {
54 Usb.Task();
55}
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 000000000..c5394331d
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/KeyboardParser.h
@@ -0,0 +1,105 @@
1#ifndef __kbdrptparser_h_
2#define __kbdrptparser_h_
3
4class KbdRptParser : public KeyboardReportParser {
5 protected:
6 virtual uint8_t HandleLockingKeys(HID *hid, uint8_t key);
7 virtual void OnControlKeysChanged(uint8_t before, uint8_t after);
8 virtual void OnKeyDown(uint8_t mod, uint8_t key);
9 virtual void OnKeyUp(uint8_t mod, uint8_t key);
10 virtual void OnKeyPressed(uint8_t key);
11
12 private:
13 void PrintKey(uint8_t mod, uint8_t key);
14};
15
16uint8_t KbdRptParser::HandleLockingKeys(HID *hid, uint8_t key) {
17 uint8_t old_keys = kbdLockingKeys.bLeds;
18
19 switch (key) {
20 case UHS_HID_BOOT_KEY_NUM_LOCK:
21 Serial.println(F("Num lock"));
22 kbdLockingKeys.kbdLeds.bmNumLock = ~kbdLockingKeys.kbdLeds.bmNumLock;
23 break;
24 case UHS_HID_BOOT_KEY_CAPS_LOCK:
25 Serial.println(F("Caps lock"));
26 kbdLockingKeys.kbdLeds.bmCapsLock = ~kbdLockingKeys.kbdLeds.bmCapsLock;
27 break;
28 case UHS_HID_BOOT_KEY_SCROLL_LOCK:
29 Serial.println(F("Scroll lock"));
30 kbdLockingKeys.kbdLeds.bmScrollLock = ~kbdLockingKeys.kbdLeds.bmScrollLock;
31 break;
32 }
33
34 if (old_keys != kbdLockingKeys.bLeds && hid) {
35 BTHID *pBTHID = reinterpret_cast<BTHID *> (hid); // A cast the other way around is done in BTHID.cpp
36 pBTHID->setLeds(kbdLockingKeys.bLeds); // Update the LEDs on the keyboard
37 }
38
39 return 0;
40};
41
42void KbdRptParser::PrintKey(uint8_t m, uint8_t key) {
43 MODIFIERKEYS mod;
44 *((uint8_t*)&mod) = m;
45 Serial.print((mod.bmLeftCtrl == 1) ? F("C") : F(" "));
46 Serial.print((mod.bmLeftShift == 1) ? F("S") : F(" "));
47 Serial.print((mod.bmLeftAlt == 1) ? F("A") : F(" "));
48 Serial.print((mod.bmLeftGUI == 1) ? F("G") : F(" "));
49
50 Serial.print(F(" >"));
51 PrintHex<uint8_t>(key, 0x80);
52 Serial.print(F("< "));
53
54 Serial.print((mod.bmRightCtrl == 1) ? F("C") : F(" "));
55 Serial.print((mod.bmRightShift == 1) ? F("S") : F(" "));
56 Serial.print((mod.bmRightAlt == 1) ? F("A") : F(" "));
57 Serial.println((mod.bmRightGUI == 1) ? F("G") : F(" "));
58};
59
60void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) {
61 Serial.print(F("DN "));
62 PrintKey(mod, key);
63 uint8_t c = OemToAscii(mod, key);
64
65 if (c)
66 OnKeyPressed(c);
67};
68
69void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {
70 MODIFIERKEYS beforeMod;
71 *((uint8_t*)&beforeMod) = before;
72
73 MODIFIERKEYS afterMod;
74 *((uint8_t*)&afterMod) = after;
75
76 if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl)
77 Serial.println(F("LeftCtrl changed"));
78 if (beforeMod.bmLeftShift != afterMod.bmLeftShift)
79 Serial.println(F("LeftShift changed"));
80 if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt)
81 Serial.println(F("LeftAlt changed"));
82 if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI)
83 Serial.println(F("LeftGUI changed"));
84
85 if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl)
86 Serial.println(F("RightCtrl changed"));
87 if (beforeMod.bmRightShift != afterMod.bmRightShift)
88 Serial.println(F("RightShift changed"));
89 if (beforeMod.bmRightAlt != afterMod.bmRightAlt)
90 Serial.println(F("RightAlt changed"));
91 if (beforeMod.bmRightGUI != afterMod.bmRightGUI)
92 Serial.println(F("RightGUI changed"));
93};
94
95void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key) {
96 Serial.print(F("UP "));
97 PrintKey(mod, key);
98};
99
100void KbdRptParser::OnKeyPressed(uint8_t key) {
101 Serial.print(F("ASCII: "));
102 Serial.println((char)key);
103};
104
105#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 000000000..a9245ded9
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/BTHID/MouseParser.h
@@ -0,0 +1,46 @@
1#ifndef __mouserptparser_h__
2#define __mouserptparser_h__
3
4class MouseRptParser : public MouseReportParser {
5 protected:
6 virtual void OnMouseMove(MOUSEINFO *mi);
7 virtual void OnLeftButtonUp(MOUSEINFO *mi);
8 virtual void OnLeftButtonDown(MOUSEINFO *mi);
9 virtual void OnRightButtonUp(MOUSEINFO *mi);
10 virtual void OnRightButtonDown(MOUSEINFO *mi);
11 virtual void OnMiddleButtonUp(MOUSEINFO *mi);
12 virtual void OnMiddleButtonDown(MOUSEINFO *mi);
13};
14
15void MouseRptParser::OnMouseMove(MOUSEINFO *mi) {
16 Serial.print(F("dx="));
17 Serial.print(mi->dX, DEC);
18 Serial.print(F(" dy="));
19 Serial.println(mi->dY, DEC);
20};
21
22void MouseRptParser::OnLeftButtonUp(MOUSEINFO *mi) {
23 Serial.println(F("L Butt Up"));
24};
25
26void MouseRptParser::OnLeftButtonDown(MOUSEINFO *mi) {
27 Serial.println(F("L Butt Dn"));
28};
29
30void MouseRptParser::OnRightButtonUp(MOUSEINFO *mi) {
31 Serial.println(F("R Butt Up"));
32};
33
34void MouseRptParser::OnRightButtonDown(MOUSEINFO *mi) {
35 Serial.println(F("R Butt Dn"));
36};
37
38void MouseRptParser::OnMiddleButtonUp(MOUSEINFO *mi) {
39 Serial.println(F("M Butt Up"));
40};
41
42void MouseRptParser::OnMiddleButtonDown(MOUSEINFO *mi) {
43 Serial.println(F("M Butt Dn"));
44};
45
46#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 000000000..b89673440
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3BT/PS3BT.ino
@@ -0,0 +1,188 @@
1/*
2 Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5 */
6
7#include <PS3BT.h>
8#include <usbhub.h>
9
10// Satisfy the IDE, which needs to see the include statment in the ino too.
11#ifdef dobogusinclude
12#include <spi4teensy3.h>
13#include <SPI.h>
14#endif
15
16USB Usb;
17//USBHub Hub1(&Usb); // Some dongles have a hub inside
18
19BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
20/* You can create the instance of the class in two ways */
21PS3BT PS3(&Btd); // This will just create the instance
22//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
23
24bool printTemperature;
25bool printAngle;
26
27void setup() {
28 Serial.begin(115200);
29#if !defined(__MIPSEL__)
30 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
31#endif
32 if (Usb.Init() == -1) {
33 Serial.print(F("\r\nOSC did not start"));
34 while (1); //halt
35 }
36 Serial.print(F("\r\nPS3 Bluetooth Library Started"));
37}
38void loop() {
39 Usb.Task();
40
41 if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
42 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) {
43 Serial.print(F("\r\nLeftHatX: "));
44 Serial.print(PS3.getAnalogHat(LeftHatX));
45 Serial.print(F("\tLeftHatY: "));
46 Serial.print(PS3.getAnalogHat(LeftHatY));
47 if (PS3.PS3Connected) { // The Navigation controller only have one joystick
48 Serial.print(F("\tRightHatX: "));
49 Serial.print(PS3.getAnalogHat(RightHatX));
50 Serial.print(F("\tRightHatY: "));
51 Serial.print(PS3.getAnalogHat(RightHatY));
52 }
53 }
54
55 // Analog button values can be read from almost all buttons
56 if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
57 Serial.print(F("\r\nL2: "));
58 Serial.print(PS3.getAnalogButton(L2));
59 if (PS3.PS3Connected) {
60 Serial.print(F("\tR2: "));
61 Serial.print(PS3.getAnalogButton(R2));
62 }
63 }
64 if (PS3.getButtonClick(PS)) {
65 Serial.print(F("\r\nPS"));
66 PS3.disconnect();
67 }
68 else {
69 if (PS3.getButtonClick(TRIANGLE))
70 Serial.print(F("\r\nTraingle"));
71 if (PS3.getButtonClick(CIRCLE))
72 Serial.print(F("\r\nCircle"));
73 if (PS3.getButtonClick(CROSS))
74 Serial.print(F("\r\nCross"));
75 if (PS3.getButtonClick(SQUARE))
76 Serial.print(F("\r\nSquare"));
77
78 if (PS3.getButtonClick(UP)) {
79 Serial.print(F("\r\nUp"));
80 if (PS3.PS3Connected) {
81 PS3.setLedOff();
82 PS3.setLedOn(LED4);
83 }
84 }
85 if (PS3.getButtonClick(RIGHT)) {
86 Serial.print(F("\r\nRight"));
87 if (PS3.PS3Connected) {
88 PS3.setLedOff();
89 PS3.setLedOn(LED1);
90 }
91 }
92 if (PS3.getButtonClick(DOWN)) {
93 Serial.print(F("\r\nDown"));
94 if (PS3.PS3Connected) {
95 PS3.setLedOff();
96 PS3.setLedOn(LED2);
97 }
98 }
99 if (PS3.getButtonClick(LEFT)) {
100 Serial.print(F("\r\nLeft"));
101 if (PS3.PS3Connected) {
102 PS3.setLedOff();
103 PS3.setLedOn(LED3);
104 }
105 }
106
107 if (PS3.getButtonClick(L1))
108 Serial.print(F("\r\nL1"));
109 if (PS3.getButtonClick(L3))
110 Serial.print(F("\r\nL3"));
111 if (PS3.getButtonClick(R1))
112 Serial.print(F("\r\nR1"));
113 if (PS3.getButtonClick(R3))
114 Serial.print(F("\r\nR3"));
115
116 if (PS3.getButtonClick(SELECT)) {
117 Serial.print(F("\r\nSelect - "));
118 PS3.printStatusString();
119 }
120 if (PS3.getButtonClick(START)) {
121 Serial.print(F("\r\nStart"));
122 printAngle = !printAngle;
123 }
124 }
125#if 0 // Set this to 1 in order to see the angle of the controller
126 if (printAngle) {
127 Serial.print(F("\r\nPitch: "));
128 Serial.print(PS3.getAngle(Pitch));
129 Serial.print(F("\tRoll: "));
130 Serial.print(PS3.getAngle(Roll));
131 }
132#endif
133 }
134#if 0 // Set this to 1 in order to enable support for the Playstation Move controller
135 else if (PS3.PS3MoveConnected) {
136 if (PS3.getAnalogButton(T)) {
137 Serial.print(F("\r\nT: "));
138 Serial.print(PS3.getAnalogButton(T));
139 }
140 if (PS3.getButtonClick(PS)) {
141 Serial.print(F("\r\nPS"));
142 PS3.disconnect();
143 }
144 else {
145 if (PS3.getButtonClick(SELECT)) {
146 Serial.print(F("\r\nSelect"));
147 printTemperature = !printTemperature;
148 }
149 if (PS3.getButtonClick(START)) {
150 Serial.print(F("\r\nStart"));
151 printAngle = !printAngle;
152 }
153 if (PS3.getButtonClick(TRIANGLE)) {
154 Serial.print(F("\r\nTriangle"));
155 PS3.moveSetBulb(Red);
156 }
157 if (PS3.getButtonClick(CIRCLE)) {
158 Serial.print(F("\r\nCircle"));
159 PS3.moveSetBulb(Green);
160 }
161 if (PS3.getButtonClick(SQUARE)) {
162 Serial.print(F("\r\nSquare"));
163 PS3.moveSetBulb(Blue);
164 }
165 if (PS3.getButtonClick(CROSS)) {
166 Serial.print(F("\r\nCross"));
167 PS3.moveSetBulb(Yellow);
168 }
169 if (PS3.getButtonClick(MOVE)) {
170 PS3.moveSetBulb(Off);
171 Serial.print(F("\r\nMove"));
172 Serial.print(F(" - "));
173 PS3.printStatusString();
174 }
175 }
176 if (printAngle) {
177 Serial.print(F("\r\nPitch: "));
178 Serial.print(PS3.getAngle(Pitch));
179 Serial.print(F("\tRoll: "));
180 Serial.print(PS3.getAngle(Roll));
181 }
182 else if (printTemperature) {
183 Serial.print(F("\r\nTemperature: "));
184 Serial.print(PS3.getTemperature());
185 }
186 }
187#endif
188}
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 000000000..5ebfd7819
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3Multi/PS3Multi.ino
@@ -0,0 +1,149 @@
1/*
2 Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus
3 This example show how one can use multiple controllers with the library
4 For more information visit my blog: http://blog.tkjelectronics.dk/ or
5 send me an e-mail: kristianl@tkjelectronics.com
6 */
7
8#include <PS3BT.h>
9#include <usbhub.h>
10
11// Satisfy the IDE, which needs to see the include statment in the ino too.
12#ifdef dobogusinclude
13#include <spi4teensy3.h>
14#include <SPI.h>
15#endif
16
17USB Usb;
18//USBHub Hub1(&Usb); // Some dongles have a hub inside
19
20BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
21PS3BT *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!
22const uint8_t length = sizeof(PS3) / sizeof(PS3[0]); // Get the lenght of the array
23bool printAngle[length];
24bool oldControllerState[length];
25
26void setup() {
27 for (uint8_t i = 0; i < length; i++) {
28 PS3[i] = new PS3BT(&Btd); // Create the instances
29 PS3[i]->attachOnInit(onInit); // onInit() is called upon a new connection - you can call the function whatever you like
30 }
31
32 Serial.begin(115200);
33#if !defined(__MIPSEL__)
34 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
35#endif
36 if (Usb.Init() == -1) {
37 Serial.print(F("\r\nOSC did not start"));
38 while (1); //halt
39 }
40 Serial.print(F("\r\nPS3 Bluetooth Library Started"));
41}
42void loop() {
43 Usb.Task();
44
45 for (uint8_t i = 0; i < length; i++) {
46 if (PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) {
47 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) {
48 Serial.print(F("\r\nLeftHatX: "));
49 Serial.print(PS3[i]->getAnalogHat(LeftHatX));
50 Serial.print(F("\tLeftHatY: "));
51 Serial.print(PS3[i]->getAnalogHat(LeftHatY));
52 if (PS3[i]->PS3Connected) { // The Navigation controller only have one joystick
53 Serial.print(F("\tRightHatX: "));
54 Serial.print(PS3[i]->getAnalogHat(RightHatX));
55 Serial.print(F("\tRightHatY: "));
56 Serial.print(PS3[i]->getAnalogHat(RightHatY));
57 }
58 }
59 //Analog button values can be read from almost all buttons
60 if (PS3[i]->getAnalogButton(L2) || PS3[i]->getAnalogButton(R2)) {
61 Serial.print(F("\r\nL2: "));
62 Serial.print(PS3[i]->getAnalogButton(L2));
63 if (PS3[i]->PS3Connected) {
64 Serial.print(F("\tR2: "));
65 Serial.print(PS3[i]->getAnalogButton(R2));
66 }
67 }
68 if (PS3[i]->getButtonClick(PS)) {
69 Serial.print(F("\r\nPS"));
70 PS3[i]->disconnect();
71 oldControllerState[i] = false; // Reset value
72 }
73 else {
74 if (PS3[i]->getButtonClick(TRIANGLE))
75 Serial.print(F("\r\nTraingle"));
76 if (PS3[i]->getButtonClick(CIRCLE))
77 Serial.print(F("\r\nCircle"));
78 if (PS3[i]->getButtonClick(CROSS))
79 Serial.print(F("\r\nCross"));
80 if (PS3[i]->getButtonClick(SQUARE))
81 Serial.print(F("\r\nSquare"));
82
83 if (PS3[i]->getButtonClick(UP)) {
84 Serial.print(F("\r\nUp"));
85 if (PS3[i]->PS3Connected) {
86 PS3[i]->setLedOff();
87 PS3[i]->setLedOn(LED4);
88 }
89 }
90 if (PS3[i]->getButtonClick(RIGHT)) {
91 Serial.print(F("\r\nRight"));
92 if (PS3[i]->PS3Connected) {
93 PS3[i]->setLedOff();
94 PS3[i]->setLedOn(LED1);
95 }
96 }
97 if (PS3[i]->getButtonClick(DOWN)) {
98 Serial.print(F("\r\nDown"));
99 if (PS3[i]->PS3Connected) {
100 PS3[i]->setLedOff();
101 PS3[i]->setLedOn(LED2);
102 }
103 }
104 if (PS3[i]->getButtonClick(LEFT)) {
105 Serial.print(F("\r\nLeft"));
106 if (PS3[i]->PS3Connected) {
107 PS3[i]->setLedOff();
108 PS3[i]->setLedOn(LED3);
109 }
110 }
111
112 if (PS3[i]->getButtonClick(L1))
113 Serial.print(F("\r\nL1"));
114 if (PS3[i]->getButtonClick(L3))
115 Serial.print(F("\r\nL3"));
116 if (PS3[i]->getButtonClick(R1))
117 Serial.print(F("\r\nR1"));
118 if (PS3[i]->getButtonClick(R3))
119 Serial.print(F("\r\nR3"));
120
121 if (PS3[i]->getButtonClick(SELECT)) {
122 Serial.print(F("\r\nSelect - "));
123 PS3[i]->printStatusString();
124 }
125 if (PS3[i]->getButtonClick(START)) {
126 Serial.print(F("\r\nStart"));
127 printAngle[i] = !printAngle[i];
128 }
129 }
130 if (printAngle[i]) {
131 Serial.print(F("\r\nPitch: "));
132 Serial.print(PS3[i]->getAngle(Pitch));
133 Serial.print(F("\tRoll: "));
134 Serial.print(PS3[i]->getAngle(Roll));
135 }
136 }
137 /* I have removed the PS3 Move code as an Uno will run out of RAM if it's included */
138 //else if(PS3[i]->PS3MoveConnected) {
139 }
140}
141
142void onInit() {
143 for (uint8_t i = 0; i < length; i++) {
144 if ((PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) && !oldControllerState[i]) {
145 oldControllerState[i] = true; // Used to check which is the new controller
146 PS3[i]->setLedOn((LEDEnum)(i + 1)); // Cast directly to LEDEnum - see: "controllerEnums.h"
147 }
148 }
149}
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 000000000..8f234cbd8
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS3SPP/PS3SPP.ino
@@ -0,0 +1,162 @@
1/*
2 Example sketch for the Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5
6 This example show how one can combine all the difference Bluetooth services in one single code.
7 Note:
8 You will need a Arduino Mega 1280/2560 to run this sketch,
9 as a normal Arduino (Uno, Duemilanove etc.) doesn't have enough SRAM and FLASH
10 */
11
12#include <PS3BT.h>
13#include <SPP.h>
14#include <usbhub.h>
15
16// Satisfy the IDE, which needs to see the include statment in the ino too.
17#ifdef dobogusinclude
18#include <spi4teensy3.h>
19#include <SPI.h>
20#endif
21
22USB Usb;
23//USBHub Hub1(&Usb); // Some dongles have a hub inside
24
25BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
26
27/* You can create the instances of the bluetooth services in two ways */
28SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000"
29//SPP SerialBTBT(&Btd,"Lauszus's Arduino","0000"); // You can also set the name and pin like so
30PS3BT PS3(&Btd); // This will just create the instance
31//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
32
33bool firstMessage = true;
34String output = ""; // We will store the data in this string
35
36void setup() {
37 Serial.begin(115200); // This wil lprint the debugging from the libraries
38#if !defined(__MIPSEL__)
39 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
40#endif
41 if (Usb.Init() == -1) {
42 Serial.print(F("\r\nOSC did not start"));
43 while (1); //halt
44 }
45 Serial.print(F("\r\nBluetooth Library Started"));
46 output.reserve(200); // Reserve 200 bytes for the output string
47}
48void loop() {
49 Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well
50
51 if (SerialBT.connected) {
52 if (firstMessage) {
53 firstMessage = false;
54 SerialBT.println(F("Hello from Arduino")); // Send welcome message
55 }
56 if (Serial.available())
57 SerialBT.write(Serial.read());
58 if (SerialBT.available())
59 Serial.write(SerialBT.read());
60 }
61 else
62 firstMessage = true;
63
64 if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
65 output = ""; // Reset output string
66 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) {
67 output += "LeftHatX: ";
68 output += PS3.getAnalogHat(LeftHatX);
69 output += "\tLeftHatY: ";
70 output += PS3.getAnalogHat(LeftHatY);
71 if (PS3.PS3Connected) { // The Navigation controller only have one joystick
72 output += "\tRightHatX: ";
73 output += PS3.getAnalogHat(RightHatX);
74 output += "\tRightHatY: ";
75 output += PS3.getAnalogHat(RightHatY);
76 }
77 }
78 //Analog button values can be read from almost all buttons
79 if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
80 if (output != "")
81 output += "\r\n";
82 output += "L2: ";
83 output += PS3.getAnalogButton(L2);
84 if (PS3.PS3Connected) {
85 output += "\tR2: ";
86 output += PS3.getAnalogButton(R2);
87 }
88 }
89 if (output != "") {
90 Serial.println(output);
91 if (SerialBT.connected)
92 SerialBT.println(output);
93 output = ""; // Reset output string
94 }
95 if (PS3.getButtonClick(PS)) {
96 output += " - PS";
97 PS3.disconnect();
98 }
99 else {
100 if (PS3.getButtonClick(TRIANGLE))
101 output += " - Traingle";
102 if (PS3.getButtonClick(CIRCLE))
103 output += " - Circle";
104 if (PS3.getButtonClick(CROSS))
105 output += " - Cross";
106 if (PS3.getButtonClick(SQUARE))
107 output += " - Square";
108
109 if (PS3.getButtonClick(UP)) {
110 output += " - Up";
111 if (PS3.PS3Connected) {
112 PS3.setLedOff();
113 PS3.setLedOn(LED4);
114 }
115 }
116 if (PS3.getButtonClick(RIGHT)) {
117 output += " - Right";
118 if (PS3.PS3Connected) {
119 PS3.setLedOff();
120 PS3.setLedOn(LED1);
121 }
122 }
123 if (PS3.getButtonClick(DOWN)) {
124 output += " - Down";
125 if (PS3.PS3Connected) {
126 PS3.setLedOff();
127 PS3.setLedOn(LED2);
128 }
129 }
130 if (PS3.getButtonClick(LEFT)) {
131 output += " - Left";
132 if (PS3.PS3Connected) {
133 PS3.setLedOff();
134 PS3.setLedOn(LED3);
135 }
136 }
137
138 if (PS3.getButtonClick(L1))
139 output += " - L1";
140 if (PS3.getButtonClick(L3))
141 output += " - L3";
142 if (PS3.getButtonClick(R1))
143 output += " - R1";
144 if (PS3.getButtonClick(R3))
145 output += " - R3";
146
147 if (PS3.getButtonClick(SELECT)) {
148 output += " - Select";
149 }
150 if (PS3.getButtonClick(START))
151 output += " - Start";
152
153 if (output != "") {
154 String string = "PS3 Controller" + output;
155 Serial.println(string);
156 if (SerialBT.connected)
157 SerialBT.println(string);
158 }
159 }
160 delay(10);
161 }
162}
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 000000000..c3ba696bd
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/PS4BT/PS4BT.ino
@@ -0,0 +1,146 @@
1/*
2 Example sketch for the PS4 Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5 */
6
7#include <PS4BT.h>
8#include <usbhub.h>
9
10// Satisfy the IDE, which needs to see the include statment in the ino too.
11#ifdef dobogusinclude
12#include <spi4teensy3.h>
13#include <SPI.h>
14#endif
15
16USB Usb;
17//USBHub Hub1(&Usb); // Some dongles have a hub inside
18BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
19
20/* You can create the instance of the PS4BT class in two ways */
21// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
22// 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
23PS4BT PS4(&Btd, PAIR);
24
25// After that you can simply create the instance like so and then press the PS button on the device
26//PS4BT PS4(&Btd);
27
28bool printAngle, printTouch;
29uint8_t oldL2Value, oldR2Value;
30
31void setup() {
32 Serial.begin(115200);
33#if !defined(__MIPSEL__)
34 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
35#endif
36 if (Usb.Init() == -1) {
37 Serial.print(F("\r\nOSC did not start"));
38 while (1); // Halt
39 }
40 Serial.print(F("\r\nPS4 Bluetooth Library Started"));
41}
42void loop() {
43 Usb.Task();
44
45 if (PS4.connected()) {
46 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) {
47 Serial.print(F("\r\nLeftHatX: "));
48 Serial.print(PS4.getAnalogHat(LeftHatX));
49 Serial.print(F("\tLeftHatY: "));
50 Serial.print(PS4.getAnalogHat(LeftHatY));
51 Serial.print(F("\tRightHatX: "));
52 Serial.print(PS4.getAnalogHat(RightHatX));
53 Serial.print(F("\tRightHatY: "));
54 Serial.print(PS4.getAnalogHat(RightHatY));
55 }
56
57 if (PS4.getAnalogButton(L2) || PS4.getAnalogButton(R2)) { // These are the only analog buttons on the PS4 controller
58 Serial.print(F("\r\nL2: "));
59 Serial.print(PS4.getAnalogButton(L2));
60 Serial.print(F("\tR2: "));
61 Serial.print(PS4.getAnalogButton(R2));
62 }
63 if (PS4.getAnalogButton(L2) != oldL2Value || PS4.getAnalogButton(R2) != oldR2Value) // Only write value if it's different
64 PS4.setRumbleOn(PS4.getAnalogButton(L2), PS4.getAnalogButton(R2));
65 oldL2Value = PS4.getAnalogButton(L2);
66 oldR2Value = PS4.getAnalogButton(R2);
67
68 if (PS4.getButtonClick(PS)) {
69 Serial.print(F("\r\nPS"));
70 PS4.disconnect();
71 }
72 else {
73 if (PS4.getButtonClick(TRIANGLE)) {
74 Serial.print(F("\r\nTraingle"));
75 PS4.setRumbleOn(RumbleLow);
76 }
77 if (PS4.getButtonClick(CIRCLE)) {
78 Serial.print(F("\r\nCircle"));
79 PS4.setRumbleOn(RumbleHigh);
80 }
81 if (PS4.getButtonClick(CROSS)) {
82 Serial.print(F("\r\nCross"));
83 PS4.setLedFlash(10, 10); // Set it to blink rapidly
84 }
85 if (PS4.getButtonClick(SQUARE)) {
86 Serial.print(F("\r\nSquare"));
87 PS4.setLedFlash(0, 0); // Turn off blinking
88 }
89
90 if (PS4.getButtonClick(UP)) {
91 Serial.print(F("\r\nUp"));
92 PS4.setLed(Red);
93 } if (PS4.getButtonClick(RIGHT)) {
94 Serial.print(F("\r\nRight"));
95 PS4.setLed(Blue);
96 } if (PS4.getButtonClick(DOWN)) {
97 Serial.print(F("\r\nDown"));
98 PS4.setLed(Yellow);
99 } if (PS4.getButtonClick(LEFT)) {
100 Serial.print(F("\r\nLeft"));
101 PS4.setLed(Green);
102 }
103
104 if (PS4.getButtonClick(L1))
105 Serial.print(F("\r\nL1"));
106 if (PS4.getButtonClick(L3))
107 Serial.print(F("\r\nL3"));
108 if (PS4.getButtonClick(R1))
109 Serial.print(F("\r\nR1"));
110 if (PS4.getButtonClick(R3))
111 Serial.print(F("\r\nR3"));
112
113 if (PS4.getButtonClick(SHARE))
114 Serial.print(F("\r\nShare"));
115 if (PS4.getButtonClick(OPTIONS)) {
116 Serial.print(F("\r\nOptions"));
117 printAngle = !printAngle;
118 }
119 if (PS4.getButtonClick(TOUCHPAD)) {
120 Serial.print(F("\r\nTouchpad"));
121 printTouch = !printTouch;
122 }
123
124 if (printAngle) { // Print angle calculated using the accelerometer only
125 Serial.print(F("\r\nPitch: "));
126 Serial.print(PS4.getAngle(Pitch));
127 Serial.print(F("\tRoll: "));
128 Serial.print(PS4.getAngle(Roll));
129 }
130
131 if (printTouch) { // Print the x, y coordinates of the touchpad
132 if (PS4.isTouching(0) || PS4.isTouching(1)) // Print newline and carriage return if any of the fingers are touching the touchpad
133 Serial.print(F("\r\n"));
134 for (uint8_t i = 0; i < 2; i++) { // The touchpad track two fingers
135 if (PS4.isTouching(i)) { // Print the position of the finger if it is touching the touchpad
136 Serial.print(F("X")); Serial.print(i + 1); Serial.print(F(": "));
137 Serial.print(PS4.getX(i));
138 Serial.print(F("\tY")); Serial.print(i + 1); Serial.print(F(": "));
139 Serial.print(PS4.getY(i));
140 Serial.print(F("\t"));
141 }
142 }
143 }
144 }
145 }
146}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/SPP/SPP.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/SPP/SPP.ino
new file mode 100644
index 000000000..8fb9c4eca
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/SPP/SPP.ino
@@ -0,0 +1,52 @@
1/*
2 Example sketch for the RFCOMM/SPP Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5 */
6
7#include <SPP.h>
8#include <usbhub.h>
9
10// Satisfy the IDE, which needs to see the include statment in the ino too.
11#ifdef dobogusinclude
12#include <spi4teensy3.h>
13#include <SPI.h>
14#endif
15
16USB Usb;
17//USBHub Hub1(&Usb); // Some dongles have a hub inside
18
19BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
20/* You can create the instance of the class in two ways */
21SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000"
22//SPP SerialBT(&Btd, "Lauszus's Arduino", "1234"); // You can also set the name and pin like so
23
24bool firstMessage = true;
25
26void setup() {
27 Serial.begin(115200);
28#if !defined(__MIPSEL__)
29 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
30#endif
31 if (Usb.Init() == -1) {
32 Serial.print(F("\r\nOSC did not start"));
33 while (1); //halt
34 }
35 Serial.print(F("\r\nSPP Bluetooth Library Started"));
36}
37void loop() {
38 Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well
39
40 if (SerialBT.connected) {
41 if (firstMessage) {
42 firstMessage = false;
43 SerialBT.println(F("Hello from Arduino")); // Send welcome message
44 }
45 if (Serial.available())
46 SerialBT.write(Serial.read());
47 if (SerialBT.available())
48 Serial.write(SerialBT.read());
49 }
50 else
51 firstMessage = true;
52}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino
new file mode 100644
index 000000000..df521d8e1
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino
@@ -0,0 +1,67 @@
1/*
2 Example sketch for the RFCOMM/SPP Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5 */
6
7#include <SPP.h>
8#include <usbhub.h>
9
10// Satisfy IDE, which only needs to see the include statment in the ino.
11#ifdef dobogusinclude
12#include <spi4teensy3.h>
13#include <SPI.h>
14#endif
15
16USB Usb;
17//USBHub Hub1(&Usb); // Some dongles have a hub inside
18
19BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
20
21const uint8_t length = 2; // Set the number of instances here
22SPP *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!
23
24bool firstMessage[length] = { true }; // Set all to true
25
26void setup() {
27 for (uint8_t i = 0; i < length; i++)
28 SerialBT[i] = new SPP(&Btd); // This will set the name to the default: "Arduino" and the pin to "0000" for all connections
29
30 Serial.begin(115200);
31#if !defined(__MIPSEL__)
32 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
33#endif
34 if (Usb.Init() == -1) {
35 Serial.print(F("\r\nOSC did not start"));
36 while (1); // Halt
37 }
38 Serial.print(F("\r\nSPP Bluetooth Library Started"));
39}
40
41void loop() {
42 Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well
43
44 for (uint8_t i = 0; i < length; i++) {
45 if (SerialBT[i]->connected) {
46 if (firstMessage[i]) {
47 firstMessage[i] = false;
48 SerialBT[i]->println(F("Hello from Arduino")); // Send welcome message
49 }
50 if (SerialBT[i]->available())
51 Serial.write(SerialBT[i]->read());
52 }
53 else
54 firstMessage[i] = true;
55 }
56
57 // Set the connection you want to send to using the first character
58 // For instance "0Hello World" would send "Hello World" to connection 0
59 if (Serial.available()) {
60 delay(10); // Wait for the rest of the data to arrive
61 uint8_t id = Serial.read() - '0'; // Convert from ASCII
62 if (id < length && SerialBT[id]->connected) { // Make sure that the id is valid and make sure that a device is actually connected
63 while (Serial.available()) // Check if data is available
64 SerialBT[id]->write(Serial.read()); // Send the data
65 }
66 }
67}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/Wii/Wii.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/Wii/Wii.ino
new file mode 100644
index 000000000..b19356816
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/Wii/Wii.ino
@@ -0,0 +1,118 @@
1/*
2 Example sketch for the Wiimote Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5 */
6
7#include <Wii.h>
8#include <usbhub.h>
9
10// Satisfy the IDE, which needs to see the include statment in the ino too.
11#ifdef dobogusinclude
12#include <spi4teensy3.h>
13#include <SPI.h>
14#endif
15
16USB Usb;
17//USBHub Hub1(&Usb); // Some dongles have a hub inside
18
19BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
20/* You can create the instance of the class in two ways */
21WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
22//WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote
23
24bool printAngle;
25
26void setup() {
27 Serial.begin(115200);
28#if !defined(__MIPSEL__)
29 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
30#endif
31 if (Usb.Init() == -1) {
32 Serial.print(F("\r\nOSC did not start"));
33 while (1); //halt
34 }
35 Serial.print(F("\r\nWiimote Bluetooth Library Started"));
36}
37void loop() {
38 Usb.Task();
39 if (Wii.wiimoteConnected) {
40 if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
41 Serial.print(F("\r\nHOME"));
42 Wii.disconnect();
43 }
44 else {
45 if (Wii.getButtonClick(LEFT)) {
46 Wii.setLedOff();
47 Wii.setLedOn(LED1);
48 Serial.print(F("\r\nLeft"));
49 }
50 if (Wii.getButtonClick(RIGHT)) {
51 Wii.setLedOff();
52 Wii.setLedOn(LED3);
53 Serial.print(F("\r\nRight"));
54 }
55 if (Wii.getButtonClick(DOWN)) {
56 Wii.setLedOff();
57 Wii.setLedOn(LED4);
58 Serial.print(F("\r\nDown"));
59 }
60 if (Wii.getButtonClick(UP)) {
61 Wii.setLedOff();
62 Wii.setLedOn(LED2);
63 Serial.print(F("\r\nUp"));
64 }
65
66 if (Wii.getButtonClick(PLUS))
67 Serial.print(F("\r\nPlus"));
68 if (Wii.getButtonClick(MINUS))
69 Serial.print(F("\r\nMinus"));
70
71 if (Wii.getButtonClick(ONE))
72 Serial.print(F("\r\nOne"));
73 if (Wii.getButtonClick(TWO))
74 Serial.print(F("\r\nTwo"));
75
76 if (Wii.getButtonClick(A)) {
77 printAngle = !printAngle;
78 Serial.print(F("\r\nA"));
79 }
80 if (Wii.getButtonClick(B)) {
81 Wii.setRumbleToggle();
82 Serial.print(F("\r\nB"));
83 }
84 }
85#if 0 // Set this to 1 in order to see the angle of the controllers
86 if (printAngle) {
87 Serial.print(F("\r\nPitch: "));
88 Serial.print(Wii.getPitch());
89 Serial.print(F("\tRoll: "));
90 Serial.print(Wii.getRoll());
91 if (Wii.motionPlusConnected) {
92 Serial.print(F("\tYaw: "));
93 Serial.print(Wii.getYaw());
94 }
95 if (Wii.nunchuckConnected) {
96 Serial.print(F("\tNunchuck Pitch: "));
97 Serial.print(Wii.getNunchuckPitch());
98 Serial.print(F("\tNunchuck Roll: "));
99 Serial.print(Wii.getNunchuckRoll());
100 }
101 }
102#endif
103 }
104#if 0 // Set this to 1 if you are using a Nunchuck controller
105 if (Wii.nunchuckConnected) {
106 if (Wii.getButtonClick(Z))
107 Serial.print(F("\r\nZ"));
108 if (Wii.getButtonClick(C))
109 Serial.print(F("\r\nC"));
110 if (Wii.getAnalogHat(HatX) > 137 || Wii.getAnalogHat(HatX) < 117 || Wii.getAnalogHat(HatY) > 137 || Wii.getAnalogHat(HatY) < 117) {
111 Serial.print(F("\r\nHatX: "));
112 Serial.print(Wii.getAnalogHat(HatX));
113 Serial.print(F("\tHatY: "));
114 Serial.print(Wii.getAnalogHat(HatY));
115 }
116 }
117#endif
118}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino
new file mode 100644
index 000000000..18c5b411e
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino
@@ -0,0 +1,51 @@
1/*
2 Example sketch for the Wii Balance Board Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5 */
6
7#include <Wii.h>
8#include <usbhub.h>
9
10// Satisfy the IDE, which needs to see the include statment in the ino too.
11#ifdef dobogusinclude
12#include <spi4teensy3.h>
13#include <SPI.h>
14#endif
15
16USB Usb;
17//USBHub Hub1(&Usb); // Some dongles have a hub inside
18
19BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
20/* You can create the instance of the class in two ways */
21WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wii Balance Board - you only have to do this once
22//WII Wii(&Btd); // After that you can simply create the instance like so and then press the power button on the Wii Balance Board
23
24void setup() {
25 Serial.begin(115200);
26#if !defined(__MIPSEL__)
27 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
28#endif
29 if (Usb.Init() == -1) {
30 Serial.print(F("\r\nOSC did not start"));
31 while (1); //halt
32 }
33 Serial.print(F("\r\nWii Balance Board Bluetooth Library Started"));
34}
35void loop() {
36 Usb.Task();
37 if (Wii.wiiBalanceBoardConnected) {
38 Serial.print(F("\r\nWeight: "));
39 for (uint8_t i = 0; i < 4; i++) {
40 Serial.print(Wii.getWeight((BalanceBoardEnum)i));
41 Serial.print(F("\t"));
42 }
43 Serial.print(F("Total Weight: "));
44 Serial.print(Wii.getTotalWeight());
45 if (Wii.getButtonClick(A)) {
46 Serial.print(F("\r\nA"));
47 //Wii.setLedToggle(LED1); // The Wii Balance Board has one LED as well
48 Wii.disconnect();
49 }
50 }
51}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino
new file mode 100644
index 000000000..573b8bd48
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino
@@ -0,0 +1,133 @@
1/*
2Example sketch for the Wii libary showing the IR camera functionality. This example
3is for the Bluetooth Wii library developed for the USB shield from Circuits@Home
4
5Created by Allan Glover and Kristian Lauszus.
6Contact Kristian: http://blog.tkjelectronics.dk/ or send an email at kristianl@tkjelectronics.com.
7Contact Allan at adglover9.81@gmail.com
8
9To test the Wiimote IR camera, you will need access to an IR source. Sunlight will work but is not ideal.
10The simpleist solution is to use the Wii sensor bar, i.e. emitter bar, supplied by the Wii system.
11Otherwise, wire up a IR LED yourself.
12*/
13
14#include <Wii.h>
15#include <usbhub.h>
16
17// Satisfy the IDE, which needs to see the include statment in the ino too.
18#ifdef dobogusinclude
19#include <spi4teensy3.h>
20#include <SPI.h>
21#endif
22
23#ifndef WIICAMERA // Used to check if WIICAMERA is defined
24#error "Please set ENABLE_WII_IR_CAMERA to 1 in settings.h"
25#endif
26
27USB Usb;
28//USBHub Hub1(&Usb); // Some dongles have a hub inside
29
30BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
31/* You can create the instance of the class in two ways */
32WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
33//WII Wii(&Btd); // After the Wiimote pairs once with the line of code above, you can simply create the instance like so and re upload and then press any button on the Wiimote
34
35bool printAngle;
36uint8_t printObjects;
37
38void setup() {
39 Serial.begin(115200);
40#if !defined(__MIPSEL__)
41 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
42#endif
43 if (Usb.Init() == -1) {
44 Serial.print(F("\r\nOSC did not start"));
45 while (1); //halt
46 }
47 Serial.print(F("\r\nWiimote Bluetooth Library Started"));
48}
49
50void loop() {
51 Usb.Task();
52 if (Wii.wiimoteConnected) {
53 if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
54 Serial.print(F("\r\nHOME"));
55 Wii.disconnect();
56 }
57 else {
58 if (Wii.getButtonClick(ONE))
59 Wii.IRinitialize(); // Run the initialisation sequence
60 if (Wii.getButtonClick(MINUS) || Wii.getButtonClick(PLUS)) {
61 if (!Wii.isIRCameraEnabled())
62 Serial.print(F("\r\nEnable IR camera first"));
63 else {
64 if (Wii.getButtonPress(MINUS)) { // getButtonClick will only return true once
65 if (printObjects > 0)
66 printObjects--;
67 }
68 else {
69 if (printObjects < 4)
70 printObjects++;
71 }
72 Serial.print(F("\r\nTracking "));
73 Serial.print(printObjects);
74 Serial.print(F(" objects"));
75 }
76 }
77 if (Wii.getButtonClick(A)) {
78 printAngle = !printAngle;
79 Serial.print(F("\r\nA"));
80 }
81 if (Wii.getButtonClick(B)) {
82 Serial.print(F("\r\nBattery level: "));
83 Serial.print(Wii.getBatteryLevel()); // You can get the battery level as well
84 }
85 }
86 if (printObjects > 0) {
87 if (Wii.getIRx1() != 0x3FF || Wii.getIRy1() != 0x3FF || Wii.getIRs1() != 0) { // Only print if the IR camera is actually seeing something
88 Serial.print(F("\r\nx1: "));
89 Serial.print(Wii.getIRx1());
90 Serial.print(F("\ty1: "));
91 Serial.print(Wii.getIRy1());
92 Serial.print(F("\ts1:"));
93 Serial.print(Wii.getIRs1());
94 }
95 if (printObjects > 1) {
96 if (Wii.getIRx2() != 0x3FF || Wii.getIRy2() != 0x3FF || Wii.getIRs2() != 0) {
97 Serial.print(F("\r\nx2: "));
98 Serial.print(Wii.getIRx2());
99 Serial.print(F("\ty2: "));
100 Serial.print(Wii.getIRy2());
101 Serial.print(F("\ts2:"));
102 Serial.print(Wii.getIRs2());
103 }
104 if (printObjects > 2) {
105 if (Wii.getIRx3() != 0x3FF || Wii.getIRy3() != 0x3FF || Wii.getIRs3() != 0) {
106 Serial.print(F("\r\nx3: "));
107 Serial.print(Wii.getIRx3());
108 Serial.print(F("\ty3: "));
109 Serial.print(Wii.getIRy3());
110 Serial.print(F("\ts3:"));
111 Serial.print(Wii.getIRs3());
112 }
113 if (printObjects > 3) {
114 if (Wii.getIRx4() != 0x3FF || Wii.getIRy4() != 0x3FF || Wii.getIRs4() != 0) {
115 Serial.print(F("\r\nx4: "));
116 Serial.print(Wii.getIRx4());
117 Serial.print(F("\ty4: "));
118 Serial.print(Wii.getIRy4());
119 Serial.print(F("\ts4:"));
120 Serial.print(Wii.getIRs4());
121 }
122 }
123 }
124 }
125 }
126 if (printAngle) { // There is no extension bytes available, so the MotionPlus or Nunchuck can't be read
127 Serial.print(F("\r\nPitch: "));
128 Serial.print(Wii.getPitch());
129 Serial.print(F("\tRoll: "));
130 Serial.print(Wii.getRoll());
131 }
132 }
133}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiMulti/WiiMulti.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiMulti/WiiMulti.ino
new file mode 100644
index 000000000..07c6f13d2
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiMulti/WiiMulti.ino
@@ -0,0 +1,132 @@
1/*
2 Example sketch for the Wiimote Bluetooth library - developed by Kristian Lauszus
3 This example show how one can use multiple controllers with the library
4 For more information visit my blog: http://blog.tkjelectronics.dk/ or
5 send me an e-mail: kristianl@tkjelectronics.com
6 */
7
8#include <Wii.h>
9#include <usbhub.h>
10
11// Satisfy the IDE, which needs to see the include statment in the ino too.
12#ifdef dobogusinclude
13#include <spi4teensy3.h>
14#include <SPI.h>
15#endif
16
17USB Usb;
18//USBHub Hub1(&Usb); // Some dongles have a hub inside
19
20BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
21WII *Wii[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!
22const uint8_t length = sizeof(Wii) / sizeof(Wii[0]); // Get the lenght of the array
23bool printAngle[length];
24bool oldControllerState[length];
25
26void setup() {
27 for (uint8_t i = 0; i < length; i++) {
28 Wii[i] = new WII(&Btd); // You will have to pair each controller with the dongle before you can define the instances like so, just add PAIR as the second argument
29 Wii[i]->attachOnInit(onInit); // onInit() is called upon a new connection - you can call the function whatever you like
30 }
31
32 Serial.begin(115200);
33#if !defined(__MIPSEL__)
34 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
35#endif
36 if (Usb.Init() == -1) {
37 Serial.print(F("\r\nOSC did not start"));
38 while (1); //halt
39 }
40 Serial.print(F("\r\nWiimote Bluetooth Library Started"));
41}
42void loop() {
43 Usb.Task();
44
45 for (uint8_t i = 0; i < length; i++) {
46 if (Wii[i]->wiimoteConnected) {
47 if (Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
48 Serial.print(F("\r\nHOME"));
49 Wii[i]->disconnect();
50 oldControllerState[i] = false; // Reset value
51 }
52 else {
53 if (Wii[i]->getButtonClick(LEFT)) {
54 Wii[i]->setLedOff();
55 Wii[i]->setLedOn(LED1);
56 Serial.print(F("\r\nLeft"));
57 }
58 if (Wii[i]->getButtonClick(RIGHT)) {
59 Wii[i]->setLedOff();
60 Wii[i]->setLedOn(LED3);
61 Serial.print(F("\r\nRight"));
62 }
63 if (Wii[i]->getButtonClick(DOWN)) {
64 Wii[i]->setLedOff();
65 Wii[i]->setLedOn(LED4);
66 Serial.print(F("\r\nDown"));
67 }
68 if (Wii[i]->getButtonClick(UP)) {
69 Wii[i]->setLedOff();
70 Wii[i]->setLedOn(LED2);
71 Serial.print(F("\r\nUp"));
72 }
73
74 if (Wii[i]->getButtonClick(PLUS))
75 Serial.print(F("\r\nPlus"));
76 if (Wii[i]->getButtonClick(MINUS))
77 Serial.print(F("\r\nMinus"));
78
79 if (Wii[i]->getButtonClick(ONE))
80 Serial.print(F("\r\nOne"));
81 if (Wii[i]->getButtonClick(TWO))
82 Serial.print(F("\r\nTwo"));
83
84 if (Wii[i]->getButtonClick(A)) {
85 printAngle[i] = !printAngle[i];
86 Serial.print(F("\r\nA"));
87 }
88 if (Wii[i]->getButtonClick(B)) {
89 Wii[i]->setRumbleToggle();
90 Serial.print(F("\r\nB"));
91 }
92 }
93 if (printAngle[i]) {
94 Serial.print(F("\r\nPitch: "));
95 Serial.print(Wii[i]->getPitch());
96 Serial.print(F("\tRoll: "));
97 Serial.print(Wii[i]->getRoll());
98 if (Wii[i]->motionPlusConnected) {
99 Serial.print(F("\tYaw: "));
100 Serial.print(Wii[i]->getYaw());
101 }
102 if (Wii[i]->nunchuckConnected) {
103 Serial.print(F("\tNunchuck Pitch: "));
104 Serial.print(Wii[i]->getNunchuckPitch());
105 Serial.print(F("\tNunchuck Roll: "));
106 Serial.print(Wii[i]->getNunchuckRoll());
107 }
108 }
109 }
110 if (Wii[i]->nunchuckConnected) {
111 if (Wii[i]->getButtonClick(Z))
112 Serial.print(F("\r\nZ"));
113 if (Wii[i]->getButtonClick(C))
114 Serial.print(F("\r\nC"));
115 if (Wii[i]->getAnalogHat(HatX) > 137 || Wii[i]->getAnalogHat(HatX) < 117 || Wii[i]->getAnalogHat(HatY) > 137 || Wii[i]->getAnalogHat(HatY) < 117) {
116 Serial.print(F("\r\nHatX: "));
117 Serial.print(Wii[i]->getAnalogHat(HatX));
118 Serial.print(F("\tHatY: "));
119 Serial.print(Wii[i]->getAnalogHat(HatY));
120 }
121 }
122 }
123}
124
125void onInit() {
126 for (uint8_t i = 0; i < length; i++) {
127 if (Wii[i]->wiimoteConnected && !oldControllerState[i]) {
128 oldControllerState[i] = true; // Used to check which is the new controller
129 Wii[i]->setLedOn((LEDEnum)(i + 1)); // Cast directly to LEDEnum - see: "controllerEnums.h"
130 }
131 }
132}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiUProController/WiiUProController.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiUProController/WiiUProController.ino
new file mode 100644
index 000000000..ab35a2747
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/Bluetooth/WiiUProController/WiiUProController.ino
@@ -0,0 +1,104 @@
1/*
2 Example sketch for the Wiimote Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5 */
6
7#include <Wii.h>
8#include <usbhub.h>
9
10// Satisfy the IDE, which needs to see the include statment in the ino too.
11#ifdef dobogusinclude
12#include <spi4teensy3.h>
13#include <SPI.h>
14#endif
15
16USB Usb;
17//USBHub Hub1(&Usb); // Some dongles have a hub inside
18
19BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
20/* You can create the instance of the class in two ways */
21WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
22//WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote
23
24void setup() {
25 Serial.begin(115200);
26#if !defined(__MIPSEL__)
27 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
28#endif
29 if (Usb.Init() == -1) {
30 Serial.print(F("\r\nOSC did not start"));
31 while (1); //halt
32 }
33 Serial.print(F("\r\nWiimote Bluetooth Library Started"));
34}
35void loop() {
36 Usb.Task();
37 if (Wii.wiiUProControllerConnected) {
38 if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
39 Serial.print(F("\r\nHome"));
40 Wii.disconnect();
41 }
42 else {
43 if (Wii.getButtonClick(LEFT)) {
44 Wii.setLedOff();
45 Wii.setLedOn(LED1);
46 Serial.print(F("\r\nLeft"));
47 }
48 if (Wii.getButtonClick(RIGHT)) {
49 Wii.setLedOff();
50 Wii.setLedOn(LED3);
51 Serial.print(F("\r\nRight"));
52 }
53 if (Wii.getButtonClick(DOWN)) {
54 Wii.setLedOff();
55 Wii.setLedOn(LED4);
56 Serial.print(F("\r\nDown"));
57 }
58 if (Wii.getButtonClick(UP)) {
59 Wii.setLedOff();
60 Wii.setLedOn(LED2);
61 Serial.print(F("\r\nUp"));
62 }
63
64 if (Wii.getButtonClick(PLUS))
65 Serial.print(F("\r\nPlus"));
66 if (Wii.getButtonClick(MINUS))
67 Serial.print(F("\r\nMinus"));
68
69 if (Wii.getButtonClick(A))
70 Serial.print(F("\r\nA"));
71 if (Wii.getButtonClick(B)) {
72 Wii.setRumbleToggle();
73 Serial.print(F("\r\nB"));
74 }
75 if (Wii.getButtonClick(X))
76 Serial.print(F("\r\nX"));
77 if (Wii.getButtonClick(Y))
78 Serial.print(F("\r\nY"));
79
80 if (Wii.getButtonClick(L))
81 Serial.print(F("\r\nL"));
82 if (Wii.getButtonClick(R))
83 Serial.print(F("\r\nR"));
84 if (Wii.getButtonClick(ZL))
85 Serial.print(F("\r\nZL"));
86 if (Wii.getButtonClick(ZR))
87 Serial.print(F("\r\nZR"));
88 if (Wii.getButtonClick(L3))
89 Serial.print(F("\r\nL3"));
90 if (Wii.getButtonClick(R3))
91 Serial.print(F("\r\nR3"));
92 }
93 if (Wii.getAnalogHat(LeftHatX) > 2200 || Wii.getAnalogHat(LeftHatX) < 1800 || Wii.getAnalogHat(LeftHatY) > 2200 || Wii.getAnalogHat(LeftHatY) < 1800 || Wii.getAnalogHat(RightHatX) > 2200 || Wii.getAnalogHat(RightHatX) < 1800 || Wii.getAnalogHat(RightHatY) > 2200 || Wii.getAnalogHat(RightHatY) < 1800) {
94 Serial.print(F("\r\nLeftHatX: "));
95 Serial.print(Wii.getAnalogHat(LeftHatX));
96 Serial.print(F("\tLeftHatY: "));
97 Serial.print(Wii.getAnalogHat(LeftHatY));
98 Serial.print(F("\tRightHatX: "));
99 Serial.print(Wii.getAnalogHat(RightHatX));
100 Serial.print(F("\tRightHatY: "));
101 Serial.print(Wii.getAnalogHat(RightHatY));
102 }
103 }
104}