logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

BTHID.ino (1912B)


  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. #include <BTHID.h>
  7. #include <usbhub.h>
  8. #include "KeyboardParser.h"
  9. #include "MouseParser.h"
  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. USB Usb;
  16. //USBHub Hub1(&Usb); // Some dongles have a hub inside
  17. BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
  18. /* You can create the instance of the class in two ways */
  19. // This will start an inquiry and then pair with your device - you only have to do this once
  20. // If you are using a Bluetooth keyboard, then you should type in the password on the keypad and then press enter
  21. BTHID bthid(&Btd, PAIR, "0000");
  22. // After that you can simply create the instance like so and then press any button on the device
  23. //BTHID hid(&Btd);
  24. KbdRptParser keyboardPrs;
  25. MouseRptParser mousePrs;
  26. void 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. bthid.SetReportParser(KEYBOARD_PARSER_ID, (HIDReportParser*)&keyboardPrs);
  36. bthid.SetReportParser(MOUSE_PARSER_ID, (HIDReportParser*)&mousePrs);
  37. // If "Boot Protocol Mode" does not work, then try "Report Protocol Mode"
  38. // If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report
  39. bthid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode
  40. //bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode
  41. Serial.print(F("\r\nHID Bluetooth Library Started"));
  42. }
  43. void loop() {
  44. Usb.Task();
  45. }