From 00f8cdb931b95bc17da1ba9a11ce2eed56e757de Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 30 Jun 2012 02:04:52 +0200 Subject: [PATCH] Updated USBHost HID examples --- .../KeyboardControllerHID.ino | 69 ++++++++++--------- .../MouseControllerHID/MouseControllerHID.ino | 63 +++++++++-------- 2 files changed, 72 insertions(+), 60 deletions(-) diff --git a/hardware/arduino/sam/libraries/USBHost/examples/KeyboardControllerHID/KeyboardControllerHID.ino b/hardware/arduino/sam/libraries/USBHost/examples/KeyboardControllerHID/KeyboardControllerHID.ino index 60583671b..2d46c479e 100644 --- a/hardware/arduino/sam/libraries/USBHost/examples/KeyboardControllerHID/KeyboardControllerHID.ino +++ b/hardware/arduino/sam/libraries/USBHost/examples/KeyboardControllerHID/KeyboardControllerHID.ino @@ -1,55 +1,57 @@ -#include "variant.h" -#include #include -class KbdRptParser : public KeyboardReportParser +class KbdRptParser : +public KeyboardReportParser { - void PrintKey(uint8_t mod, uint8_t key); + void PrintKey(uint8_t mod, uint8_t key); protected: - virtual void OnKeyDown (uint8_t mod, uint8_t key); - virtual void OnKeyUp (uint8_t mod, uint8_t key); - virtual void OnKeyPressed(uint8_t key); + virtual void OnKeyDown(uint8_t mod, uint8_t key); + virtual void OnKeyUp(uint8_t mod, uint8_t key); + virtual void OnKeyPressed(uint8_t key); }; void KbdRptParser::PrintKey(uint8_t m, uint8_t key) { - MODIFIERKEYS mod; + MODIFIERKEYS mod; - *((uint8_t*)&mod) = m; - printf((mod.bmLeftCtrl == 1) ? "C" : " "); - printf((mod.bmLeftShift == 1) ? "S" : " "); - printf((mod.bmLeftAlt == 1) ? "A" : " "); - printf((mod.bmLeftGUI == 1) ? "G" : " "); + *((uint8_t*)&mod) = m; + Serial1.print((mod.bmLeftCtrl == 1) ? "C" : " "); + Serial1.print((mod.bmLeftShift == 1) ? "S" : " "); + Serial1.print((mod.bmLeftAlt == 1) ? "A" : " "); + Serial1.print((mod.bmLeftGUI == 1) ? "G" : " "); - printf("<%c>", key); + Serial1.print("<"); + Serial1.print(key); + Serial1.print(">"); - printf((mod.bmRightCtrl == 1) ? "C" : " "); - printf((mod.bmRightShift == 1) ? "S" : " "); - printf((mod.bmRightAlt == 1) ? "A" : " "); - printf((mod.bmRightGUI == 1) ? "G" : " "); -}; + Serial1.print((mod.bmRightCtrl == 1) ? "C" : " "); + Serial1.print((mod.bmRightShift == 1) ? "S" : " "); + Serial1.print((mod.bmRightAlt == 1) ? "A" : " "); + Serial1.print((mod.bmRightGUI == 1) ? "G" : " "); +} void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) { - printf("DN "); - PrintKey(mod, key); - uint8_t c = OemToAscii(mod, key); + Serial1.print("DOWN "); + PrintKey(mod, key); + uint8_t c = OemToAscii(mod, key); - if (c) - OnKeyPressed(c); + if (c) + OnKeyPressed(c); } void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key) { - printf("UP "); - PrintKey(mod, key); + Serial1.print("UP "); + PrintKey(mod, key); } void KbdRptParser::OnKeyPressed(uint8_t key) { - printf("ASCII: %c", key); -}; + Serial1.print("ASCII: "); + Serial1.println(key); +} USBHost Usb; HIDBoot Kbd(&Usb); @@ -57,14 +59,15 @@ KbdRptParser Prs; void setup() { - cpu_irq_enable(); - printf("\r\nProgram started:\r\n"); - delay(200); + Serial1.begin(115200); + Serial1.println("Program started!"); + delay(200); - Kbd.SetReportParser(0, (HIDReportParser*)&Prs); + Kbd.SetReportParser(0, &Prs); } void loop() { - Usb.Task(); + Usb.Task(); } + diff --git a/hardware/arduino/sam/libraries/USBHost/examples/MouseControllerHID/MouseControllerHID.ino b/hardware/arduino/sam/libraries/USBHost/examples/MouseControllerHID/MouseControllerHID.ino index a836acfd5..4415c51fc 100644 --- a/hardware/arduino/sam/libraries/USBHost/examples/MouseControllerHID/MouseControllerHID.ino +++ b/hardware/arduino/sam/libraries/USBHost/examples/MouseControllerHID/MouseControllerHID.ino @@ -1,45 +1,54 @@ -#include "variant.h" -#include #include class MouseRptParser : public MouseReportParser { protected: - virtual void OnMouseMove (MOUSEINFO *mi); - virtual void OnLeftButtonUp (MOUSEINFO *mi); - virtual void OnLeftButtonDown (MOUSEINFO *mi); - virtual void OnRightButtonUp (MOUSEINFO *mi); - virtual void OnRightButtonDown (MOUSEINFO *mi); - virtual void OnMiddleButtonUp (MOUSEINFO *mi); - virtual void OnMiddleButtonDown (MOUSEINFO *mi); + virtual void OnMouseMove(MOUSEINFO *mi); + virtual void OnLeftButtonUp(MOUSEINFO *mi); + virtual void OnLeftButtonDown(MOUSEINFO *mi); + virtual void OnRightButtonUp(MOUSEINFO *mi); + virtual void OnRightButtonDown(MOUSEINFO *mi); + virtual void OnMiddleButtonUp(MOUSEINFO *mi); + virtual void OnMiddleButtonDown(MOUSEINFO *mi); }; + void MouseRptParser::OnMouseMove(MOUSEINFO *mi) { - printf("Pos={%d,%d}\r\n", mi->dX, mi->dY); + Serial1.print("Moving { "); + Serial1.print(mi->dX); + Serial1.print(", "); + Serial1.print(mi->dY); + Serial1.println(" }"); }; -void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi) + +void MouseRptParser::OnLeftButtonUp(MOUSEINFO *mi) { - printf("L Butt Up\r\n"); + Serial1.println("Left Button UP"); }; -void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi) + +void MouseRptParser::OnLeftButtonDown(MOUSEINFO *mi) { - printf("L Butt Dn\r\n"); + Serial1.println("Left Button DOWN"); }; -void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi) + +void MouseRptParser::OnRightButtonUp(MOUSEINFO *mi) { - printf("R Butt Up\r\n"); + Serial1.println("Right Button UP"); }; -void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi) + +void MouseRptParser::OnRightButtonDown(MOUSEINFO *mi) { - printf("R Butt Dn\r\n"); + Serial1.println("Right Button DOWN"); }; -void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi) + +void MouseRptParser::OnMiddleButtonUp(MOUSEINFO *mi) { - printf("M Butt Up\r\n"); + Serial1.println("Middle Button UP"); }; -void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi) + +void MouseRptParser::OnMiddleButtonDown(MOUSEINFO *mi) { - printf("M Butt Dn\r\n"); + Serial1.println("Middle Button DOWN"); }; USBHost Usb; @@ -48,14 +57,14 @@ MouseRptParser Prs; void setup() { - cpu_irq_enable(); - printf("\r\nProgram started:\r\n"); - delay(200); + Serial1.begin(115200); + Serial1.println("Program started:"); + delay(200); - HostMouse.SetReportParser(0,(HIDReportParser*)&Prs); + HostMouse.SetReportParser(0, &Prs); } void loop() { - Usb.Task(); + Usb.Task(); }