diff --git a/examples/HID/USBHIDBootKbdAndMouse/Makefile b/examples/HID/USBHIDBootKbdAndMouse/Makefile new file mode 100644 index 00000000..253ecfb5 --- /dev/null +++ b/examples/HID/USBHIDBootKbdAndMouse/Makefile @@ -0,0 +1,30 @@ +# +# These are set for a mega 1280 + quadram plus my serial patch. +# If you lack quadram, or want to disable LFN, just change _FS_TINY=1 _USE_LFN=0 +# +# If your board is a mega 2560 uncomment the following two lines +# BOARD = mega2560 +# PROGRAMMER = wiring +# ...and then comment out the following two lines +BOARD = mega +PROGRAMMER = arduino + +# set your Arduino tty port here +PORT = /dev/ttyUSB0 + + +# uncomment the next line to enable debugging +#EXTRA_FLAGS += -D DEBUG_USB_HOST=1 + +# +# Advanced debug on Serial3 +# + +# uncomment the next line to enable debug on Serial3 +#EXTRA_FLAGS += -D USB_HOST_SERIAL=Serial3 + +# The following are the libraries used. +LIB_DIRS = +LIB_DIRS += ../libraries/USB_Host_Shield_2_0 +# And finally, the part that brings everything together for you. +include ../Arduino_Makefile_master/_Makefile.master diff --git a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino new file mode 100644 index 00000000..586d4132 --- /dev/null +++ b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino @@ -0,0 +1,170 @@ +#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); +}; +void MouseRptParser::OnMouseMove(MOUSEINFO *mi) +{ + Serial.print("dx="); + Serial.print(mi->dX, DEC); + Serial.print(" dy="); + Serial.println(mi->dY, DEC); +}; +void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi) +{ + Serial.println("L Butt Up"); +}; +void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi) +{ + Serial.println("L Butt Dn"); +}; +void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi) +{ + Serial.println("R Butt Up"); +}; +void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi) +{ + Serial.println("R Butt Dn"); +}; +void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi) +{ + Serial.println("M Butt Up"); +}; +void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi) +{ + Serial.println("M Butt Dn"); +}; + +class KbdRptParser : public KeyboardReportParser +{ + void PrintKey(uint8_t mod, uint8_t key); + +protected: + virtual void OnControlKeysChanged(uint8_t before, uint8_t after); + + 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; + *((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(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 HidComposite(&Usb); +HIDBoot HidKeyboard(&Usb); +HIDBoot HidMouse(&Usb); + +//uint32_t next_time; + +KbdRptParser KbdPrs; +MouseRptParser MousePrs; + +void setup() +{ + Serial.begin( 115200 ); + Serial.println("Start"); + + if (Usb.Init() == -1) + Serial.println("OSC did not start."); + + delay( 200 ); + + //next_time = millis() + 5000; + + HidComposite.SetReportParser(0, (HIDReportParser*)&KbdPrs); + HidComposite.SetReportParser(1,(HIDReportParser*)&MousePrs); + HidKeyboard.SetReportParser(0, (HIDReportParser*)&KbdPrs); + HidMouse.SetReportParser(0,(HIDReportParser*)&MousePrs); +} + +void loop() +{ + Usb.Task(); +} + diff --git a/examples/HID/USBHIDBootKbdAndMouse/nbproject/Package-Default.bash b/examples/HID/USBHIDBootKbdAndMouse/nbproject/Package-Default.bash new file mode 100644 index 00000000..808a7e12 --- /dev/null +++ b/examples/HID/USBHIDBootKbdAndMouse/nbproject/Package-Default.bash @@ -0,0 +1,75 @@ +#!/bin/bash -x + +# +# Generated - do not edit! +# + +# Macros +TOP=`pwd` +CND_PLATFORM=AVR-Linux-x86 +CND_CONF=Default +CND_DISTDIR=dist +CND_BUILDDIR=build +NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging +TMPDIRNAME=tmp-packaging +OUTPUT_PATH=MissingOutputInProject +OUTPUT_BASENAME=MissingOutputInProject +PACKAGE_TOP_DIR=USBHIDBootKbdAndMouse/ + +# Functions +function checkReturnCode +{ + rc=$? + if [ $rc != 0 ] + then + exit $rc + fi +} +function makeDirectory +# $1 directory path +# $2 permission (optional) +{ + mkdir -p "$1" + checkReturnCode + if [ "$2" != "" ] + then + chmod $2 "$1" + checkReturnCode + fi +} +function copyFileToTmpDir +# $1 from-file path +# $2 to-file path +# $3 permission +{ + cp "$1" "$2" + checkReturnCode + if [ "$3" != "" ] + then + chmod $3 "$2" + checkReturnCode + fi +} + +# Setup +cd "${TOP}" +mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package +rm -rf ${NBTMPDIR} +mkdir -p ${NBTMPDIR} + +# Copy files and create directories and links +cd "${TOP}" +makeDirectory "${NBTMPDIR}/USBHIDBootKbdAndMouse" +copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 + + +# Generate tar file +cd "${TOP}" +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/USBHIDBootKbdAndMouse.tar +cd ${NBTMPDIR} +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/USBHIDBootKbdAndMouse.tar * +checkReturnCode + +# Cleanup +cd "${TOP}" +rm -rf ${NBTMPDIR} diff --git a/examples/HID/USBHIDBootKbdAndMouse/nbproject/configurations.xml b/examples/HID/USBHIDBootKbdAndMouse/nbproject/configurations.xml new file mode 100644 index 00000000..e19c68a4 --- /dev/null +++ b/examples/HID/USBHIDBootKbdAndMouse/nbproject/configurations.xml @@ -0,0 +1,38 @@ + + + + + + USBHIDBootKbdAndMouse_ino.cpp + + USBHIDBootKbdAndMouse.ino + + + Makefile + + + ^(nbproject)$ + + . + + Makefile + + + + LOCAL_SOURCES + default + + + + . + ${MAKE} -f Makefile + ${MAKE} -f Makefile clean + + + + + + diff --git a/examples/HID/USBHIDBootKbdAndMouse/nbproject/project.xml b/examples/HID/USBHIDBootKbdAndMouse/nbproject/project.xml new file mode 100644 index 00000000..c831722a --- /dev/null +++ b/examples/HID/USBHIDBootKbdAndMouse/nbproject/project.xml @@ -0,0 +1,23 @@ + + + org.netbeans.modules.cnd.makeproject + + + USBHIDBootKbdAndMouse + + cpp,ino + + UTF-8 + + + . + + + + Default + 0 + + + + +