2013-04-03 19:56:36 +02:00
|
|
|
#include <hidboot.h>
|
2013-10-02 00:49:46 +02:00
|
|
|
#include <usbhub.h>
|
2014-08-03 00:57:37 +02:00
|
|
|
|
2015-03-03 19:08:39 +01:00
|
|
|
// Satisfy the IDE, which needs to see the include statment in the ino too.
|
|
|
|
#ifdef dobogusinclude
|
2013-12-05 03:56:06 +01:00
|
|
|
#include <spi4teensy3.h>
|
|
|
|
#endif
|
2017-08-14 09:39:38 +02:00
|
|
|
#include <SPI.h>
|
2013-04-03 19:56:36 +02:00
|
|
|
|
|
|
|
class KbdRptParser : public KeyboardReportParser
|
|
|
|
{
|
2015-02-22 18:27:30 +01:00
|
|
|
void PrintKey(uint8_t mod, uint8_t key);
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2015-02-22 18:27:30 +01:00
|
|
|
protected:
|
|
|
|
void OnControlKeysChanged(uint8_t before, uint8_t after);
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2015-02-22 18:27:30 +01:00
|
|
|
void OnKeyDown (uint8_t mod, uint8_t key);
|
|
|
|
void OnKeyUp (uint8_t mod, uint8_t key);
|
|
|
|
void OnKeyPressed(uint8_t key);
|
2013-04-03 19:56:36 +02:00
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2015-02-22 18:27:30 +01: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" : " ");
|
|
|
|
|
|
|
|
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" : " ");
|
2013-04-03 19:56:36 +02:00
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2015-02-22 18:27:30 +01:00
|
|
|
Serial.print("DN ");
|
|
|
|
PrintKey(mod, key);
|
|
|
|
uint8_t c = OemToAscii(mod, key);
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2015-02-22 18:27:30 +01:00
|
|
|
if (c)
|
|
|
|
OnKeyPressed(c);
|
2013-04-03 19:56:36 +02:00
|
|
|
}
|
|
|
|
|
2013-05-16 20:45:26 +02:00
|
|
|
void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {
|
|
|
|
|
2015-02-22 18:27:30 +01:00
|
|
|
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");
|
|
|
|
}
|
2013-05-16 20:45:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-02-22 18:27:30 +01:00
|
|
|
Serial.print("UP ");
|
|
|
|
PrintKey(mod, key);
|
2013-04-03 19:56:36 +02:00
|
|
|
}
|
|
|
|
|
2013-06-17 21:37:09 +02:00
|
|
|
void KbdRptParser::OnKeyPressed(uint8_t key)
|
2013-04-03 19:56:36 +02:00
|
|
|
{
|
2015-02-22 18:27:30 +01:00
|
|
|
Serial.print("ASCII: ");
|
|
|
|
Serial.println((char)key);
|
2013-04-03 19:56:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
USB Usb;
|
|
|
|
//USBHub Hub(&Usb);
|
2016-01-16 20:01:11 +01:00
|
|
|
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
|
2013-04-03 19:56:36 +02:00
|
|
|
|
|
|
|
KbdRptParser Prs;
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2015-02-22 18:27:30 +01:00
|
|
|
Serial.begin( 115200 );
|
2014-11-10 07:35:13 +01:00
|
|
|
#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
|
2015-02-22 18:27:30 +01:00
|
|
|
Serial.println("Start");
|
2013-04-03 19:56:36 +02:00
|
|
|
|
2015-02-22 18:27:30 +01:00
|
|
|
if (Usb.Init() == -1)
|
|
|
|
Serial.println("OSC did not start.");
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2015-02-22 18:27:30 +01:00
|
|
|
delay( 200 );
|
2013-06-17 21:37:09 +02:00
|
|
|
|
2016-01-20 14:59:16 +01:00
|
|
|
HidKeyboard.SetReportParser(0, &Prs);
|
2013-04-03 19:56:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2015-02-22 18:27:30 +01:00
|
|
|
Usb.Task();
|
2013-04-03 19:56:36 +02:00
|
|
|
}
|
|
|
|
|