4 // Satisfy IDE, which only needs to see the include statment in the ino.
6 #include <spi4teensy3.h>
10 class MouseRptParser : public MouseReportParser
13 void OnMouseMove(MOUSEINFO *mi);
14 void OnLeftButtonUp(MOUSEINFO *mi);
15 void OnLeftButtonDown(MOUSEINFO *mi);
16 void OnRightButtonUp(MOUSEINFO *mi);
17 void OnRightButtonDown(MOUSEINFO *mi);
18 void OnMiddleButtonUp(MOUSEINFO *mi);
19 void OnMiddleButtonDown(MOUSEINFO *mi);
21 void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
24 Serial.print(mi->dX, DEC);
26 Serial.println(mi->dY, DEC);
28 void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
30 Serial.println("L Butt Up");
32 void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
34 Serial.println("L Butt Dn");
36 void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
38 Serial.println("R Butt Up");
40 void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
42 Serial.println("R Butt Dn");
44 void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi)
46 Serial.println("M Butt Up");
48 void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
50 Serial.println("M Butt Dn");
53 class KbdRptParser : public KeyboardReportParser
55 void PrintKey(uint8_t mod, uint8_t key);
58 void OnControlKeysChanged(uint8_t before, uint8_t after);
59 void OnKeyDown (uint8_t mod, uint8_t key);
60 void OnKeyUp (uint8_t mod, uint8_t key);
61 void OnKeyPressed(uint8_t key);
64 void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
67 *((uint8_t*)&mod) = m;
68 Serial.print((mod.bmLeftCtrl == 1) ? "C" : " ");
69 Serial.print((mod.bmLeftShift == 1) ? "S" : " ");
70 Serial.print((mod.bmLeftAlt == 1) ? "A" : " ");
71 Serial.print((mod.bmLeftGUI == 1) ? "G" : " ");
74 PrintHex<uint8_t>(key, 0x80);
77 Serial.print((mod.bmRightCtrl == 1) ? "C" : " ");
78 Serial.print((mod.bmRightShift == 1) ? "S" : " ");
79 Serial.print((mod.bmRightAlt == 1) ? "A" : " ");
80 Serial.println((mod.bmRightGUI == 1) ? "G" : " ");
83 void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
87 uint8_t c = OemToAscii(mod, key);
93 void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {
95 MODIFIERKEYS beforeMod;
96 *((uint8_t*)&beforeMod) = before;
98 MODIFIERKEYS afterMod;
99 *((uint8_t*)&afterMod) = after;
101 if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) {
102 Serial.println("LeftCtrl changed");
104 if (beforeMod.bmLeftShift != afterMod.bmLeftShift) {
105 Serial.println("LeftShift changed");
107 if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) {
108 Serial.println("LeftAlt changed");
110 if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) {
111 Serial.println("LeftGUI changed");
114 if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) {
115 Serial.println("RightCtrl changed");
117 if (beforeMod.bmRightShift != afterMod.bmRightShift) {
118 Serial.println("RightShift changed");
120 if (beforeMod.bmRightAlt != afterMod.bmRightAlt) {
121 Serial.println("RightAlt changed");
123 if (beforeMod.bmRightGUI != afterMod.bmRightGUI) {
124 Serial.println("RightGUI changed");
129 void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
135 void KbdRptParser::OnKeyPressed(uint8_t key)
137 Serial.print("ASCII: ");
138 Serial.println((char)key);
144 HIDBoot < HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE > HidComposite(&Usb);
145 HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
146 HIDBoot<HID_PROTOCOL_MOUSE> HidMouse(&Usb);
148 //uint32_t next_time;
151 MouseRptParser MousePrs;
155 Serial.begin( 115200 );
156 #if !defined(__MIPSEL__)
157 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
159 Serial.println("Start");
161 if (Usb.Init() == -1)
162 Serial.println("OSC did not start.");
166 //next_time = millis() + 5000;
168 HidComposite.SetReportParser(0, (HIDReportParser*)&KbdPrs);
169 HidComposite.SetReportParser(1, (HIDReportParser*)&MousePrs);
170 HidKeyboard.SetReportParser(0, (HIDReportParser*)&KbdPrs);
171 HidMouse.SetReportParser(0, (HIDReportParser*)&MousePrs);