mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Add example for composite mouse/keyboard, also supports single units on a hub, or embedded hub.
This commit is contained in:
parent
2432379a27
commit
5656fa9b6d
5 changed files with 336 additions and 0 deletions
30
examples/HID/USBHIDBootKbdAndMouse/Makefile
Normal file
30
examples/HID/USBHIDBootKbdAndMouse/Makefile
Normal file
|
@ -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
|
170
examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino
Normal file
170
examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
#include <usbhub.h>
|
||||||
|
#include <hidboot.h>
|
||||||
|
|
||||||
|
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<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" : " ");
|
||||||
|
};
|
||||||
|
|
||||||
|
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<HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE> HidComposite(&Usb);
|
||||||
|
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
|
||||||
|
HIDBoot<HID_PROTOCOL_MOUSE> 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();
|
||||||
|
}
|
||||||
|
|
|
@ -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}
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configurationDescriptor version="80">
|
||||||
|
<logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT">
|
||||||
|
<df name="USBHIDBootKbd" root=".">
|
||||||
|
<df name="build">
|
||||||
|
<in>USBHIDBootKbdAndMouse_ino.cpp</in>
|
||||||
|
</df>
|
||||||
|
<in>USBHIDBootKbdAndMouse.ino</in>
|
||||||
|
</df>
|
||||||
|
<logicalFolder name="ExternalFiles"
|
||||||
|
displayName="Important Files"
|
||||||
|
projectFiles="false"
|
||||||
|
kind="IMPORTANT_FILES_FOLDER">
|
||||||
|
<itemPath>Makefile</itemPath>
|
||||||
|
</logicalFolder>
|
||||||
|
</logicalFolder>
|
||||||
|
<sourceFolderFilter>^(nbproject)$</sourceFolderFilter>
|
||||||
|
<sourceRootList>
|
||||||
|
<Elem>.</Elem>
|
||||||
|
</sourceRootList>
|
||||||
|
<projectmakefile>Makefile</projectmakefile>
|
||||||
|
<confs>
|
||||||
|
<conf name="Default" type="0">
|
||||||
|
<toolsSet>
|
||||||
|
<remote-sources-mode>LOCAL_SOURCES</remote-sources-mode>
|
||||||
|
<compilerSet>default</compilerSet>
|
||||||
|
</toolsSet>
|
||||||
|
<makefileType>
|
||||||
|
<makeTool>
|
||||||
|
<buildCommandWorkingDir>.</buildCommandWorkingDir>
|
||||||
|
<buildCommand>${MAKE} -f Makefile</buildCommand>
|
||||||
|
<cleanCommand>${MAKE} -f Makefile clean</cleanCommand>
|
||||||
|
<executablePath></executablePath>
|
||||||
|
</makeTool>
|
||||||
|
</makefileType>
|
||||||
|
</conf>
|
||||||
|
</confs>
|
||||||
|
</configurationDescriptor>
|
23
examples/HID/USBHIDBootKbdAndMouse/nbproject/project.xml
Normal file
23
examples/HID/USBHIDBootKbdAndMouse/nbproject/project.xml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||||
|
<type>org.netbeans.modules.cnd.makeproject</type>
|
||||||
|
<configuration>
|
||||||
|
<data xmlns="http://www.netbeans.org/ns/make-project/1">
|
||||||
|
<name>USBHIDBootKbdAndMouse</name>
|
||||||
|
<c-extensions/>
|
||||||
|
<cpp-extensions>cpp,ino</cpp-extensions>
|
||||||
|
<header-extensions/>
|
||||||
|
<sourceEncoding>UTF-8</sourceEncoding>
|
||||||
|
<make-dep-projects/>
|
||||||
|
<sourceRootList>
|
||||||
|
<sourceRootElem>.</sourceRootElem>
|
||||||
|
</sourceRootList>
|
||||||
|
<confList>
|
||||||
|
<confElem>
|
||||||
|
<name>Default</name>
|
||||||
|
<type>0</type>
|
||||||
|
</confElem>
|
||||||
|
</confList>
|
||||||
|
</data>
|
||||||
|
</configuration>
|
||||||
|
</project>
|
Loading…
Reference in a new issue