You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

USBHID_desc.ino 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <hid.h>
  2. #include <hiduniversal.h>
  3. #include <hidescriptorparser.h>
  4. #include <usbhub.h>
  5. #include "pgmstrings.h"
  6. // Satisfy the IDE, which needs to see the include statment in the ino too.
  7. #ifdef dobogusinclude
  8. #include <spi4teensy3.h>
  9. #include <SPI.h>
  10. #endif
  11. class HIDUniversal2 : public HIDUniversal
  12. {
  13. public:
  14. HIDUniversal2(USB *usb) : HIDUniversal(usb) {};
  15. protected:
  16. uint8_t OnInitSuccessful();
  17. };
  18. uint8_t HIDUniversal2::OnInitSuccessful()
  19. {
  20. uint8_t rcode;
  21. HexDumper<USBReadParser, uint16_t, uint16_t> Hex;
  22. ReportDescParser Rpt;
  23. if ((rcode = GetReportDescr(0, &Hex)))
  24. goto FailGetReportDescr1;
  25. if ((rcode = GetReportDescr(0, &Rpt)))
  26. goto FailGetReportDescr2;
  27. return 0;
  28. FailGetReportDescr1:
  29. USBTRACE("GetReportDescr1:");
  30. goto Fail;
  31. FailGetReportDescr2:
  32. USBTRACE("GetReportDescr2:");
  33. goto Fail;
  34. Fail:
  35. Serial.println(rcode, HEX);
  36. Release();
  37. return rcode;
  38. }
  39. USB Usb;
  40. //USBHub Hub(&Usb);
  41. HIDUniversal2 Hid(&Usb);
  42. UniversalReportParser Uni;
  43. void setup()
  44. {
  45. Serial.begin( 115200 );
  46. #if !defined(__MIPSEL__)
  47. while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  48. #endif
  49. Serial.println("Start");
  50. if (Usb.Init() == -1)
  51. Serial.println("OSC did not start.");
  52. delay( 200 );
  53. if (!Hid.SetReportParser(0, &Uni))
  54. ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
  55. }
  56. void loop()
  57. {
  58. Usb.Task();
  59. }