2013-04-03 19:56:36 +02:00
|
|
|
#include <hidboot.h>
|
2013-10-02 00:49:46 +02:00
|
|
|
#include <usbhub.h>
|
2013-12-05 03:56:06 +01:00
|
|
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
|
|
|
#ifdef dobogusinclude
|
|
|
|
#include <spi4teensy3.h>
|
|
|
|
#endif
|
2013-04-03 19:56:36 +02:00
|
|
|
|
|
|
|
class KbdRptParser : public KeyboardReportParser
|
|
|
|
{
|
|
|
|
void PrintKey(uint8_t mod, uint8_t key);
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2013-04-03 19:56:36 +02:00
|
|
|
protected:
|
2013-05-16 20:45:26 +02:00
|
|
|
virtual void OnControlKeysChanged(uint8_t before, uint8_t after);
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2013-04-03 19:56:36 +02:00
|
|
|
virtual void OnKeyDown (uint8_t mod, uint8_t key);
|
|
|
|
virtual void OnKeyUp (uint8_t mod, uint8_t key);
|
|
|
|
virtual void OnKeyPressed(uint8_t key);
|
|
|
|
};
|
|
|
|
|
2013-06-17 21:37:09 +02:00
|
|
|
void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
|
2013-04-03 19:56:36 +02:00
|
|
|
{
|
|
|
|
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" : " ");
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2013-04-03 19:56:36 +02:00
|
|
|
Serial.print(" >");
|
2013-08-14 22:08:37 +02:00
|
|
|
PrintHex<uint8_t>(key, 0x80);
|
2013-04-03 19:56:36 +02:00
|
|
|
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" : " ");
|
|
|
|
};
|
|
|
|
|
2013-06-17 21:37:09 +02:00
|
|
|
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
|
2013-04-03 19:56:36 +02:00
|
|
|
{
|
|
|
|
Serial.print("DN ");
|
|
|
|
PrintKey(mod, key);
|
|
|
|
uint8_t c = OemToAscii(mod, key);
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2013-04-03 19:56:36 +02:00
|
|
|
if (c)
|
|
|
|
OnKeyPressed(c);
|
|
|
|
}
|
|
|
|
|
2013-05-16 20:45:26 +02:00
|
|
|
void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {
|
|
|
|
|
|
|
|
MODIFIERKEYS beforeMod;
|
|
|
|
*((uint8_t*)&beforeMod) = before;
|
|
|
|
|
|
|
|
MODIFIERKEYS afterMod;
|
|
|
|
*((uint8_t*)&afterMod) = after;
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2013-05-16 20:45:26 +02:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-17 21:37:09 +02:00
|
|
|
void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
|
2013-04-03 19:56:36 +02:00
|
|
|
{
|
|
|
|
Serial.print("UP ");
|
|
|
|
PrintKey(mod, key);
|
|
|
|
}
|
|
|
|
|
2013-06-17 21:37:09 +02:00
|
|
|
void KbdRptParser::OnKeyPressed(uint8_t key)
|
2013-04-03 19:56:36 +02:00
|
|
|
{
|
|
|
|
Serial.print("ASCII: ");
|
|
|
|
Serial.println((char)key);
|
|
|
|
};
|
|
|
|
|
|
|
|
USB Usb;
|
|
|
|
//USBHub Hub(&Usb);
|
2013-04-30 22:06:36 +02:00
|
|
|
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
|
2013-04-03 19:56:36 +02:00
|
|
|
|
|
|
|
uint32_t next_time;
|
|
|
|
|
|
|
|
KbdRptParser Prs;
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin( 115200 );
|
2013-10-21 19:58:03 +02:00
|
|
|
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
2013-04-03 19:56:36 +02:00
|
|
|
Serial.println("Start");
|
|
|
|
|
|
|
|
if (Usb.Init() == -1)
|
|
|
|
Serial.println("OSC did not start.");
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2013-04-03 19:56:36 +02:00
|
|
|
delay( 200 );
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2013-04-03 19:56:36 +02:00
|
|
|
next_time = millis() + 5000;
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2013-04-30 22:06:36 +02:00
|
|
|
HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs);
|
2013-04-03 19:56:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
Usb.Task();
|
|
|
|
}
|
|
|
|
|