summaryrefslogtreecommitdiff
path: root/protocol/usb_hid/USB_Host_Shield_2.0/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino
diff options
context:
space:
mode:
Diffstat (limited to 'protocol/usb_hid/USB_Host_Shield_2.0/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino')
m---------protocol/usb_hid/USB_Host_Shield_2.00
-rw-r--r--protocol/usb_hid/USB_Host_Shield_2.0/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino129
2 files changed, 129 insertions, 0 deletions
diff --git a/protocol/usb_hid/USB_Host_Shield_2.0 b/protocol/usb_hid/USB_Host_Shield_2.0
deleted file mode 160000
-Subproject 7c2e6c1bcdcc22cfdbd82edd9d8fc4c4276ead4
diff --git a/protocol/usb_hid/USB_Host_Shield_2.0/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino b/protocol/usb_hid/USB_Host_Shield_2.0/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino
new file mode 100644
index 0000000000..48b33abfd2
--- /dev/null
+++ b/protocol/usb_hid/USB_Host_Shield_2.0/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino
@@ -0,0 +1,129 @@
+#include <hidboot.h>
+#include <usbhub.h>
+
+// Satisfy the IDE, which needs to see the include statment in the ino too.
+#ifdef dobogusinclude
+#include <spi4teensy3.h>
+#include <SPI.h>
+#endif
+
+class KbdRptParser : public KeyboardReportParser
+{
+ void PrintKey(uint8_t mod, uint8_t key);
+
+ protected:
+ void OnControlKeysChanged(uint8_t before, uint8_t after);
+
+ void OnKeyDown (uint8_t mod, uint8_t key);
+ void OnKeyUp (uint8_t mod, uint8_t key);
+ void OnKeyPressed(uint8_t key);
+};
+
+void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
+{
+ MODIFIERKEYS mod;
+ *((uint8_t*)&mod) = m;
+ Serial.print((mod.bmLeftCtrl == 1) ? "C" : " ");
+ Serial.print((mod.bmLeftShift == 1) ? "S" : " ");
+ Serial.print((mod.bmLeftAlt == 1) ? "A" : " ");
+ Serial.print((mod.bmLeftGUI == 1) ? "G" : " ");
+
+ Serial.print(" >");
+ PrintHex<uint8_t>(key, 0x80);
+ Serial.print("< ");
+
+ Serial.print((mod.bmRightCtrl == 1) ? "C" : " ");
+ Serial.print((mod.bmRightShift == 1) ? "S" : " ");
+ Serial.print((mod.bmRightAlt == 1) ? "A" : " ");
+ Serial.println((mod.bmRightGUI == 1) ? "G" : " ");
+};
+
+void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
+{
+ Serial.print("DN ");
+ PrintKey(mod, key);
+ uint8_t c = OemToAscii(mod, key);
+
+ if (c)
+ OnKeyPressed(c);
+}
+
+void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {
+
+ MODIFIERKEYS beforeMod;
+ *((uint8_t*)&beforeMod) = before;
+
+ MODIFIERKEYS afterMod;
+ *((uint8_t*)&afterMod) = after;
+
+ if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) {
+ Serial.println("LeftCtrl changed");
+ }
+ if (beforeMod.bmLeftShift != afterMod.bmLeftShift) {
+ Serial.println("LeftShift changed");
+ }
+ if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) {
+ Serial.println("LeftAlt changed");
+ }
+ if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) {
+ Serial.println("LeftGUI changed");
+ }
+
+ if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) {
+ Serial.println("RightCtrl changed");
+ }
+ if (beforeMod.bmRightShift != afterMod.bmRightShift) {
+ Serial.println("RightShift changed");
+ }
+ if (beforeMod.bmRightAlt != afterMod.bmRightAlt) {
+ Serial.println("RightAlt changed");
+ }
+ if (beforeMod.bmRightGUI != afterMod.bmRightGUI) {
+ Serial.println("RightGUI changed");
+ }
+
+}
+
+void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
+{
+ Serial.print("UP ");
+ PrintKey(mod, key);
+}
+
+void KbdRptParser::OnKeyPressed(uint8_t key)
+{
+ Serial.print("ASCII: ");
+ Serial.println((char)key);
+};
+
+USB Usb;
+//USBHub Hub(&Usb);
+HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
+
+uint32_t next_time;
+
+KbdRptParser Prs;
+
+void setup()
+{
+ Serial.begin( 115200 );
+#if !defined(__MIPSEL__)
+ while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
+#endif
+ Serial.println("Start");
+
+ if (Usb.Init() == -1)
+ Serial.println("OSC did not start.");
+
+ delay( 200 );
+
+ next_time = millis() + 5000;
+
+ HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs);
+}
+
+void loop()
+{
+ Usb.Task();
+}
+