2013-11-24 21:55:15 +01:00
|
|
|
/*
|
|
|
|
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>
|
2013-11-24 23:51:45 +01:00
|
|
|
#include "KeyboardParser.h"
|
|
|
|
#include "MouseParser.h"
|
2013-12-05 07:32:32 +01:00
|
|
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
|
|
|
#ifdef dobogusinclude
|
|
|
|
#include <spi4teensy3.h>
|
|
|
|
#endif
|
2013-11-24 21:55:15 +01:00
|
|
|
|
|
|
|
USB Usb;
|
|
|
|
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
|
|
|
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
|
2013-11-24 23:51:45 +01:00
|
|
|
|
2013-11-24 21:55:15 +01:00
|
|
|
/* You can create the instance of the class in two ways */
|
2013-11-24 23:51:45 +01:00
|
|
|
// 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
|
2014-01-12 16:31:47 +01:00
|
|
|
BTHID bthid(&Btd, PAIR, "0000");
|
2013-11-24 23:51:45 +01:00
|
|
|
|
|
|
|
// After that you can simply create the instance like so and then press any button on the device
|
|
|
|
//BTHID hid(&Btd);
|
|
|
|
|
2013-11-25 17:39:59 +01:00
|
|
|
KbdRptParser keyboardPrs;
|
2013-11-24 23:51:45 +01:00
|
|
|
MouseRptParser mousePrs;
|
2013-11-24 21:55:15 +01:00
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
|
|
|
if (Usb.Init() == -1) {
|
|
|
|
Serial.print(F("\r\nOSC did not start"));
|
2013-11-24 23:51:45 +01:00
|
|
|
while (1); // Halt
|
2013-11-24 21:55:15 +01:00
|
|
|
}
|
2013-11-24 23:51:45 +01:00
|
|
|
|
2014-01-12 16:31:47 +01:00
|
|
|
bthid.SetReportParser(KEYBOARD_PARSER_ID, (HIDReportParser*)&keyboardPrs);
|
|
|
|
bthid.SetReportParser(MOUSE_PARSER_ID, (HIDReportParser*)&mousePrs);
|
2013-11-24 23:51:45 +01:00
|
|
|
|
|
|
|
// 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
|
2014-01-12 16:31:47 +01:00
|
|
|
bthid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode
|
|
|
|
//bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode
|
2013-11-24 23:51:45 +01:00
|
|
|
|
2013-11-24 21:55:15 +01:00
|
|
|
Serial.print(F("\r\nHID Bluetooth Library Started"));
|
|
|
|
}
|
|
|
|
void loop() {
|
|
|
|
Usb.Task();
|
|
|
|
}
|