diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/hidapi/testgui')
16 files changed, 1228 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile-manual b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile-manual new file mode 100644 index 0000000..3f61705 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile-manual | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | |||
| 2 | |||
| 3 | OS=$(shell uname) | ||
| 4 | |||
| 5 | ifeq ($(OS), Darwin) | ||
| 6 | FILE=Makefile.mac | ||
| 7 | endif | ||
| 8 | |||
| 9 | ifneq (,$(findstring MINGW,$(OS))) | ||
| 10 | FILE=Makefile.mingw | ||
| 11 | endif | ||
| 12 | |||
| 13 | ifeq ($(OS), Linux) | ||
| 14 | FILE=Makefile.linux | ||
| 15 | endif | ||
| 16 | |||
| 17 | ifeq ($(OS), FreeBSD) | ||
| 18 | FILE=Makefile.freebsd | ||
| 19 | endif | ||
| 20 | |||
| 21 | ifeq ($(FILE), ) | ||
| 22 | all: | ||
| 23 | $(error Your platform ${OS} is not supported at this time.) | ||
| 24 | endif | ||
| 25 | |||
| 26 | include $(FILE) | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.am b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.am new file mode 100644 index 0000000..1c02f3f --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.am | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | |||
| 2 | AM_CPPFLAGS = -I$(top_srcdir)/hidapi/ $(CFLAGS_TESTGUI) | ||
| 3 | |||
| 4 | if OS_LINUX | ||
| 5 | ## Linux | ||
| 6 | bin_PROGRAMS = hidapi-hidraw-testgui hidapi-libusb-testgui | ||
| 7 | |||
| 8 | hidapi_hidraw_testgui_SOURCES = test.cpp | ||
| 9 | hidapi_hidraw_testgui_LDADD = $(top_builddir)/linux/libhidapi-hidraw.la $(LIBS_TESTGUI) | ||
| 10 | |||
| 11 | hidapi_libusb_testgui_SOURCES = test.cpp | ||
| 12 | hidapi_libusb_testgui_LDADD = $(top_builddir)/libusb/libhidapi-libusb.la $(LIBS_TESTGUI) | ||
| 13 | else | ||
| 14 | ## Other OS's | ||
| 15 | bin_PROGRAMS = hidapi-testgui | ||
| 16 | |||
| 17 | hidapi_testgui_SOURCES = test.cpp | ||
| 18 | hidapi_testgui_LDADD = $(top_builddir)/$(backend)/libhidapi.la $(LIBS_TESTGUI) | ||
| 19 | endif | ||
| 20 | |||
| 21 | if OS_DARWIN | ||
| 22 | hidapi_testgui_SOURCES = test.cpp mac_support_cocoa.m mac_support.h | ||
| 23 | # Rules for copying the binary and its dependencies into the app bundle. | ||
| 24 | TestGUI.app/Contents/MacOS/hidapi-testgui$(EXEEXT): hidapi-testgui$(EXEEXT) | ||
| 25 | $(srcdir)/copy_to_bundle.sh | ||
| 26 | |||
| 27 | all: all-am TestGUI.app/Contents/MacOS/hidapi-testgui$(EXEEXT) | ||
| 28 | |||
| 29 | endif | ||
| 30 | |||
| 31 | EXTRA_DIST = \ | ||
| 32 | copy_to_bundle.sh \ | ||
| 33 | Makefile-manual \ | ||
| 34 | Makefile.freebsd \ | ||
| 35 | Makefile.linux \ | ||
| 36 | Makefile.mac \ | ||
| 37 | Makefile.mingw \ | ||
| 38 | TestGUI.app.in \ | ||
| 39 | testgui.sln \ | ||
| 40 | testgui.vcproj | ||
| 41 | |||
| 42 | distclean-local: | ||
| 43 | rm -rf TestGUI.app | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.freebsd b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.freebsd new file mode 100644 index 0000000..09a2473 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.freebsd | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | ########################################### | ||
| 2 | # Simple Makefile for HIDAPI test program | ||
| 3 | # | ||
| 4 | # Alan Ott | ||
| 5 | # Signal 11 Software | ||
| 6 | # 2010-06-01 | ||
| 7 | ########################################### | ||
| 8 | |||
| 9 | all: testgui | ||
| 10 | |||
| 11 | CC=cc | ||
| 12 | CXX=c++ | ||
| 13 | COBJS=../libusb/hid.o | ||
| 14 | CPPOBJS=test.o | ||
| 15 | OBJS=$(COBJS) $(CPPOBJS) | ||
| 16 | CFLAGS=-I../hidapi -I/usr/local/include `fox-config --cflags` -Wall -g -c | ||
| 17 | LDFLAGS= -L/usr/local/lib | ||
| 18 | LIBS= -lusb -liconv `fox-config --libs` -pthread | ||
| 19 | |||
| 20 | |||
| 21 | testgui: $(OBJS) | ||
| 22 | $(CXX) -Wall -g $^ $(LDFLAGS) -o $@ $(LIBS) | ||
| 23 | |||
| 24 | $(COBJS): %.o: %.c | ||
| 25 | $(CC) $(CFLAGS) $< -o $@ | ||
| 26 | |||
| 27 | $(CPPOBJS): %.o: %.cpp | ||
| 28 | $(CXX) $(CFLAGS) $< -o $@ | ||
| 29 | |||
| 30 | clean: | ||
| 31 | rm *.o testgui | ||
| 32 | |||
| 33 | .PHONY: clean | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.linux b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.linux new file mode 100644 index 0000000..d32e163 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.linux | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | ########################################### | ||
| 2 | # Simple Makefile for HIDAPI test program | ||
| 3 | # | ||
| 4 | # Alan Ott | ||
| 5 | # Signal 11 Software | ||
| 6 | # 2010-06-01 | ||
| 7 | ########################################### | ||
| 8 | |||
| 9 | all: testgui | ||
| 10 | |||
| 11 | CC=gcc | ||
| 12 | CXX=g++ | ||
| 13 | COBJS=../libusb/hid.o | ||
| 14 | CPPOBJS=test.o | ||
| 15 | OBJS=$(COBJS) $(CPPOBJS) | ||
| 16 | CFLAGS=-I../hidapi -Wall -g -c `fox-config --cflags` `pkg-config libusb-1.0 --cflags` | ||
| 17 | LIBS=-ludev -lrt -lpthread `fox-config --libs` `pkg-config libusb-1.0 --libs` | ||
| 18 | |||
| 19 | |||
| 20 | testgui: $(OBJS) | ||
| 21 | g++ -Wall -g $^ $(LIBS) -o testgui | ||
| 22 | |||
| 23 | $(COBJS): %.o: %.c | ||
| 24 | $(CC) $(CFLAGS) $< -o $@ | ||
| 25 | |||
| 26 | $(CPPOBJS): %.o: %.cpp | ||
| 27 | $(CXX) $(CFLAGS) $< -o $@ | ||
| 28 | |||
| 29 | clean: | ||
| 30 | rm *.o testgui | ||
| 31 | |||
| 32 | .PHONY: clean | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.mac b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.mac new file mode 100644 index 0000000..cda7d49 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.mac | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | ########################################### | ||
| 2 | # Simple Makefile for HIDAPI test program | ||
| 3 | # | ||
| 4 | # Alan Ott | ||
| 5 | # Signal 11 Software | ||
| 6 | # 2010-07-03 | ||
| 7 | ########################################### | ||
| 8 | |||
| 9 | all: hidapi-testgui | ||
| 10 | |||
| 11 | CC=gcc | ||
| 12 | CXX=g++ | ||
| 13 | COBJS=../mac/hid.o | ||
| 14 | CPPOBJS=test.o | ||
| 15 | OBJCOBJS=mac_support_cocoa.o | ||
| 16 | OBJS=$(COBJS) $(CPPOBJS) $(OBJCOBJS) | ||
| 17 | CFLAGS=-I../hidapi -Wall -g -c `fox-config --cflags` | ||
| 18 | LDFLAGS=-L/usr/X11R6/lib | ||
| 19 | LIBS=`fox-config --libs` -framework IOKit -framework CoreFoundation -framework Cocoa | ||
| 20 | |||
| 21 | |||
| 22 | hidapi-testgui: $(OBJS) TestGUI.app | ||
| 23 | g++ -Wall -g $(OBJS) $(LIBS) $(LDFLAGS) -o hidapi-testgui | ||
| 24 | ./copy_to_bundle.sh | ||
| 25 | #cp TestGUI.app/Contents/MacOS/hidapi-testgui TestGUI.app/Contents/MacOS/tg | ||
| 26 | #cp start.sh TestGUI.app/Contents/MacOS/hidapi-testgui | ||
| 27 | |||
| 28 | $(COBJS): %.o: %.c | ||
| 29 | $(CC) $(CFLAGS) $< -o $@ | ||
| 30 | |||
| 31 | $(CPPOBJS): %.o: %.cpp | ||
| 32 | $(CXX) $(CFLAGS) $< -o $@ | ||
| 33 | |||
| 34 | $(OBJCOBJS): %.o: %.m | ||
| 35 | $(CXX) $(CFLAGS) -x objective-c++ $< -o $@ | ||
| 36 | |||
| 37 | TestGUI.app: TestGUI.app.in | ||
| 38 | rm -Rf TestGUI.app | ||
| 39 | mkdir -p TestGUI.app | ||
| 40 | cp -R TestGUI.app.in/ TestGUI.app | ||
| 41 | |||
| 42 | clean: | ||
| 43 | rm -f $(OBJS) hidapi-testgui | ||
| 44 | rm -Rf TestGUI.app | ||
| 45 | |||
| 46 | .PHONY: clean | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.mingw b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.mingw new file mode 100644 index 0000000..f76b5a0 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/Makefile.mingw | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | ########################################### | ||
| 2 | # Simple Makefile for HIDAPI test program | ||
| 3 | # | ||
| 4 | # Alan Ott | ||
| 5 | # Signal 11 Software | ||
| 6 | # 2010-06-01 | ||
| 7 | ########################################### | ||
| 8 | |||
| 9 | all: hidapi-testgui | ||
| 10 | |||
| 11 | CC=gcc | ||
| 12 | CXX=g++ | ||
| 13 | COBJS=../windows/hid.o | ||
| 14 | CPPOBJS=test.o | ||
| 15 | OBJS=$(COBJS) $(CPPOBJS) | ||
| 16 | CFLAGS=-I../hidapi -I../../hidapi-externals/fox/include -g -c | ||
| 17 | LIBS= -mwindows -L../../hidapi-externals/fox/lib -Wl,-Bstatic -lFOX-1.6 -Wl,-Bdynamic -lgdi32 -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lkernel32 | ||
| 18 | |||
| 19 | |||
| 20 | hidapi-testgui: $(OBJS) | ||
| 21 | g++ -g $^ $(LIBS) -o hidapi-testgui | ||
| 22 | |||
| 23 | $(COBJS): %.o: %.c | ||
| 24 | $(CC) $(CFLAGS) $< -o $@ | ||
| 25 | |||
| 26 | $(CPPOBJS): %.o: %.cpp | ||
| 27 | $(CXX) $(CFLAGS) $< -o $@ | ||
| 28 | |||
| 29 | clean: | ||
| 30 | rm -f *.o hidapi-testgui.exe | ||
| 31 | |||
| 32 | .PHONY: clean | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/Info.plist b/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/Info.plist new file mode 100644 index 0000000..ab473d5 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/Info.plist | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 3 | <plist version="1.0"> | ||
| 4 | <dict> | ||
| 5 | <key>CFBundleDevelopmentRegion</key> | ||
| 6 | <string>English</string> | ||
| 7 | <key>CFBundleDisplayName</key> | ||
| 8 | <string></string> | ||
| 9 | <key>CFBundleExecutable</key> | ||
| 10 | <string>hidapi-testgui</string> | ||
| 11 | <key>CFBundleIconFile</key> | ||
| 12 | <string>Signal11.icns</string> | ||
| 13 | <key>CFBundleIdentifier</key> | ||
| 14 | <string>us.signal11.hidtestgui</string> | ||
| 15 | <key>CFBundleInfoDictionaryVersion</key> | ||
| 16 | <string>6.0</string> | ||
| 17 | <key>CFBundleName</key> | ||
| 18 | <string>testgui</string> | ||
| 19 | <key>CFBundlePackageType</key> | ||
| 20 | <string>APPL</string> | ||
| 21 | <key>CFBundleSignature</key> | ||
| 22 | <string>????</string> | ||
| 23 | <key>CFBundleVersion</key> | ||
| 24 | <string>1.0</string> | ||
| 25 | <key>CSResourcesFileMapped</key> | ||
| 26 | <true/> | ||
| 27 | </dict> | ||
| 28 | </plist> | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/PkgInfo b/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/PkgInfo new file mode 100644 index 0000000..bd04210 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/PkgInfo | |||
| @@ -0,0 +1 @@ | |||
| APPL???? \ No newline at end of file | |||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/Resources/English.lproj/InfoPlist.strings b/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/Resources/English.lproj/InfoPlist.strings new file mode 100644 index 0000000..dea12de --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/Resources/English.lproj/InfoPlist.strings | |||
| Binary files differ | |||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/Resources/Signal11.icns b/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/Resources/Signal11.icns new file mode 100644 index 0000000..bb6b7bd --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/TestGUI.app.in/Contents/Resources/Signal11.icns | |||
| Binary files differ | |||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/copy_to_bundle.sh b/contrib/SDL-3.2.8/src/hidapi/testgui/copy_to_bundle.sh new file mode 100755 index 0000000..ddff64f --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/copy_to_bundle.sh | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | #### Configuration: | ||
| 4 | # The name of the executable. It is assumed | ||
| 5 | # that it is in the current working directory. | ||
| 6 | EXE_NAME=hidapi-testgui | ||
| 7 | # Path to the executable directory inside the bundle. | ||
| 8 | # This must be an absolute path, so use $PWD. | ||
| 9 | EXEPATH=$PWD/TestGUI.app/Contents/MacOS | ||
| 10 | # Libraries to explicitly bundle, even though they | ||
| 11 | # may not be in /opt/local. One per line. These | ||
| 12 | # are used with grep, so only a portion of the name | ||
| 13 | # is required. eg: libFOX, libz, etc. | ||
| 14 | LIBS_TO_BUNDLE=libFOX | ||
| 15 | |||
| 16 | |||
| 17 | function copydeps { | ||
| 18 | local file=$1 | ||
| 19 | # echo "Copying deps for $file...." | ||
| 20 | local BASE_OF_EXE=`basename $file` | ||
| 21 | |||
| 22 | # A will contain the dependencies of this library | ||
| 23 | local A=`otool -LX $file |cut -f 1 -d " "` | ||
| 24 | local i | ||
| 25 | for i in $A; do | ||
| 26 | local BASE=`basename $i` | ||
| 27 | |||
| 28 | # See if it's a lib we specifically want to bundle | ||
| 29 | local bundle_this_lib=0 | ||
| 30 | local j | ||
| 31 | for j in $LIBS_TO_BUNDLE; do | ||
| 32 | echo $i |grep -q $j | ||
| 33 | if [ $? -eq 0 ]; then | ||
| 34 | bundle_this_lib=1 | ||
| 35 | echo "bundling $i because it's in the list." | ||
| 36 | break; | ||
| 37 | fi | ||
| 38 | done | ||
| 39 | |||
| 40 | # See if it's in /opt/local. Bundle all in /opt/local | ||
| 41 | local isOptLocal=0 | ||
| 42 | echo $i |grep -q /opt/local | ||
| 43 | if [ $? -eq 0 ]; then | ||
| 44 | isOptLocal=1 | ||
| 45 | echo "bundling $i because it's in /opt/local." | ||
| 46 | fi | ||
| 47 | |||
| 48 | # Bundle the library | ||
| 49 | if [ $isOptLocal -ne 0 ] || [ $bundle_this_lib -ne 0 ]; then | ||
| 50 | |||
| 51 | # Copy the file into the bundle if it exists. | ||
| 52 | if [ -f $EXEPATH/$BASE ]; then | ||
| 53 | z=0 | ||
| 54 | else | ||
| 55 | cp $i $EXEPATH | ||
| 56 | chmod 755 $EXEPATH/$BASE | ||
| 57 | fi | ||
| 58 | |||
| 59 | |||
| 60 | # echo "$BASE_OF_EXE depends on $BASE" | ||
| 61 | |||
| 62 | # Fix the paths using install_name_tool and then | ||
| 63 | # call this function recursively for each dependency | ||
| 64 | # of this library. | ||
| 65 | if [ $BASE_OF_EXE != $BASE ]; then | ||
| 66 | |||
| 67 | # Fix the paths | ||
| 68 | install_name_tool -id @executable_path/$BASE $EXEPATH/$BASE | ||
| 69 | install_name_tool -change $i @executable_path/$BASE $EXEPATH/$BASE_OF_EXE | ||
| 70 | |||
| 71 | # Call this function (recursive) on | ||
| 72 | # on each dependency of this library. | ||
| 73 | copydeps $EXEPATH/$BASE | ||
| 74 | fi | ||
| 75 | fi | ||
| 76 | done | ||
| 77 | } | ||
| 78 | |||
| 79 | rm -f $EXEPATH/* | ||
| 80 | mkdir -p $EXEPATH | ||
| 81 | |||
| 82 | # Copy the binary into the bundle. Use ../libtool to do this if it's | ||
| 83 | # available because if $EXE_NAME was built with autotools, it will be | ||
| 84 | # necessary. If ../libtool not available, just use cp to do the copy, but | ||
| 85 | # only if $EXE_NAME is a binary. | ||
| 86 | if [ -x ../libtool ]; then | ||
| 87 | ../libtool --mode=install cp $EXE_NAME $EXEPATH | ||
| 88 | else | ||
| 89 | file -bI $EXE_NAME |grep binary | ||
| 90 | if [ $? -ne 0 ]; then | ||
| 91 | echo "There is no ../libtool and $EXE_NAME is not a binary." | ||
| 92 | echo "I'm not sure what to do." | ||
| 93 | exit 1 | ||
| 94 | else | ||
| 95 | cp $EXE_NAME $EXEPATH | ||
| 96 | fi | ||
| 97 | fi | ||
| 98 | copydeps $EXEPATH/$EXE_NAME | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/mac_support.h b/contrib/SDL-3.2.8/src/hidapi/testgui/mac_support.h new file mode 100644 index 0000000..7d9ab49 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/mac_support.h | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | /******************************* | ||
| 2 | Mac support for HID Test GUI | ||
| 3 | |||
| 4 | Alan Ott | ||
| 5 | Signal 11 Software | ||
| 6 | |||
| 7 | *******************************/ | ||
| 8 | |||
| 9 | #ifndef MAC_SUPPORT_H__ | ||
| 10 | #define MAC_SUPPORT_H__ | ||
| 11 | |||
| 12 | extern "C" { | ||
| 13 | void init_apple_message_system(); | ||
| 14 | void check_apple_events(); | ||
| 15 | } | ||
| 16 | |||
| 17 | #endif | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/mac_support_cocoa.m b/contrib/SDL-3.2.8/src/hidapi/testgui/mac_support_cocoa.m new file mode 100644 index 0000000..1b12163 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/mac_support_cocoa.m | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | /******************************* | ||
| 2 | Mac support for HID Test GUI | ||
| 3 | |||
| 4 | Alan Ott | ||
| 5 | Signal 11 Software | ||
| 6 | *******************************/ | ||
| 7 | |||
| 8 | #include <fx.h> | ||
| 9 | #import <Cocoa/Cocoa.h> | ||
| 10 | |||
| 11 | #ifndef MAC_OS_X_VERSION_10_12 | ||
| 12 | #define MAC_OS_X_VERSION_10_12 101200 | ||
| 13 | #endif | ||
| 14 | |||
| 15 | // macOS 10.12 deprecated NSAnyEventMask in favor of NSEventMaskAny | ||
| 16 | #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12 | ||
| 17 | #define NSEventMaskAny NSAnyEventMask | ||
| 18 | #endif | ||
| 19 | |||
| 20 | extern FXMainWindow *g_main_window; | ||
| 21 | |||
| 22 | |||
| 23 | @interface MyAppDelegate : NSObject<NSApplicationDelegate> | ||
| 24 | { | ||
| 25 | } | ||
| 26 | @end | ||
| 27 | |||
| 28 | @implementation MyAppDelegate | ||
| 29 | - (void) applicationWillBecomeActive:(NSNotification*)notif | ||
| 30 | { | ||
| 31 | printf("WillBecomeActive\n"); | ||
| 32 | g_main_window->show(); | ||
| 33 | |||
| 34 | } | ||
| 35 | |||
| 36 | - (void) applicationWillTerminate:(NSNotification*)notif | ||
| 37 | { | ||
| 38 | /* Doesn't get called. Not sure why */ | ||
| 39 | printf("WillTerminate\n"); | ||
| 40 | FXApp::instance()->exit(); | ||
| 41 | } | ||
| 42 | |||
| 43 | - (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender | ||
| 44 | { | ||
| 45 | /* Doesn't get called. Not sure why */ | ||
| 46 | printf("ShouldTerminate\n"); | ||
| 47 | return YES; | ||
| 48 | } | ||
| 49 | |||
| 50 | - (void) applicationWillHide:(NSNotification*)notif | ||
| 51 | { | ||
| 52 | printf("WillHide\n"); | ||
| 53 | g_main_window->hide(); | ||
| 54 | } | ||
| 55 | |||
| 56 | - (void) handleQuitEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent | ||
| 57 | { | ||
| 58 | printf("QuitEvent\n"); | ||
| 59 | FXApp::instance()->exit(); | ||
| 60 | } | ||
| 61 | |||
| 62 | @end | ||
| 63 | |||
| 64 | extern "C" { | ||
| 65 | |||
| 66 | void | ||
| 67 | init_apple_message_system() | ||
| 68 | { | ||
| 69 | static MyAppDelegate *d = [MyAppDelegate new]; | ||
| 70 | |||
| 71 | [[NSApplication sharedApplication] setDelegate:d]; | ||
| 72 | |||
| 73 | /* Register for Apple Events. */ | ||
| 74 | /* This is from | ||
| 75 | http://stackoverflow.com/questions/1768497/application-exit-event */ | ||
| 76 | NSAppleEventManager *aem = [NSAppleEventManager sharedAppleEventManager]; | ||
| 77 | [aem setEventHandler:d | ||
| 78 | andSelector:@selector(handleQuitEvent:withReplyEvent:) | ||
| 79 | forEventClass:kCoreEventClass andEventID:kAEQuitApplication]; | ||
| 80 | } | ||
| 81 | |||
| 82 | void | ||
| 83 | check_apple_events() | ||
| 84 | { | ||
| 85 | NSApplication *app = [NSApplication sharedApplication]; | ||
| 86 | |||
| 87 | NSAutoreleasePool *pool = [NSAutoreleasePool new]; | ||
| 88 | while (1) { | ||
| 89 | NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny | ||
| 90 | untilDate:nil | ||
| 91 | inMode:NSDefaultRunLoopMode | ||
| 92 | dequeue:YES]; | ||
| 93 | if (event == NULL) | ||
| 94 | break; | ||
| 95 | else { | ||
| 96 | //printf("Event happened: Type: %d\n", event->_type); | ||
| 97 | [app sendEvent: event]; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | [pool release]; | ||
| 101 | } | ||
| 102 | |||
| 103 | } /* extern "C" */ | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/test.cpp b/contrib/SDL-3.2.8/src/hidapi/testgui/test.cpp new file mode 100644 index 0000000..538db79 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/test.cpp | |||
| @@ -0,0 +1,532 @@ | |||
| 1 | /******************************************************* | ||
| 2 | Demo Program for HIDAPI | ||
| 3 | |||
| 4 | Alan Ott | ||
| 5 | Signal 11 Software | ||
| 6 | |||
| 7 | 2010-07-20 | ||
| 8 | |||
| 9 | Copyright 2010, All Rights Reserved | ||
| 10 | |||
| 11 | This contents of this file may be used by anyone | ||
| 12 | for any reason without any conditions and may be | ||
| 13 | used as a starting point for your own applications | ||
| 14 | which use HIDAPI. | ||
| 15 | ********************************************************/ | ||
| 16 | |||
| 17 | |||
| 18 | #include <fx.h> | ||
| 19 | |||
| 20 | #include "hidapi.h" | ||
| 21 | #include "mac_support.h" | ||
| 22 | #include <string.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <limits.h> | ||
| 25 | |||
| 26 | #ifdef _WIN32 | ||
| 27 | // Thanks Microsoft, but I know how to use strncpy(). | ||
| 28 | #pragma warning(disable:4996) | ||
| 29 | #endif | ||
| 30 | |||
| 31 | class MainWindow : public FXMainWindow { | ||
| 32 | FXDECLARE(MainWindow) | ||
| 33 | |||
| 34 | public: | ||
| 35 | enum { | ||
| 36 | ID_FIRST = FXMainWindow::ID_LAST, | ||
| 37 | ID_CONNECT, | ||
| 38 | ID_DISCONNECT, | ||
| 39 | ID_RESCAN, | ||
| 40 | ID_SEND_OUTPUT_REPORT, | ||
| 41 | ID_SEND_FEATURE_REPORT, | ||
| 42 | ID_GET_FEATURE_REPORT, | ||
| 43 | ID_CLEAR, | ||
| 44 | ID_TIMER, | ||
| 45 | ID_MAC_TIMER, | ||
| 46 | ID_LAST, | ||
| 47 | }; | ||
| 48 | |||
| 49 | private: | ||
| 50 | FXList *device_list; | ||
| 51 | FXButton *connect_button; | ||
| 52 | FXButton *disconnect_button; | ||
| 53 | FXButton *rescan_button; | ||
| 54 | FXButton *output_button; | ||
| 55 | FXLabel *connected_label; | ||
| 56 | FXTextField *output_text; | ||
| 57 | FXTextField *output_len; | ||
| 58 | FXButton *feature_button; | ||
| 59 | FXButton *get_feature_button; | ||
| 60 | FXTextField *feature_text; | ||
| 61 | FXTextField *feature_len; | ||
| 62 | FXTextField *get_feature_text; | ||
| 63 | FXText *input_text; | ||
| 64 | FXFont *title_font; | ||
| 65 | |||
| 66 | struct hid_device_info *devices; | ||
| 67 | hid_device *connected_device; | ||
| 68 | size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len); | ||
| 69 | int getLengthFromTextField(FXTextField *tf); | ||
| 70 | |||
| 71 | |||
| 72 | protected: | ||
| 73 | MainWindow() {}; | ||
| 74 | public: | ||
| 75 | MainWindow(FXApp *a); | ||
| 76 | ~MainWindow(); | ||
| 77 | virtual void create(); | ||
| 78 | |||
| 79 | long onConnect(FXObject *sender, FXSelector sel, void *ptr); | ||
| 80 | long onDisconnect(FXObject *sender, FXSelector sel, void *ptr); | ||
| 81 | long onRescan(FXObject *sender, FXSelector sel, void *ptr); | ||
| 82 | long onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr); | ||
| 83 | long onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr); | ||
| 84 | long onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr); | ||
| 85 | long onClear(FXObject *sender, FXSelector sel, void *ptr); | ||
| 86 | long onTimeout(FXObject *sender, FXSelector sel, void *ptr); | ||
| 87 | long onMacTimeout(FXObject *sender, FXSelector sel, void *ptr); | ||
| 88 | }; | ||
| 89 | |||
| 90 | // FOX 1.7 changes the timeouts to all be nanoseconds. | ||
| 91 | // Fox 1.6 had all timeouts as milliseconds. | ||
| 92 | #if (FOX_MINOR >= 7) | ||
| 93 | const int timeout_scalar = 1000*1000; | ||
| 94 | #else | ||
| 95 | const int timeout_scalar = 1; | ||
| 96 | #endif | ||
| 97 | |||
| 98 | FXMainWindow *g_main_window; | ||
| 99 | |||
| 100 | |||
| 101 | FXDEFMAP(MainWindow) MainWindowMap [] = { | ||
| 102 | FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CONNECT, MainWindow::onConnect ), | ||
| 103 | FXMAPFUNC(SEL_COMMAND, MainWindow::ID_DISCONNECT, MainWindow::onDisconnect ), | ||
| 104 | FXMAPFUNC(SEL_COMMAND, MainWindow::ID_RESCAN, MainWindow::onRescan ), | ||
| 105 | FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_OUTPUT_REPORT, MainWindow::onSendOutputReport ), | ||
| 106 | FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_FEATURE_REPORT, MainWindow::onSendFeatureReport ), | ||
| 107 | FXMAPFUNC(SEL_COMMAND, MainWindow::ID_GET_FEATURE_REPORT, MainWindow::onGetFeatureReport ), | ||
| 108 | FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CLEAR, MainWindow::onClear ), | ||
| 109 | FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ), | ||
| 110 | FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ), | ||
| 111 | }; | ||
| 112 | |||
| 113 | FXIMPLEMENT(MainWindow, FXMainWindow, MainWindowMap, ARRAYNUMBER(MainWindowMap)); | ||
| 114 | |||
| 115 | MainWindow::MainWindow(FXApp *app) | ||
| 116 | : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 425,700) | ||
| 117 | { | ||
| 118 | devices = NULL; | ||
| 119 | connected_device = NULL; | ||
| 120 | |||
| 121 | FXVerticalFrame *vf = new FXVerticalFrame(this, LAYOUT_FILL_Y|LAYOUT_FILL_X); | ||
| 122 | |||
| 123 | FXLabel *label = new FXLabel(vf, "HIDAPI Test Tool"); | ||
| 124 | title_font = new FXFont(getApp(), "Arial", 14, FXFont::Bold); | ||
| 125 | label->setFont(title_font); | ||
| 126 | |||
| 127 | new FXLabel(vf, | ||
| 128 | "Select a device and press Connect.", NULL, JUSTIFY_LEFT); | ||
| 129 | new FXLabel(vf, | ||
| 130 | "Output data bytes can be entered in the Output section, \n" | ||
| 131 | "separated by space, comma or brackets. Data starting with 0x\n" | ||
| 132 | "is treated as hex. Data beginning with a 0 is treated as \n" | ||
| 133 | "octal. All other data is treated as decimal.", NULL, JUSTIFY_LEFT); | ||
| 134 | new FXLabel(vf, | ||
| 135 | "Data received from the device appears in the Input section.", | ||
| 136 | NULL, JUSTIFY_LEFT); | ||
| 137 | new FXLabel(vf, | ||
| 138 | "Optionally, a report length may be specified. Extra bytes are\n" | ||
| 139 | "padded with zeros. If no length is specified, the length is \n" | ||
| 140 | "inferred from the data.", | ||
| 141 | NULL, JUSTIFY_LEFT); | ||
| 142 | new FXLabel(vf, ""); | ||
| 143 | |||
| 144 | // Device List and Connect/Disconnect buttons | ||
| 145 | FXHorizontalFrame *hf = new FXHorizontalFrame(vf, LAYOUT_FILL_X); | ||
| 146 | //device_list = new FXList(new FXHorizontalFrame(hf,FRAME_SUNKEN|FRAME_THICK, 0,0,0,0, 0,0,0,0), NULL, 0, LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT, 0,0,300,200); | ||
| 147 | device_list = new FXList(new FXHorizontalFrame(hf,FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0), NULL, 0, LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,300,200); | ||
| 148 | FXVerticalFrame *buttonVF = new FXVerticalFrame(hf); | ||
| 149 | connect_button = new FXButton(buttonVF, "Connect", NULL, this, ID_CONNECT, BUTTON_NORMAL|LAYOUT_FILL_X); | ||
| 150 | disconnect_button = new FXButton(buttonVF, "Disconnect", NULL, this, ID_DISCONNECT, BUTTON_NORMAL|LAYOUT_FILL_X); | ||
| 151 | disconnect_button->disable(); | ||
| 152 | rescan_button = new FXButton(buttonVF, "Re-Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X); | ||
| 153 | new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0); | ||
| 154 | |||
| 155 | connected_label = new FXLabel(vf, "Disconnected"); | ||
| 156 | |||
| 157 | new FXHorizontalFrame(vf); | ||
| 158 | |||
| 159 | // Output Group Box | ||
| 160 | FXGroupBox *gb = new FXGroupBox(vf, "Output", FRAME_GROOVE|LAYOUT_FILL_X); | ||
| 161 | FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X); | ||
| 162 | new FXLabel(matrix, "Data"); | ||
| 163 | new FXLabel(matrix, "Length"); | ||
| 164 | new FXLabel(matrix, ""); | ||
| 165 | |||
| 166 | //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X); | ||
| 167 | output_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); | ||
| 168 | output_text->setText("1 0x81 0"); | ||
| 169 | output_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); | ||
| 170 | output_button = new FXButton(matrix, "Send Output Report", NULL, this, ID_SEND_OUTPUT_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X); | ||
| 171 | output_button->disable(); | ||
| 172 | //new FXHorizontalFrame(matrix, LAYOUT_FILL_X); | ||
| 173 | |||
| 174 | //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X); | ||
| 175 | feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); | ||
| 176 | feature_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); | ||
| 177 | feature_button = new FXButton(matrix, "Send Feature Report", NULL, this, ID_SEND_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X); | ||
| 178 | feature_button->disable(); | ||
| 179 | |||
| 180 | get_feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); | ||
| 181 | new FXWindow(matrix); | ||
| 182 | get_feature_button = new FXButton(matrix, "Get Feature Report", NULL, this, ID_GET_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X); | ||
| 183 | get_feature_button->disable(); | ||
| 184 | |||
| 185 | |||
| 186 | // Input Group Box | ||
| 187 | gb = new FXGroupBox(vf, "Input", FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y); | ||
| 188 | FXVerticalFrame *innerVF = new FXVerticalFrame(gb, LAYOUT_FILL_X|LAYOUT_FILL_Y); | ||
| 189 | input_text = new FXText(new FXHorizontalFrame(innerVF,LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, 0,0,0,0, 0,0,0,0), NULL, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y); | ||
| 190 | input_text->setEditable(false); | ||
| 191 | new FXButton(innerVF, "Clear", NULL, this, ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT); | ||
| 192 | |||
| 193 | |||
| 194 | } | ||
| 195 | |||
| 196 | MainWindow::~MainWindow() | ||
| 197 | { | ||
| 198 | if (connected_device) | ||
| 199 | hid_close(connected_device); | ||
| 200 | hid_exit(); | ||
| 201 | delete title_font; | ||
| 202 | } | ||
| 203 | |||
| 204 | void | ||
| 205 | MainWindow::create() | ||
| 206 | { | ||
| 207 | FXMainWindow::create(); | ||
| 208 | show(); | ||
| 209 | |||
| 210 | onRescan(NULL, 0, NULL); | ||
| 211 | |||
| 212 | |||
| 213 | #ifdef __APPLE__ | ||
| 214 | init_apple_message_system(); | ||
| 215 | #endif | ||
| 216 | |||
| 217 | getApp()->addTimeout(this, ID_MAC_TIMER, | ||
| 218 | 50 * timeout_scalar /*50ms*/); | ||
| 219 | } | ||
| 220 | |||
| 221 | long | ||
| 222 | MainWindow::onConnect(FXObject *sender, FXSelector sel, void *ptr) | ||
| 223 | { | ||
| 224 | if (connected_device != NULL) | ||
| 225 | return 1; | ||
| 226 | |||
| 227 | FXint cur_item = device_list->getCurrentItem(); | ||
| 228 | if (cur_item < 0) | ||
| 229 | return -1; | ||
| 230 | FXListItem *item = device_list->getItem(cur_item); | ||
| 231 | if (!item) | ||
| 232 | return -1; | ||
| 233 | struct hid_device_info *device_info = (struct hid_device_info*) item->getData(); | ||
| 234 | if (!device_info) | ||
| 235 | return -1; | ||
| 236 | |||
| 237 | connected_device = hid_open_path(device_info->path); | ||
| 238 | |||
| 239 | if (!connected_device) { | ||
| 240 | FXMessageBox::error(this, MBOX_OK, "Device Error", "Unable To Connect to Device"); | ||
| 241 | return -1; | ||
| 242 | } | ||
| 243 | |||
| 244 | hid_set_nonblocking(connected_device, 1); | ||
| 245 | |||
| 246 | getApp()->addTimeout(this, ID_TIMER, | ||
| 247 | 5 * timeout_scalar /*5ms*/); | ||
| 248 | |||
| 249 | FXString s; | ||
| 250 | s.format("Connected to: %04hx:%04hx -", device_info->vendor_id, device_info->product_id); | ||
| 251 | s += FXString(" ") + device_info->manufacturer_string; | ||
| 252 | s += FXString(" ") + device_info->product_string; | ||
| 253 | connected_label->setText(s); | ||
| 254 | output_button->enable(); | ||
| 255 | feature_button->enable(); | ||
| 256 | get_feature_button->enable(); | ||
| 257 | connect_button->disable(); | ||
| 258 | disconnect_button->enable(); | ||
| 259 | input_text->setText(""); | ||
| 260 | |||
| 261 | |||
| 262 | return 1; | ||
| 263 | } | ||
| 264 | |||
| 265 | long | ||
| 266 | MainWindow::onDisconnect(FXObject *sender, FXSelector sel, void *ptr) | ||
| 267 | { | ||
| 268 | hid_close(connected_device); | ||
| 269 | connected_device = NULL; | ||
| 270 | connected_label->setText("Disconnected"); | ||
| 271 | output_button->disable(); | ||
| 272 | feature_button->disable(); | ||
| 273 | get_feature_button->disable(); | ||
| 274 | connect_button->enable(); | ||
| 275 | disconnect_button->disable(); | ||
| 276 | |||
| 277 | getApp()->removeTimeout(this, ID_TIMER); | ||
| 278 | |||
| 279 | return 1; | ||
| 280 | } | ||
| 281 | |||
| 282 | long | ||
| 283 | MainWindow::onRescan(FXObject *sender, FXSelector sel, void *ptr) | ||
| 284 | { | ||
| 285 | struct hid_device_info *cur_dev; | ||
| 286 | |||
| 287 | device_list->clearItems(); | ||
| 288 | |||
| 289 | // List the Devices | ||
| 290 | hid_free_enumeration(devices); | ||
| 291 | devices = hid_enumerate(0x0, 0x0); | ||
| 292 | cur_dev = devices; | ||
| 293 | while (cur_dev) { | ||
| 294 | // Add it to the List Box. | ||
| 295 | FXString s; | ||
| 296 | FXString usage_str; | ||
| 297 | s.format("%04hx:%04hx -", cur_dev->vendor_id, cur_dev->product_id); | ||
| 298 | s += FXString(" ") + cur_dev->manufacturer_string; | ||
| 299 | s += FXString(" ") + cur_dev->product_string; | ||
| 300 | usage_str.format(" (usage: %04hx:%04hx) ", cur_dev->usage_page, cur_dev->usage); | ||
| 301 | s += usage_str; | ||
| 302 | FXListItem *li = new FXListItem(s, NULL, cur_dev); | ||
| 303 | device_list->appendItem(li); | ||
| 304 | |||
| 305 | cur_dev = cur_dev->next; | ||
| 306 | } | ||
| 307 | |||
| 308 | if (device_list->getNumItems() == 0) | ||
| 309 | device_list->appendItem("*** No Devices Connected ***"); | ||
| 310 | else { | ||
| 311 | device_list->selectItem(0); | ||
| 312 | } | ||
| 313 | |||
| 314 | return 1; | ||
| 315 | } | ||
| 316 | |||
| 317 | size_t | ||
| 318 | MainWindow::getDataFromTextField(FXTextField *tf, char *buf, size_t len) | ||
| 319 | { | ||
| 320 | const char *delim = " ,{}\t\r\n"; | ||
| 321 | FXString data = tf->getText(); | ||
| 322 | const FXchar *d = data.text(); | ||
| 323 | size_t i = 0; | ||
| 324 | |||
| 325 | // Copy the string from the GUI. | ||
| 326 | size_t sz = strlen(d); | ||
| 327 | char *str = (char*) malloc(sz+1); | ||
| 328 | strcpy(str, d); | ||
| 329 | |||
| 330 | // For each token in the string, parse and store in buf[]. | ||
| 331 | char *token = strtok(str, delim); | ||
| 332 | while (token) { | ||
| 333 | char *endptr; | ||
| 334 | long int val = strtol(token, &endptr, 0); | ||
| 335 | buf[i++] = val; | ||
| 336 | token = strtok(NULL, delim); | ||
| 337 | } | ||
| 338 | |||
| 339 | free(str); | ||
| 340 | return i; | ||
| 341 | } | ||
| 342 | |||
| 343 | /* getLengthFromTextField() | ||
| 344 | Returns length: | ||
| 345 | 0: empty text field | ||
| 346 | >0: valid length | ||
| 347 | -1: invalid length */ | ||
| 348 | int | ||
| 349 | MainWindow::getLengthFromTextField(FXTextField *tf) | ||
| 350 | { | ||
| 351 | long int len; | ||
| 352 | FXString str = tf->getText(); | ||
| 353 | size_t sz = str.length(); | ||
| 354 | |||
| 355 | if (sz > 0) { | ||
| 356 | char *endptr; | ||
| 357 | len = strtol(str.text(), &endptr, 0); | ||
| 358 | if (endptr != str.text() && *endptr == '\0') { | ||
| 359 | if (len <= 0) { | ||
| 360 | FXMessageBox::error(this, MBOX_OK, "Invalid length", "Enter a length greater than zero."); | ||
| 361 | return -1; | ||
| 362 | } | ||
| 363 | return len; | ||
| 364 | } | ||
| 365 | else | ||
| 366 | return -1; | ||
| 367 | } | ||
| 368 | |||
| 369 | return 0; | ||
| 370 | } | ||
| 371 | |||
| 372 | long | ||
| 373 | MainWindow::onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr) | ||
| 374 | { | ||
| 375 | char buf[256]; | ||
| 376 | size_t data_len, len; | ||
| 377 | int textfield_len; | ||
| 378 | |||
| 379 | memset(buf, 0x0, sizeof(buf)); | ||
| 380 | textfield_len = getLengthFromTextField(output_len); | ||
| 381 | data_len = getDataFromTextField(output_text, buf, sizeof(buf)); | ||
| 382 | |||
| 383 | if (textfield_len < 0) { | ||
| 384 | FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal."); | ||
| 385 | return 1; | ||
| 386 | } | ||
| 387 | |||
| 388 | if (textfield_len > sizeof(buf)) { | ||
| 389 | FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long."); | ||
| 390 | return 1; | ||
| 391 | } | ||
| 392 | |||
| 393 | len = (textfield_len)? textfield_len: data_len; | ||
| 394 | |||
| 395 | int res = hid_write(connected_device, (const unsigned char*)buf, len); | ||
| 396 | if (res < 0) { | ||
| 397 | FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not write to device. Error reported was: %ls", hid_error(connected_device)); | ||
| 398 | } | ||
| 399 | |||
| 400 | return 1; | ||
| 401 | } | ||
| 402 | |||
| 403 | long | ||
| 404 | MainWindow::onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr) | ||
| 405 | { | ||
| 406 | char buf[256]; | ||
| 407 | size_t data_len, len; | ||
| 408 | int textfield_len; | ||
| 409 | |||
| 410 | memset(buf, 0x0, sizeof(buf)); | ||
| 411 | textfield_len = getLengthFromTextField(feature_len); | ||
| 412 | data_len = getDataFromTextField(feature_text, buf, sizeof(buf)); | ||
| 413 | |||
| 414 | if (textfield_len < 0) { | ||
| 415 | FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal."); | ||
| 416 | return 1; | ||
| 417 | } | ||
| 418 | |||
| 419 | if (textfield_len > sizeof(buf)) { | ||
| 420 | FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long."); | ||
| 421 | return 1; | ||
| 422 | } | ||
| 423 | |||
| 424 | len = (textfield_len)? textfield_len: data_len; | ||
| 425 | |||
| 426 | int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len); | ||
| 427 | if (res < 0) { | ||
| 428 | FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not send feature report to device. Error reported was: %ls", hid_error(connected_device)); | ||
| 429 | } | ||
| 430 | |||
| 431 | return 1; | ||
| 432 | } | ||
| 433 | |||
| 434 | long | ||
| 435 | MainWindow::onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr) | ||
| 436 | { | ||
| 437 | char buf[256]; | ||
| 438 | size_t len; | ||
| 439 | |||
| 440 | memset(buf, 0x0, sizeof(buf)); | ||
| 441 | len = getDataFromTextField(get_feature_text, buf, sizeof(buf)); | ||
| 442 | |||
| 443 | if (len != 1) { | ||
| 444 | FXMessageBox::error(this, MBOX_OK, "Too many numbers", "Enter only a single report number in the text field"); | ||
| 445 | } | ||
| 446 | |||
| 447 | int res = hid_get_feature_report(connected_device, (unsigned char*)buf, sizeof(buf)); | ||
| 448 | if (res < 0) { | ||
| 449 | FXMessageBox::error(this, MBOX_OK, "Error Getting Report", "Could not get feature report from device. Error reported was: %ls", hid_error(connected_device)); | ||
| 450 | } | ||
| 451 | |||
| 452 | if (res > 0) { | ||
| 453 | FXString s; | ||
| 454 | s.format("Returned Feature Report. %d bytes:\n", res); | ||
| 455 | for (int i = 0; i < res; i++) { | ||
| 456 | FXString t; | ||
| 457 | t.format("%02hhx ", buf[i]); | ||
| 458 | s += t; | ||
| 459 | if ((i+1) % 4 == 0) | ||
| 460 | s += " "; | ||
| 461 | if ((i+1) % 16 == 0) | ||
| 462 | s += "\n"; | ||
| 463 | } | ||
| 464 | s += "\n"; | ||
| 465 | input_text->appendText(s); | ||
| 466 | input_text->setBottomLine(INT_MAX); | ||
| 467 | } | ||
| 468 | |||
| 469 | return 1; | ||
| 470 | } | ||
| 471 | |||
| 472 | long | ||
| 473 | MainWindow::onClear(FXObject *sender, FXSelector sel, void *ptr) | ||
| 474 | { | ||
| 475 | input_text->setText(""); | ||
| 476 | return 1; | ||
| 477 | } | ||
| 478 | |||
| 479 | long | ||
| 480 | MainWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr) | ||
| 481 | { | ||
| 482 | unsigned char buf[256]; | ||
| 483 | int res = hid_read(connected_device, buf, sizeof(buf)); | ||
| 484 | |||
| 485 | if (res > 0) { | ||
| 486 | FXString s; | ||
| 487 | s.format("Received %d bytes:\n", res); | ||
| 488 | for (int i = 0; i < res; i++) { | ||
| 489 | FXString t; | ||
| 490 | t.format("%02hhx ", buf[i]); | ||
| 491 | s += t; | ||
| 492 | if ((i+1) % 4 == 0) | ||
| 493 | s += " "; | ||
| 494 | if ((i+1) % 16 == 0) | ||
| 495 | s += "\n"; | ||
| 496 | } | ||
| 497 | s += "\n"; | ||
| 498 | input_text->appendText(s); | ||
| 499 | input_text->setBottomLine(INT_MAX); | ||
| 500 | } | ||
| 501 | if (res < 0) { | ||
| 502 | input_text->appendText("hid_read() returned error\n"); | ||
| 503 | input_text->setBottomLine(INT_MAX); | ||
| 504 | } | ||
| 505 | |||
| 506 | getApp()->addTimeout(this, ID_TIMER, | ||
| 507 | 5 * timeout_scalar /*5ms*/); | ||
| 508 | return 1; | ||
| 509 | } | ||
| 510 | |||
| 511 | long | ||
| 512 | MainWindow::onMacTimeout(FXObject *sender, FXSelector sel, void *ptr) | ||
| 513 | { | ||
| 514 | #ifdef __APPLE__ | ||
| 515 | check_apple_events(); | ||
| 516 | |||
| 517 | getApp()->addTimeout(this, ID_MAC_TIMER, | ||
| 518 | 50 * timeout_scalar /*50ms*/); | ||
| 519 | #endif | ||
| 520 | |||
| 521 | return 1; | ||
| 522 | } | ||
| 523 | |||
| 524 | int main(int argc, char **argv) | ||
| 525 | { | ||
| 526 | FXApp app("HIDAPI Test Application", "Signal 11 Software"); | ||
| 527 | app.init(argc, argv); | ||
| 528 | g_main_window = new MainWindow(&app); | ||
| 529 | app.create(); | ||
| 530 | app.run(); | ||
| 531 | return 0; | ||
| 532 | } | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/testgui.sln b/contrib/SDL-3.2.8/src/hidapi/testgui/testgui.sln new file mode 100644 index 0000000..56be6c6 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/testgui.sln | |||
| @@ -0,0 +1,20 @@ | |||
| 1 |  | ||
| 2 | Microsoft Visual Studio Solution File, Format Version 10.00 | ||
| 3 | # Visual C++ Express 2008 | ||
| 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testgui", "testgui.vcproj", "{08769AC3-785A-4DDC-BFC7-1775414B7AB7}" | ||
| 5 | EndProject | ||
| 6 | Global | ||
| 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| 8 | Debug|Win32 = Debug|Win32 | ||
| 9 | Release|Win32 = Release|Win32 | ||
| 10 | EndGlobalSection | ||
| 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| 12 | {08769AC3-785A-4DDC-BFC7-1775414B7AB7}.Debug|Win32.ActiveCfg = Debug|Win32 | ||
| 13 | {08769AC3-785A-4DDC-BFC7-1775414B7AB7}.Debug|Win32.Build.0 = Debug|Win32 | ||
| 14 | {08769AC3-785A-4DDC-BFC7-1775414B7AB7}.Release|Win32.ActiveCfg = Release|Win32 | ||
| 15 | {08769AC3-785A-4DDC-BFC7-1775414B7AB7}.Release|Win32.Build.0 = Release|Win32 | ||
| 16 | EndGlobalSection | ||
| 17 | GlobalSection(SolutionProperties) = preSolution | ||
| 18 | HideSolutionNode = FALSE | ||
| 19 | EndGlobalSection | ||
| 20 | EndGlobal | ||
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/testgui.vcproj b/contrib/SDL-3.2.8/src/hidapi/testgui/testgui.vcproj new file mode 100644 index 0000000..f6e6c09 --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/testgui/testgui.vcproj | |||
| @@ -0,0 +1,217 @@ | |||
| 1 | <?xml version="1.0" encoding="Windows-1252"?> | ||
| 2 | <VisualStudioProject | ||
| 3 | ProjectType="Visual C++" | ||
| 4 | Version="9.00" | ||
| 5 | Name="testgui" | ||
| 6 | ProjectGUID="{08769AC3-785A-4DDC-BFC7-1775414B7AB7}" | ||
| 7 | RootNamespace="testgui" | ||
| 8 | Keyword="Win32Proj" | ||
| 9 | TargetFrameworkVersion="196613" | ||
| 10 | > | ||
| 11 | <Platforms> | ||
| 12 | <Platform | ||
| 13 | Name="Win32" | ||
| 14 | /> | ||
| 15 | </Platforms> | ||
| 16 | <ToolFiles> | ||
| 17 | </ToolFiles> | ||
| 18 | <Configurations> | ||
| 19 | <Configuration | ||
| 20 | Name="Debug|Win32" | ||
| 21 | OutputDirectory="$(SolutionDir)$(ConfigurationName)" | ||
| 22 | IntermediateDirectory="$(ConfigurationName)" | ||
| 23 | ConfigurationType="1" | ||
| 24 | CharacterSet="1" | ||
| 25 | > | ||
| 26 | <Tool | ||
| 27 | Name="VCPreBuildEventTool" | ||
| 28 | /> | ||
| 29 | <Tool | ||
| 30 | Name="VCCustomBuildTool" | ||
| 31 | /> | ||
| 32 | <Tool | ||
| 33 | Name="VCXMLDataGeneratorTool" | ||
| 34 | /> | ||
| 35 | <Tool | ||
| 36 | Name="VCWebServiceProxyGeneratorTool" | ||
| 37 | /> | ||
| 38 | <Tool | ||
| 39 | Name="VCMIDLTool" | ||
| 40 | /> | ||
| 41 | <Tool | ||
| 42 | Name="VCCLCompilerTool" | ||
| 43 | Optimization="0" | ||
| 44 | AdditionalIncludeDirectories=""..\..\hidapi-externals\fox\include";..\hidapi" | ||
| 45 | PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS" | ||
| 46 | MinimalRebuild="true" | ||
| 47 | BasicRuntimeChecks="3" | ||
| 48 | RuntimeLibrary="3" | ||
| 49 | UsePrecompiledHeader="0" | ||
| 50 | WarningLevel="3" | ||
| 51 | DebugInformationFormat="4" | ||
| 52 | /> | ||
| 53 | <Tool | ||
| 54 | Name="VCManagedResourceCompilerTool" | ||
| 55 | /> | ||
| 56 | <Tool | ||
| 57 | Name="VCResourceCompilerTool" | ||
| 58 | /> | ||
| 59 | <Tool | ||
| 60 | Name="VCPreLinkEventTool" | ||
| 61 | /> | ||
| 62 | <Tool | ||
| 63 | Name="VCLinkerTool" | ||
| 64 | AdditionalDependencies="fox-1.6.lib" | ||
| 65 | OutputFile="$(ProjectName).exe" | ||
| 66 | LinkIncremental="2" | ||
| 67 | AdditionalLibraryDirectories="..\hidapi\objfre_wxp_x86\i386;"..\..\hidapi-externals\fox\lib"" | ||
| 68 | GenerateDebugInformation="true" | ||
| 69 | SubSystem="2" | ||
| 70 | EntryPointSymbol="mainCRTStartup" | ||
| 71 | TargetMachine="1" | ||
| 72 | /> | ||
| 73 | <Tool | ||
| 74 | Name="VCALinkTool" | ||
| 75 | /> | ||
| 76 | <Tool | ||
| 77 | Name="VCManifestTool" | ||
| 78 | /> | ||
| 79 | <Tool | ||
| 80 | Name="VCXDCMakeTool" | ||
| 81 | /> | ||
| 82 | <Tool | ||
| 83 | Name="VCBscMakeTool" | ||
| 84 | /> | ||
| 85 | <Tool | ||
| 86 | Name="VCFxCopTool" | ||
| 87 | /> | ||
| 88 | <Tool | ||
| 89 | Name="VCAppVerifierTool" | ||
| 90 | /> | ||
| 91 | <Tool | ||
| 92 | Name="VCPostBuildEventTool" | ||
| 93 | CommandLine="" | ||
| 94 | /> | ||
| 95 | </Configuration> | ||
| 96 | <Configuration | ||
| 97 | Name="Release|Win32" | ||
| 98 | OutputDirectory="$(SolutionDir)$(ConfigurationName)" | ||
| 99 | IntermediateDirectory="$(ConfigurationName)" | ||
| 100 | ConfigurationType="1" | ||
| 101 | CharacterSet="1" | ||
| 102 | WholeProgramOptimization="1" | ||
| 103 | > | ||
| 104 | <Tool | ||
| 105 | Name="VCPreBuildEventTool" | ||
| 106 | /> | ||
| 107 | <Tool | ||
| 108 | Name="VCCustomBuildTool" | ||
| 109 | /> | ||
| 110 | <Tool | ||
| 111 | Name="VCXMLDataGeneratorTool" | ||
| 112 | /> | ||
| 113 | <Tool | ||
| 114 | Name="VCWebServiceProxyGeneratorTool" | ||
| 115 | /> | ||
| 116 | <Tool | ||
| 117 | Name="VCMIDLTool" | ||
| 118 | /> | ||
| 119 | <Tool | ||
| 120 | Name="VCCLCompilerTool" | ||
| 121 | Optimization="2" | ||
| 122 | EnableIntrinsicFunctions="true" | ||
| 123 | AdditionalIncludeDirectories=""..\..\hidapi-externals\fox\include";..\hidapi" | ||
| 124 | PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" | ||
| 125 | RuntimeLibrary="2" | ||
| 126 | EnableFunctionLevelLinking="true" | ||
| 127 | UsePrecompiledHeader="0" | ||
| 128 | WarningLevel="3" | ||
| 129 | DebugInformationFormat="3" | ||
| 130 | /> | ||
| 131 | <Tool | ||
| 132 | Name="VCManagedResourceCompilerTool" | ||
| 133 | /> | ||
| 134 | <Tool | ||
| 135 | Name="VCResourceCompilerTool" | ||
| 136 | /> | ||
| 137 | <Tool | ||
| 138 | Name="VCPreLinkEventTool" | ||
| 139 | /> | ||
| 140 | <Tool | ||
| 141 | Name="VCLinkerTool" | ||
| 142 | AdditionalDependencies="fox-1.6.lib" | ||
| 143 | OutputFile="$(ProjectName).exe" | ||
| 144 | LinkIncremental="1" | ||
| 145 | AdditionalLibraryDirectories="..\hidapi\objfre_wxp_x86\i386;"..\..\hidapi-externals\fox\lib"" | ||
| 146 | GenerateDebugInformation="true" | ||
| 147 | SubSystem="2" | ||
| 148 | OptimizeReferences="2" | ||
| 149 | EnableCOMDATFolding="2" | ||
| 150 | EntryPointSymbol="mainCRTStartup" | ||
| 151 | TargetMachine="1" | ||
| 152 | /> | ||
| 153 | <Tool | ||
| 154 | Name="VCALinkTool" | ||
| 155 | /> | ||
| 156 | <Tool | ||
| 157 | Name="VCManifestTool" | ||
| 158 | /> | ||
| 159 | <Tool | ||
| 160 | Name="VCXDCMakeTool" | ||
| 161 | /> | ||
| 162 | <Tool | ||
| 163 | Name="VCBscMakeTool" | ||
| 164 | /> | ||
| 165 | <Tool | ||
| 166 | Name="VCFxCopTool" | ||
| 167 | /> | ||
| 168 | <Tool | ||
| 169 | Name="VCAppVerifierTool" | ||
| 170 | /> | ||
| 171 | <Tool | ||
| 172 | Name="VCPostBuildEventTool" | ||
| 173 | CommandLine="" | ||
| 174 | /> | ||
| 175 | </Configuration> | ||
| 176 | </Configurations> | ||
| 177 | <References> | ||
| 178 | </References> | ||
| 179 | <Files> | ||
| 180 | <Filter | ||
| 181 | Name="Source Files" | ||
| 182 | Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" | ||
| 183 | UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" | ||
| 184 | > | ||
| 185 | <File | ||
| 186 | RelativePath="..\windows\hid.c" | ||
| 187 | > | ||
| 188 | </File> | ||
| 189 | <File | ||
| 190 | RelativePath=".\test.cpp" | ||
| 191 | > | ||
| 192 | </File> | ||
| 193 | </Filter> | ||
| 194 | <Filter | ||
| 195 | Name="Header Files" | ||
| 196 | Filter="h;hpp;hxx;hm;inl;inc;xsd" | ||
| 197 | UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" | ||
| 198 | > | ||
| 199 | <File | ||
| 200 | RelativePath="..\hidapi\hidapi.h" | ||
| 201 | > | ||
| 202 | </File> | ||
| 203 | </Filter> | ||
| 204 | <Filter | ||
| 205 | Name="Resource Files" | ||
| 206 | Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" | ||
| 207 | UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" | ||
| 208 | > | ||
| 209 | </Filter> | ||
| 210 | <File | ||
| 211 | RelativePath=".\ReadMe.txt" | ||
| 212 | > | ||
| 213 | </File> | ||
| 214 | </Files> | ||
| 215 | <Globals> | ||
| 216 | </Globals> | ||
| 217 | </VisualStudioProject> | ||
