tobeedelafuente

arduino-usb-host-barcode-scanner

Dec 18th, 2017
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <usbhid.h>
  2. #include <hiduniversal.h>
  3. #include <Usb.h>
  4. #include <usbhub.h>
  5. #include <hidboot.h>
  6. USB Usb;
  7. USBHub Hub(&Usb);
  8. HIDUniversal Hid(&Usb);
  9.  
  10. class KbdRptParser : public KeyboardReportParser {
  11.     void PrintKey(uint8_t mod, uint8_t key);
  12.   protected:
  13.     virtual void OnKeyDown  (uint8_t mod, uint8_t key);
  14.     virtual void OnKeyPressed(uint8_t key);
  15. };
  16.  
  17. void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
  18. {
  19.   uint8_t c = OemToAscii(mod, key);
  20.  
  21.   if (c)
  22.     OnKeyPressed(c);
  23. }
  24.  
  25. void KbdRptParser::OnKeyPressed(uint8_t key)
  26. {
  27.   Serial.print((char) key );
  28. };
  29.  
  30. KbdRptParser Prs;
  31.  
  32. void setup()
  33. {
  34.   Serial.begin( 115200 );
  35.   Serial.println("Start");
  36.  
  37.   if (Usb.Init() == -1) {
  38.     Serial.println("OSC did not start.");
  39.   }
  40.  
  41.   delay( 200 );
  42.  
  43.   Hid.SetReportParser(0, (HIDReportParser*)&Prs);
  44. }
  45.  
  46. void loop()
  47. {
  48.   Usb.Task();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment