From d7b2615d73802a9e39453cb1974cd65710d5ef36 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 27 May 2006 00:57:15 +0000 Subject: seemed to fix the mac crasher bug caused by HIDReleaseBuildList wierdness; cleaned up things a bit and made it possible to open devices by type svn path=/trunk/externals/hcs/hid/; revision=5138 --- Makefile | 150 +----------------------------------- TODO | 68 ++++++++++++----- doc/hid-help.pd | 187 ++++++++++++++++++++++----------------------- hid.c | 231 +++++++++++++++++++++++++++++++++++++++++--------------- hid.h | 69 ++++++++++------- hid_darwin.c | 162 ++++++++++++++++++++++++--------------- hid_linux.c | 12 +-- hid_windows.c | 12 +-- mouse.pd | 48 ++++++------ 9 files changed, 495 insertions(+), 444 deletions(-) diff --git a/Makefile b/Makefile index e919c0b..a13265f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -TARGET := `pwd|sed 's|.*/\(.*\)$|\1|'` -EXTERNALS_ROOT := `pwd | sed 's|^\(/.*externals\).*|\1|'` +TARGET := $(shell pwd | sed 's|.*/\(.*\)$$|\1|') +EXTERNALS_ROOT := $(shell pwd | sed 's|^\(/.*externals\).*|\1|') default: make -C $(EXTERNALS_ROOT) $(TARGET) @@ -10,148 +10,6 @@ install: clean: make -C $(EXTERNALS_ROOT) $(TARGET)_clean -#============================================================================== -#============================================================================== -#============================================================================== -#============================================================================== -#============================================================================== -# this stuff below probably works, but its not maintained anymore since I use -# externals/Makefile - -CWD := $(shell pwd) - -# these are setup to be overridden by the packages/Makefile -cvs_root_dir = $(CWD)/../../.. -DESTDIR = $(CWD)/build/ -BUILDLAYOUT_DIR = $(cvs_root_dir)/packages - --include $(BUILDLAYOUT_DIR)/Makefile.buildlayout - - - -CFLAGS = $(OPT_FLAGS) -Wall -I./ -I../../../pd/src -LDFLAGS = -LIBS = -lm - -ifeq (x$(OS_NAME),x) -default: - @echo no OS_NAME specified -endif - - -#SRC = $(wildcard $(externals_src)/hcs/hid/hid*.c) -SRC = $(wildcard *.c) -SRC = input_arrays.c hid_$(OS_NAME).c -OBJ := $(SRC:.c=.o) - -# ----------------------- GNU/LINUX i386 ----------------------- -ifeq ($(OS_NAME),linux) - EXTENSION = pd_linux - LDFLAGS += -export_dynamic -shared - LIBS += -lc - STRIP = strip --strip-unneeded - hid.$(EXTENSION): input_arrays $(OBJ) -endif - -# ----------------------- Windows MinGW ----------------------- -ifeq ($(OS_NAME),windows) - EXTENSION = dll - CFLAGS += -mms-bitfields - LDFLAGS += -shared - LIBS += -lhid -lsetupapi -L../../../pd/bin -lpd - STRIP = strip --strip-unneeded - hid.$(EXTENSION): input_arrays $(OBJ) -endif - -# ----------------------- DARWIN ----------------------- -ifeq ($(OS_NAME),darwin) - EXTENSION = pd_darwin - CFLAGS += -I./HID\ Utilities\ Source - PDEXECUTABLE = ../../../pd/bin/pd - FRAMEWORKS = Carbon IOKit ForceFeedback - LDFLAGS += -bundle -bundle_loader $(PDEXECUTABLE) - LIBS += -lc -L/sw/lib -L./HID\ Utilities\ Source/build \ - -lHIDUtilities $(patsubst %,-framework %,$(FRAMEWORKS)) - STRIP = strip -x - hid.$(EXTENSION): input_arrays hid_utilites $(OBJ) -.SUFFIXES: .pd_darwin -endif - -all: hid.$(EXTENSION) - -.SUFFIXES: .$(EXTENSION) - -# ----------------------- GENERAL --------------------------------------------- -# generic optimization -OPT_FLAGS = -O3 -ffast-math -# G4 optimization on Mac OS X -#OPT_FLAGS = -O3 -mcpu=7400 -maltivec -ffast-math -fPIC -# faster G4 7450 optimization (gives errors) on GNU/Linux -#OPT_FLAGS = -O3 -mcpu=7450 -maltivec -ffast-math -fPIC -# G4 optimization on Mac OS X -#OPT_FLAGS = -O3 -mcpu=7400 -faltivec -ffast-math -fPIC -# faster G4 7450 optimization (gives errors) on Mac OS X -#OPT_FLAGS = -ffast -mcpu=7450 -faltivec -ffast-math -fPIC - -%.o: %.c - $(CC) $(CFLAGS) -o "$*.o" -c "$*.c" - -%.$(EXTENSION): %.o - $(CC) $(LDFLAGS) -o "$*.$(EXTENSION)" "$*.o" $(OBJ) $(LIBS) \ - `test -f $*.libs && cat $*.libs` \ - `test -f $(dir $*)../$(OS_NAME)/$(notdir $*).libs && \ - cat $(dir $*)../$(OS_NAME)/$(notdir $*).libs` - chmod a-x "$*.$(EXTENSION)" - $(STRIP) $*.$(EXTENSION) - rm -f -- $*.o - - -input_arrays: input_arrays.c input_arrays.h - -input_arrays.c: linux/input.h - ./make-arrays-from-input.h.pl - -input_arrays.h: linux/input.h - ./make-arrays-from-input.h.pl - - -hid_utilities: - test -f ./HID\ Utilities\ Source/build/libHIDUtilities.a || \ - ( cd ./HID\ Utilities\ Source && pbxbuild ) - - -local_clean: - -rm -f -- *.$(EXTENSION) *~ - -find . -name '*.o' | xargs rm -f -- - -distclean: local_clean - -rm -f -- input_arrays.? doc/ev*-list.pd - -.PHONY: all input_arrays hid_utilities clean distclean - - test_locations: - @echo "EXTENSION: $(EXTENSION)" - @echo "CFLAGS: $(CFLAGS)" - @echo "LDFLAGS: $(LDFLAGS)" - @echo "LIBS: $(LIBS)" - @echo "STRIP: $(STRIP)" - @echo " " - @echo "SRC: $(SRC)" - @echo "OBJ: $(OBJ)" - @echo " " - @echo "OS_NAME: $(OS_NAME)" - @echo "PD_VERSION: $(PD_VERSION)" - @echo "PACKAGE_VERSION: $(PACKAGE_VERSION)" - @echo "CWD: $(CWD)" - @echo "DESTDIR: $(DESTDIR)" - @echo "PREFIX: $(prefix)" - @echo "BINDIR: $(bindir)" - @echo "LIBDIR: $(libdir)" - @echo "OBJECTSDIR: $(objectsdir)" - @echo "PDDOCDIR: $(pddocdir)" - @echo "LIBPDDIR: $(libpddir)" - @echo "LIBPDBINDIR: $(libpdbindir)" - @echo "HELPDIR: $(helpdir)" - @echo "MANUALSDIR: $(manualsdir)" - @echo "EXAMPLESDIR: $(examplesdir)" + make -C $(EXTERNALS_ROOT) test_locations + diff --git a/TODO b/TODO index a32547d..74954d0 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,14 @@ + + + +TODO: make open functions: + +device number +vendor_id product_id +Product String + + + ============================================================================== = test verbose names @@ -23,24 +34,34 @@ ============================================================================== -= make fake names in input_arrays.c += hid/serial -Instead of having "NULL" names, make up names using the event type, and the -code number, i.e. abs_41, rel_15 +- open/close status outlet +- [send ( to send data + +- [tgl] 1/0 for open/close ============================================================================== -= check out GDAM HID implementation += linux input synch events (EV_SYN) + +- these seem to be generated by the Linux kernel, so they probably don't fit + in with the [hid] scheme. Probably the best thing is to ditch them, or + figure out whether they should be used in controlling the flow of event + data, as they are intended. + + +============================================================================== += open/close status outlet -- GDAM has a HID Manager implementation and probably a Linux one too ============================================================================== = profile [hid] object and usage -- find out how much more CPU the names (btn_?, abs, rel, etc) use over using - just floats. +- find out if [autoscale] takes a lot of CPU power, or where in [hid] is using + CPU where it doesn't have to be ============================================================================== @@ -56,6 +77,12 @@ by # (1,2,...), generic name (mouse1, joystick2, tablet3...), or device name - check against HID Utilities Source/PID.h +============================================================================== += device 0 gets events for all available devices + +- it might be useful to have device #0 open all available devices and output + the events. + ============================================================================== = figure out how to store device ID in obj struct @@ -86,13 +113,11 @@ by # (1,2,...), generic name (mouse1, joystick2, tablet3...), or device name - most functions probably do not need return values -- return (1) seems to be the default on many functions - ============================================================================== = control input messages -- are [poll(, [start(, and [stop( needed? is 0/1/del# enough? +- are [poll(, [start(, and [stop( needed? is 0/1/delay# enough? ============================================================================== @@ -104,7 +129,7 @@ void hid_post(const char *format, const char *); ============================================================================== = event name changes -- make key/button Type btn rather than key (undecided on this one) +- make key/button Type "button" rather than "key" (undecided on this one) ============================================================================== @@ -118,13 +143,6 @@ void hid_post(const char *format, const char *); - these objects should follow the same conventions as [hid] -============================================================================== -= device 0 gets events for all available devices - -- it might be useful to have device #0 open all available devices and output - the events. - - ============================================================================== = figure out whole degree issue @@ -160,6 +178,11 @@ Curves!! http://www.2dcurves.com +============================================================================== += check out using USB timestamp + +- use the USB timestamp to correctly space the output data + /++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -167,6 +190,13 @@ http://www.2dcurves.com ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/ +______________________________________________________________________________ +- BUG: figure out how to prevent segfaults on mismapped devices/elements + +- it should gracefully ignore things where it currently segfaults + +- looks like its in build_device_list + ______________________________________________________________________________ - BUG: multiple instances pointing to the same device don't have seperate close/free @@ -184,6 +214,8 @@ ______________________________________________________________________________ the screen. Hopefully the HID Manager API will allow raw mouse data access. It must since its used with games. +- turn off/unlink mousepointer for that device? + ______________________________________________________________________________ - BUG: getting events from the queue doesn't output a 0 value event when the diff --git a/doc/hid-help.pd b/doc/hid-help.pd index 8575873..892689d 100644 --- a/doc/hid-help.pd +++ b/doc/hid-help.pd @@ -1,15 +1,9 @@ -#N canvas 282 77 921 634 10; +#N canvas 264 93 957 670 10; #X msg 455 295 key btn_0 0; -#X obj 455 274 prepend set; #X floatatom 27 484 5 0 0 0 - - -; #X floatatom 83 484 5 0 0 0 - - -; -#X msg 158 121 start; -#X msg 158 141 stop; -#X msg 261 110 open 0; -#X msg 268 128 open 1; -#X msg 275 146 open 2; #X floatatom 63 440 6 0 0 0 - - -; -#X obj 68 122 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 25 25 +#X obj 129 122 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 0 25 ; #X floatatom 534 356 12 0 0 1 value - -; #X symbolatom 494 372 15 0 0 1 event_code - -; @@ -39,14 +33,14 @@ #X floatatom 268 384 5 0 0 1 ev_syn - -; #X obj 241 383 +; #X msg 241 363 1; -#X msg 366 124 close; -#X msg 366 103 refresh; -#X text 427 101 refresh device list; +#X msg 402 117 close; +#X msg 402 96 refresh; +#X text 463 94 refresh device list; #X text 607 531 For more info:; #X text 49 588 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 266 602 released under the GNU GPL; -#X text 472 589 $Revision: 1.19 $$Date: 2006-03-17 04:57:20 $; +#X text 472 589 $Revision: 1.20 $$Date: 2006-05-27 00:57:15 $; #X text 473 602 $Author: eighthave $; #X msg 428 185 poll 20; #X msg 366 185 poll 2; @@ -261,14 +255,13 @@ of it could change without notice !!!; #X floatatom 140 484 5 0 0 0 - - -; #X obj 421 439 route abs_hat0x abs_hat0y abs_hat1x abs_hat1y; #X floatatom 421 461 7 0 0 0 - - -; -#X msg 118 121 1; -#X msg 118 141 0; +#X msg 179 121 1; +#X msg 179 141 0; #X msg 868 3 pddp; -#X obj 716 530 pddp_open all_about_hid; -#X msg 366 145 print; +#X msg 402 138 print; #X obj 247 223 hid 0; -#X text 429 125 close the device; -#X text 429 146 print the device and element lists; +#X text 465 118 close the device; +#X text 465 139 print the device and element lists; #X text 10 50 Any non-zero value starts polling \,; #X text 10 63 0 stops the polling. If the number; #X text 10 76 is greater than 1 \, then the poll; @@ -279,7 +272,7 @@ of it could change without notice !!!; #X obj 455 335 unpack s s f; #X msg 248 91 open \$1; #X obj 248 73 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1 --1 3; +-1 0; #X floatatom 235 94 1 0 0 0 - - -; #X text 387 248 event_type event_code value; #X obj 63 419 route abs_x abs_y abs_z abs_rx abs_ry abs_rz abs_throttle @@ -287,7 +280,7 @@ of it could change without notice !!!; #X obj 421 477 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; #X floatatom 498 461 7 0 0 0 - - -; -#X obj 498 477 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 +#X obj 498 477 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X floatatom 576 461 7 0 0 0 - - -; #X obj 576 477 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 @@ -309,15 +302,15 @@ of it could change without notice !!!; ; #X obj 129 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; -#X obj 159 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 1 +#X obj 159 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 189 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; -#X obj 219 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 1 +#X obj 219 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 249 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; -#X obj 279 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 1 +#X obj 279 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 309 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; @@ -333,74 +326,82 @@ btn_8 btn_9 btn_10 btn_11 btn_12 btn_13 btn_14 btn_15; 1; #X obj 459 547 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; -#X connect 1 0 0 0; -#X connect 4 0 61 0; -#X connect 5 0 61 0; -#X connect 6 0 61 0; -#X connect 7 0 61 0; -#X connect 8 0 61 0; -#X connect 10 0 61 0; -#X connect 31 0 30 0; -#X connect 31 0 14 0; -#X connect 32 0 31 1; -#X connect 33 0 34 1; -#X connect 34 0 33 0; -#X connect 35 0 34 0; -#X connect 36 0 61 0; -#X connect 37 0 61 0; -#X connect 44 0 61 0; -#X connect 45 0 61 0; -#X connect 48 0 103 0; -#X connect 48 1 69 0; -#X connect 48 2 76 0; -#X connect 48 3 35 0; -#X connect 54 0 55 0; -#X connect 54 1 78 0; -#X connect 54 2 80 0; -#X connect 54 3 82 0; -#X connect 55 0 77 0; -#X connect 56 0 61 0; -#X connect 57 0 61 0; -#X connect 60 0 61 0; -#X connect 61 0 31 0; -#X connect 61 0 1 0; -#X connect 61 0 48 0; -#X connect 61 0 71 0; -#X connect 68 0 61 0; -#X connect 69 0 2 0; -#X connect 69 1 3 0; -#X connect 69 2 53 0; -#X connect 69 3 70 0; -#X connect 71 0 13 0; -#X connect 71 1 12 0; -#X connect 71 2 11 0; -#X connect 72 0 61 0; -#X connect 73 0 72 0; +#X obj 455 274 cyclone/prepend set; +#X msg 37 196 debug \$1; +#X obj 37 174 hradio 15 1 1 10 empty empty empty 0 -6 0 8 -262144 -1 +-1 9; +#X obj 716 530 pddp/pddp_open all_about_hid; +#X msg 261 110 open mouse1; +#X msg 270 133 open mouse; +#X msg 270 157 open keyboard; +#X connect 4 0 54 0; +#X connect 25 0 24 0; +#X connect 25 0 8 0; +#X connect 26 0 25 1; +#X connect 27 0 28 1; +#X connect 28 0 27 0; +#X connect 29 0 28 0; +#X connect 30 0 54 0; +#X connect 31 0 54 0; +#X connect 38 0 54 0; +#X connect 39 0 54 0; +#X connect 42 0 96 0; +#X connect 42 1 62 0; +#X connect 42 2 69 0; +#X connect 42 3 29 0; +#X connect 48 0 49 0; +#X connect 48 1 71 0; +#X connect 48 2 73 0; +#X connect 48 3 75 0; +#X connect 49 0 70 0; +#X connect 50 0 54 0; +#X connect 51 0 54 0; +#X connect 53 0 54 0; +#X connect 54 0 25 0; +#X connect 54 0 42 0; +#X connect 54 0 64 0; +#X connect 54 0 99 0; +#X connect 61 0 54 0; +#X connect 62 0 1 0; +#X connect 62 1 2 0; +#X connect 62 2 47 0; +#X connect 62 3 63 0; +#X connect 64 0 7 0; +#X connect 64 1 6 0; +#X connect 64 2 5 0; +#X connect 65 0 54 0; +#X connect 66 0 65 0; +#X connect 66 0 67 0; +#X connect 69 0 3 0; +#X connect 69 1 77 0; +#X connect 69 2 78 0; +#X connect 69 3 79 0; +#X connect 69 4 80 0; +#X connect 69 5 81 0; +#X connect 69 6 82 0; +#X connect 69 7 48 0; +#X connect 71 0 72 0; #X connect 73 0 74 0; -#X connect 76 0 9 0; -#X connect 76 1 84 0; -#X connect 76 2 85 0; -#X connect 76 3 86 0; -#X connect 76 4 87 0; -#X connect 76 5 88 0; -#X connect 76 6 89 0; -#X connect 76 7 54 0; -#X connect 78 0 79 0; -#X connect 80 0 81 0; -#X connect 82 0 83 0; -#X connect 103 0 49 0; -#X connect 103 1 90 0; -#X connect 103 2 91 0; -#X connect 103 3 92 0; -#X connect 103 4 93 0; -#X connect 103 5 94 0; -#X connect 103 6 95 0; -#X connect 103 7 96 0; -#X connect 103 8 97 0; -#X connect 103 9 98 0; -#X connect 103 10 99 0; -#X connect 103 11 100 0; -#X connect 103 12 101 0; -#X connect 103 13 102 0; -#X connect 103 14 104 0; -#X connect 103 15 105 0; +#X connect 75 0 76 0; +#X connect 96 0 43 0; +#X connect 96 1 83 0; +#X connect 96 2 84 0; +#X connect 96 3 85 0; +#X connect 96 4 86 0; +#X connect 96 5 87 0; +#X connect 96 6 88 0; +#X connect 96 7 89 0; +#X connect 96 8 90 0; +#X connect 96 9 91 0; +#X connect 96 10 92 0; +#X connect 96 11 93 0; +#X connect 96 12 94 0; +#X connect 96 13 95 0; +#X connect 96 14 97 0; +#X connect 96 15 98 0; +#X connect 99 0 0 0; +#X connect 100 0 54 0; +#X connect 101 0 100 0; +#X connect 103 0 54 0; +#X connect 104 0 54 0; +#X connect 105 0 54 0; diff --git a/hid.c b/hid.c index 9435257..4471d3a 100644 --- a/hid.c +++ b/hid.c @@ -23,6 +23,12 @@ /* */ /* --------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include + #include "hid.h" /*------------------------------------------------------------------------------ @@ -32,17 +38,18 @@ #define DEBUG(x) //#define DEBUG(x) x +unsigned short global_debug_level = 0; + static t_class *hid_class; /*------------------------------------------------------------------------------ * FUNCTION PROTOTYPES */ -void hid_start(t_hid *x, t_float f); -void hid_stop(t_hid *x); -t_int hid_open(t_hid *x, t_float f); -t_int hid_close(t_hid *x); -t_int hid_read(t_hid *x,int fd); +static void hid_poll(t_hid *x, t_float f); +static t_int hid_open(t_hid *x, t_symbol *s, t_int argc, t_atom *argv); +static t_int hid_close(t_hid *x); +static t_int hid_read(t_hid *x,int fd); static void hid_float(t_hid* x, t_floatarg f); @@ -50,6 +57,46 @@ static void hid_float(t_hid* x, t_floatarg f); * SUPPORT FUNCTIONS */ +void debug_print(t_int message_debug_level, const char *fmt, ...) +{ + if(message_debug_level <= global_debug_level) + { + char buf[MAXPDSTRING]; + va_list ap; + //t_int arg[8]; + va_start(ap, fmt); + vsnprintf(buf, MAXPDSTRING-1, fmt, ap); + post(buf); + va_end(ap); + } +} + +void debug_error(t_hid *x, t_int message_debug_level, const char *fmt, ...) +{ + if(message_debug_level <= global_debug_level) + { + char buf[MAXPDSTRING]; + va_list ap; + //t_int arg[8]; + va_start(ap, fmt); + vsnprintf(buf, MAXPDSTRING-1, fmt, ap); + pd_error(x, buf); + va_end(ap); + } +} + +static unsigned int name_to_usage(char *usage_name) +{ // output usagepage << 16 + usage + if(strcmp(usage_name,"pointer") == 0) return(0x00010001); + if(strcmp(usage_name,"mouse") == 0) return(0x00010002); + if(strcmp(usage_name,"joystick") == 0) return(0x00010004); + if(strcmp(usage_name,"gamepad") == 0) return(0x00010005); + if(strcmp(usage_name,"keyboard") == 0) return(0x00010006); + if(strcmp(usage_name,"keypad") == 0) return(0x00010007); + if(strcmp(usage_name,"multiaxiscontroller") == 0) return(0x00010008); + return(0); +} + void hid_output_event(t_hid *x, char *type, char *code, t_float value) { t_atom event_data[3]; @@ -61,6 +108,19 @@ void hid_output_event(t_hid *x, char *type, char *code, t_float value) outlet_anything(x->x_data_outlet,atom_gensym(event_data),2,event_data+1); } +/* stop polling the device */ +void stop_poll(t_hid* x) +{ + debug_print(LOG_DEBUG,"stop_poll"); + + if (x->x_started) + { + clock_unset(x->x_clock); + debug_print(LOG_INFO,"[hid] polling stopped"); + x->x_started = 0; + } +} + void hid_set_from_float(t_hid *x, t_floatarg f) { /* values greater than 1 set the polling delay time */ @@ -68,47 +128,35 @@ void hid_set_from_float(t_hid *x, t_floatarg f) if (f > 1) { x->x_delay = (t_int)f; - hid_start(x,f); + hid_poll(x,f); } else if (f == 1) { if (! x->x_started) - hid_start(x,f); + hid_poll(x,f); } else if (f == 0) { - hid_stop(x); + stop_poll(x); } } /*------------------------------------------------------------------------------ - * IMPLEMENTATION + * METHODS FOR [hid]'s MESSAGES */ -/* stop polling the device */ -void hid_stop(t_hid* x) -{ - DEBUG(post("hid_stop");); - - if (x->x_started) - { - clock_unset(x->x_clock); - DEBUG(post("[hid] polling stopped");); - x->x_started = 0; - } -} /* close the device */ t_int hid_close(t_hid *x) { - DEBUG(post("hid_close");); + debug_print(LOG_DEBUG,"hid_close"); /* just to be safe, stop it first */ - hid_stop(x); + stop_poll(x); if(! hid_close_device(x)) { - post("[hid] closed device %d",x->x_device_number); + debug_print(LOG_INFO,"[hid] closed device %d",x->x_device_number); x->x_device_open = 0; return (0); } @@ -126,28 +174,62 @@ t_int hid_close(t_hid *x) * open / different device close open */ -t_int hid_open(t_hid *x, t_float f) +t_int hid_open(t_hid *x, t_symbol *s, t_int argc, t_atom *argv) { - DEBUG(post("hid_open");); - + debug_print(LOG_DEBUG,"hid_open"); + unsigned short i; + unsigned short device_number = 0; + unsigned short usage_number; + unsigned int usage; + char usage_string[MAXPDSTRING] = ""; + + if(argc == 1) + { + if(atom_getsymbolarg(0,argc,argv) == &s_) + { // single float arg means device + debug_print(LOG_DEBUG,"[hid] setting device# to %d",device_number); + device_number = (unsigned short) atom_getfloatarg(0,argc,argv); + } + else + { // single symbol arg means usagepage/usage + debug_print(LOG_DEBUG,"[hid] setting device via usagepage/usage"); + atom_string(argv, usage_string, MAXPDSTRING-1); + i = strlen(usage_string); + do { + --i; + } while(isdigit(usage_string[i])); + usage_number = strtol(usage_string + i + 1,NULL,10); + usage_string[i+1] = '\0'; + debug_print(LOG_DEBUG,"[hid] looking for %s #%d",usage_string,usage_number); + usage = name_to_usage(usage_string); + debug_print(LOG_DEBUG,"[hid] usage 0x%08x 0x%04x 0x%04x",usage, usage >> 16, usage & 0xffff); + device_number = get_device_number_from_usage_list(usage_number, + usage >> 16, usage & 0xffff); + } + } + else if( (argc == 2) && (atom_getsymbolarg(0,argc,argv) != NULL) + && (atom_getsymbolarg(1,argc,argv) != NULL) ) + { /* two symbols means idVendor and idProduct in hex */ + } + /* store running state to be restored after the device has been opened */ t_int started = x->x_started; /* only close the device if its different than the current and open */ - if ( (f != x->x_device_number) && (x->x_device_open) ) + if( (device_number != x->x_device_number) && (x->x_device_open) ) hid_close(x); - if (f > 0) - x->x_device_number = f; + if(device_number > 0) + x->x_device_number = device_number; else x->x_device_number = 0; /* if device is open still, that means the same device is trying to be opened, * therefore ignore the redundant open request. To reopen the same device, * send a [close( msg, then an [open( msg. */ - if (! x->x_device_open) + if(! x->x_device_open) { - if (hid_open_device(x,x->x_device_number)) + if(hid_open_device(x,x->x_device_number)) { error("[hid] can not open device %d",x->x_device_number); return (1); @@ -164,13 +246,15 @@ t_int hid_open(t_hid *x, t_float f) if(started) hid_set_from_float(x,x->x_delay); + debug_print(LOG_DEBUG,"[hid] done device# to %d",device_number); + return (0); } t_int hid_read(t_hid *x,int fd) { -// DEBUG(post("hid_read");); +// debug_print(LOG_DEBUG,"hid_read"); hid_get_events(x); @@ -183,36 +267,62 @@ t_int hid_read(t_hid *x,int fd) return 1; } -void hid_start(t_hid* x, t_float f) +void hid_poll(t_hid* x, t_float f) { - DEBUG(post("hid_start");); + debug_print(LOG_DEBUG,"hid_poll"); /* if the user sets the delay less than one, ignore */ - if( f >= 1 ) + if( f > 0 ) x->x_delay = (t_int)f; if(!x->x_device_open) - hid_open(x,x->x_device_number); + hid_open(x,gensym("open"),0,NULL); - if(!x->x_started) + if(!x->x_started) { clock_delay(x->x_clock, x->x_delay); - DEBUG(post("[hid] polling started");); + debug_print(LOG_DEBUG,"[hid] polling started"); x->x_started = 1; } } +static void hid_anything(t_hid *x, t_symbol *s, t_int argc, t_atom *argv) +{ + int i; + t_symbol *my_symbol; + char device_name[MAXPDSTRING]; + + startpost("ANYTHING! selector: %s data:"); + for(i=0; is_name); + else + post(" %f",atom_getfloatarg(i,argc,argv)); + } +} + + static void hid_float(t_hid* x, t_floatarg f) { - DEBUG(post("hid_float");); + debug_print(LOG_DEBUG,"hid_float"); hid_set_from_float(x,f); } -/* setup functions */ +static void hid_debug(t_hid *x, t_float f) +{ + global_debug_level = f; +} + + +/*------------------------------------------------------------------------------ + * system functions + */ static void hid_free(t_hid* x) { - DEBUG(post("hid_free");); + debug_print(LOG_DEBUG,"hid_free"); hid_close(x); clock_free(x->x_clock); @@ -225,13 +335,16 @@ static void hid_free(t_hid* x) static void *hid_new(t_float f) { t_hid *x = (t_hid *)pd_new(hid_class); - - DEBUG(post("hid_new");); - + + debug_print(LOG_DEBUG,"hid_new"); + /* only display the version when the first instance is loaded */ if(!hid_instance_count) + { post("[hid] %d.%d, written by Hans-Christoph Steiner ", HID_MAJOR_VERSION, HID_MINOR_VERSION); + post("\tcompiled on "__DATE__" at "__TIME__ " "); + } #if !defined(__linux__) && !defined(__APPLE__) error(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); @@ -240,6 +353,7 @@ static void *hid_new(t_float f) #endif /* init vars */ + global_debug_level = 9; /* high numbers here means see more messages */ x->x_has_ff = 0; x->x_device_open = 0; x->x_started = 0; @@ -250,16 +364,14 @@ static void *hid_new(t_float f) /* create anything outlet used for HID data */ x->x_data_outlet = outlet_new(&x->x_obj, 0); x->x_device_name_outlet = outlet_new(&x->x_obj, 0); - - /* find and report the list of devices */ - hid_build_device_list(x); - - /* Open the device and save settings. If there is an error, return the object - * anyway, so that the inlets and outlets are created, thus not breaking the - * patch. */ - if (hid_open(x,f)) - error("[hid] device %d did not open",(t_int)f); + x->x_device_number = 0; + + if(f > 0) + x->x_device_number = f; + else + x->x_device_number = 0; + hid_instance_count++; return (x); @@ -267,7 +379,7 @@ static void *hid_new(t_float f) void hid_setup(void) { - DEBUG(post("hid_setup");); + debug_print(LOG_DEBUG,"hid_setup"); hid_class = class_new(gensym("hid"), (t_newmethod)hid_new, (t_method)hid_free, @@ -278,16 +390,15 @@ void hid_setup(void) /* add inlet datatype methods */ class_addfloat(hid_class,(t_method) hid_float); class_addbang(hid_class,(t_method) hid_read); + class_addanything(hid_class,(t_method) hid_anything); /* add inlet message methods */ + class_addmethod(hid_class,(t_method) hid_debug,gensym("debug"),A_DEFFLOAT,0); class_addmethod(hid_class,(t_method) hid_build_device_list,gensym("refresh"),0); class_addmethod(hid_class,(t_method) hid_print,gensym("print"),0); - class_addmethod(hid_class,(t_method) hid_open,gensym("open"),A_DEFFLOAT,0); + class_addmethod(hid_class,(t_method) hid_open,gensym("open"),A_GIMME,0); class_addmethod(hid_class,(t_method) hid_close,gensym("close"),0); - class_addmethod(hid_class,(t_method) hid_start,gensym("start"),A_DEFFLOAT,0); - class_addmethod(hid_class,(t_method) hid_start,gensym("poll"),A_DEFFLOAT,0); - class_addmethod(hid_class,(t_method) hid_stop,gensym("stop"),0); - class_addmethod(hid_class,(t_method) hid_stop,gensym("nopoll"),0); + class_addmethod(hid_class,(t_method) hid_poll,gensym("poll"),A_DEFFLOAT,0); /* force feedback messages */ class_addmethod(hid_class,(t_method) hid_ff_autocenter, gensym("ff_autocenter"),A_DEFFLOAT,0); diff --git a/hid.h b/hid.h index 527dddf..a246e5b 100644 --- a/hid.h +++ b/hid.h @@ -2,6 +2,7 @@ #define _HID_H #include +#include #include @@ -12,26 +13,29 @@ #include "input_arrays.h" #define HID_MAJOR_VERSION 0 -#define HID_MINOR_VERSION 6 +#define HID_MINOR_VERSION 7 -/* static char *version = "$Revision: 1.19 $"; */ +/* static char *version = "$Revision: 1.20 $"; */ /*------------------------------------------------------------------------------ * CLASS DEF */ typedef struct _hid { - t_object x_obj; - t_int x_fd; - t_int x_device_number; - t_int x_has_ff; - void *x_ff_device; - t_clock *x_clock; - t_int x_delay; - t_int x_started; - t_int x_device_open; - t_outlet *x_data_outlet; - t_outlet *x_device_name_outlet; + t_object x_obj; + t_int x_fd; +// unsigned short x_device_number; + t_float x_device_number; + unsigned short vendor_id; // USB idVendor for current device + unsigned short product_id; // USB idProduct for current device + t_int x_has_ff; + void *x_ff_device; + t_clock *x_clock; + t_int x_delay; + t_int x_started; + t_int x_device_open; + t_outlet *x_data_outlet; + t_outlet *x_device_name_outlet; } t_hid; @@ -52,36 +56,43 @@ typedef struct _hid */ t_int hid_instance_count; +extern unsigned short global_debug_level; /*------------------------------------------------------------------------------ * FUNCTION PROTOTYPES FOR DIFFERENT PLATFORMS */ /* support functions */ -void hid_output_event( t_hid *x, char *type, char *code, t_float value ); +void debug_print(t_int debug_level, const char *fmt, ...); +void debug_error(t_hid *x, t_int debug_level, const char *fmt, ...); +void hid_output_event(t_hid *x, char *type, char *code, t_float value); /* generic, cross-platform functions implemented in a separate file for each * platform */ -t_int hid_open_device( t_hid *x, t_int device_number ); -t_int hid_close_device( t_hid *x ); -t_int hid_build_device_list( t_hid* x ); -t_int hid_get_events( t_hid *x ) ; -void hid_print( t_hid* x ); -void hid_platform_specific_free( t_hid *x ); +t_int hid_open_device(t_hid *x, t_int device_number); +t_int hid_close_device(t_hid *x); +void hid_build_device_list(void); +t_int hid_get_events(t_hid *x); +void hid_print(t_hid* x); +void hid_platform_specific_free(t_hid *x); +t_int get_device_number_by_ids(unsigned short vendor_id, unsigned short product_id); +t_int get_device_number_from_usage_list(t_int device_number, + unsigned short usage_page, unsigned short usage); + /* cross-platform force feedback functions */ -t_int hid_ff_autocenter( t_hid *x, t_float value ); -t_int hid_ff_gain( t_hid *x, t_float value ); -t_int hid_ff_motors( t_hid *x, t_float value ); -t_int hid_ff_continue( t_hid *x ); -t_int hid_ff_pause( t_hid *x ); -t_int hid_ff_reset( t_hid *x ); -t_int hid_ff_stopall( t_hid *x ); +t_int hid_ff_autocenter(t_hid *x, t_float value); +t_int hid_ff_gain(t_hid *x, t_float value); +t_int hid_ff_motors(t_hid *x, t_float value); +t_int hid_ff_continue(t_hid *x); +t_int hid_ff_pause(t_hid *x); +t_int hid_ff_reset(t_hid *x); +t_int hid_ff_stopall(t_hid *x); // these are just for testing... -t_int hid_ff_fftest ( t_hid *x, t_float value); -void hid_ff_print( t_hid *x ); +t_int hid_ff_fftest (t_hid *x, t_float value); +void hid_ff_print(t_hid *x); diff --git a/hid_darwin.c b/hid_darwin.c index 6d413f8..f4cbd4d 100644 --- a/hid_darwin.c +++ b/hid_darwin.c @@ -63,7 +63,7 @@ extern t_int hid_instance_count; /*============================================================================== - * FUNCTION PROTOTYPES +h * FUNCTION PROTOTYPES *============================================================================== */ @@ -96,7 +96,7 @@ void convertAxis(pRecElement element, char *linux_type, char *linux_code, char * void convertDarwinElementToLinuxTypeCode(pRecElement element, char *linux_type, char *linux_code) { - t_int button_offset = 0; +// t_int button_offset = 0; switch(element->type) { @@ -202,6 +202,61 @@ pRecDevice hid_get_device_by_number(t_int device_number) return pCurrentHIDDevice; } +t_int get_device_number_by_ids(unsigned short vendor_id, unsigned short product_id) +{ + return(1); +} + +t_int get_device_number_from_usage_list(t_int device_number, + unsigned short usage_page, unsigned short usage) +{ + debug_print(LOG_DEBUG,"get_device_number_from_usage_list"); + + pRecDevice pCurrentHIDDevice; + t_int i; + t_int device_count; + t_int total_devices = 0; + char cstrDeviceName[MAXPDSTRING]; + + if( !HIDHaveDeviceList() ) hid_build_device_list(); + + pCurrentHIDDevice = HIDGetFirstDevice(); + while(pCurrentHIDDevice != NULL) + { + if( (pCurrentHIDDevice->usagePage == usage_page) && + (pCurrentHIDDevice->usage == usage) ) + { + ++total_devices; + } + pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); + } + i = total_devices; + device_count = HIDCountDevices(); + debug_print(LOG_DEBUG,"[hid] %d is less than %d",i,device_number); + pCurrentHIDDevice = HIDGetFirstDevice(); + while( (pCurrentHIDDevice != NULL) && (i > device_number) ) + { + debug_print(LOG_DEBUG,"[hid] %d: %d == %d %d == %d",i, + pCurrentHIDDevice->usagePage, + usage_page, + pCurrentHIDDevice->usage, + usage); + device_count--; + if( (pCurrentHIDDevice->usagePage == usage_page) && + (pCurrentHIDDevice->usage == usage) ) + { + i--; + HIDGetUsageName(pCurrentHIDDevice->usagePage, + pCurrentHIDDevice->usage, + cstrDeviceName); + debug_print(LOG_DEBUG,"[hid]: found a %s at %d: %s %s",cstrDeviceName,i, + pCurrentHIDDevice->manufacturer,pCurrentHIDDevice->product); + } + pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); + } + return(device_count); +} + void hid_build_element_list(t_hid *x) { @@ -210,7 +265,7 @@ void hid_build_element_list(t_hid *x) t_int hid_print_element_list(t_hid *x) { - DEBUG(post("hid_print_element_list");); + debug_print(LOG_DEBUG,"hid_print_element_list"); UInt32 i; pRecElement pCurrentHIDElement; @@ -264,7 +319,7 @@ t_int hid_print_element_list(t_hid *x) void hid_ff_print( t_hid *x ) { - DEBUG(post("hid_ff_print");); + debug_print(LOG_DEBUG,"hid_ff_print"); HRESULT result; UInt32 value; @@ -291,7 +346,7 @@ void hid_print_device_list(t_hid *x) { char cstrDeviceName [256]; t_int i,numdevs; - UInt32 usagePage, usage; +// UInt32 usagePage, usage; pRecDevice pCurrentHIDDevice = NULL; if( HIDHaveDeviceList() ) @@ -303,16 +358,23 @@ void hid_print_device_list(t_hid *x) for(i=0; i < numdevs; i++) { pCurrentHIDDevice = hid_get_device_by_number(i); - post("Device %d: '%s' '%s' version %d",i,pCurrentHIDDevice->manufacturer, - pCurrentHIDDevice->product,pCurrentHIDDevice->version); + debug_print(LOG_INFO,"Device %d: '%s' '%s' version %d", + i, + pCurrentHIDDevice->manufacturer, + pCurrentHIDDevice->product, + pCurrentHIDDevice->version); //usage - HIDGetUsageName (pCurrentHIDDevice->usagePage, + HIDGetUsageName(pCurrentHIDDevice->usagePage, pCurrentHIDDevice->usage, cstrDeviceName); - DEBUG(post(" vendorID: %d productID: %d locID: %d", + debug_print(LOG_INFO,"\t\tcstrDeviceName: %s",cstrDeviceName); + debug_print(LOG_INFO,"\t\tusage page: 0x%04x\tusage: 0x%04x", + pCurrentHIDDevice->usagePage, + pCurrentHIDDevice->usage); + debug_print(LOG_INFO,"\t\tvendorID: 0x%04x\tproductID: 0x%04x\tlocID: 0x%08x", pCurrentHIDDevice->vendorID, pCurrentHIDDevice->productID, - pCurrentHIDDevice->locID);); + pCurrentHIDDevice->locID); } post(""); } @@ -321,7 +383,7 @@ void hid_print_device_list(t_hid *x) void hid_output_device_name(t_hid *x, char *manufacturer, char *product) { char *device_name; - t_symbol *device_name_symbol; +// t_symbol *device_name_symbol; device_name = malloc( strlen(manufacturer) + 1 + strlen(product) + 1 ); // device_name = malloc( 7 + strlen(manufacturer) + 1 + strlen(product) + 1 ); @@ -344,7 +406,7 @@ void hid_output_device_name(t_hid *x, char *manufacturer, char *product) t_int hid_ff_autocenter(t_hid *x, t_float value) { - DEBUG(post("hid_ff_autocenter");); + debug_print(LOG_DEBUG,"hid_ff_autocenter"); HRESULT result; UInt32 autocenter_value; @@ -368,7 +430,7 @@ t_int hid_ff_autocenter(t_hid *x, t_float value) t_int hid_ff_gain(t_hid *x, t_float value) { - DEBUG(post("hid_ff_gain");); + debug_print(LOG_DEBUG,"hid_ff_gain"); HRESULT result; UInt32 ffgain_value; @@ -408,37 +470,37 @@ t_int hid_ff_send_ff_command (t_hid *x, UInt32 ff_command) t_int hid_ff_continue( t_hid *x ) { - DEBUG(post("hid_ff_continue");); + debug_print(LOG_DEBUG,"hid_ff_continue"); return( hid_ff_send_ff_command( x, FFSFFC_CONTINUE ) ); } t_int hid_ff_pause( t_hid *x ) { - DEBUG(post("hid_ff_pause");); + debug_print(LOG_DEBUG,"hid_ff_pause"); return( hid_ff_send_ff_command( x, FFSFFC_PAUSE ) ); } t_int hid_ff_reset( t_hid *x ) { - DEBUG(post("hid_ff_reset");); + debug_print(LOG_DEBUG,"hid_ff_reset"); return( hid_ff_send_ff_command( x, FFSFFC_RESET ) ); } t_int hid_ff_setactuatorsoff( t_hid *x ) { - DEBUG(post("hid_ff_setactuatorsoff");); + debug_print(LOG_DEBUG,"hid_ff_setactuatorsoff"); return( hid_ff_send_ff_command( x, FFSFFC_SETACTUATORSOFF ) ); } t_int hid_ff_setactuatorson( t_hid *x ) { - DEBUG(post("hid_ff_setactuatorson");); + debug_print(LOG_DEBUG,"hid_ff_setactuatorson"); return( hid_ff_send_ff_command( x, FFSFFC_SETACTUATORSON ) ); } t_int hid_ff_stopall( t_hid *x ) { - DEBUG(post("hid_ff_stopall");); + debug_print(LOG_DEBUG,"hid_ff_stopall"); return( hid_ff_send_ff_command( x, FFSFFC_STOPALL ) ); } @@ -461,7 +523,7 @@ t_int hid_ff_motors( t_hid *x, t_float value ) t_int hid_ff_fftest ( t_hid *x, t_float value) { - DEBUG(post("hid_get_events");); + debug_print(LOG_DEBUG,"hid_get_events"); return( 0 ); } @@ -472,7 +534,7 @@ t_int hid_ff_fftest ( t_hid *x, t_float value) t_int hid_get_events(t_hid *x) { - //DEBUG(post("hid_get_events");); + //debug_print(LOG_DEBUG,"hid_get_events"); SInt32 value; pRecDevice pCurrentHIDDevice; @@ -481,10 +543,10 @@ t_int hid_get_events(t_hid *x) char type[256]; char code[256]; char event_output_string[256]; - t_atom event_data[4]; +// t_atom event_data[4]; int event_counter = 0; - Boolean result; +// Boolean result; pCurrentHIDDevice = hid_get_device_by_number(x->x_device_number); @@ -623,28 +685,19 @@ t_int hid_get_events(t_hid *x) t_int hid_open_device(t_hid *x, t_int device_number) { - DEBUG(post("hid_open_device");); + debug_print(LOG_DEBUG,"hid_open_device"); t_int result = 0; pRecDevice pCurrentHIDDevice = NULL; - io_service_t hidDevice = NULL; + io_service_t hidDevice = 0; FFDeviceObjectReference ffDeviceReference = NULL; /* rebuild device list to make sure the list is current */ - if ( ! HIDHaveDeviceList() ) - { - result = (t_int) HIDBuildDeviceList (NULL, NULL); - // returns false if no device found - if(result) - { - error("[hid]: no HID devices found\n"); - return(result); - } - } + if( !HIDHaveDeviceList() ) hid_build_device_list(); pCurrentHIDDevice = hid_get_device_by_number(device_number); - if ( ! HIDIsValidDevice(pCurrentHIDDevice) ) + if( ! HIDIsValidDevice(pCurrentHIDDevice) ) { error("[hid]: device %d is not a valid device\n",device_number); return(1); @@ -658,10 +711,10 @@ t_int hid_open_device(t_hid *x, t_int device_number) hid_build_element_list(x); hidDevice = AllocateHIDObjectFromRecDevice( pCurrentHIDDevice ); - if ( FFIsForceFeedback(hidDevice) == FF_OK ) + if( FFIsForceFeedback(hidDevice) == FF_OK ) { post("\tdevice has Force Feedback support"); - if ( FFCreateDevice(hidDevice,&ffDeviceReference) == FF_OK ) + if( FFCreateDevice(hidDevice,&ffDeviceReference) == FF_OK ) { x->x_has_ff = 1; x->x_ff_device = ffDeviceReference; @@ -684,42 +737,27 @@ t_int hid_open_device(t_hid *x, t_int device_number) t_int hid_close_device(t_hid *x) { - DEBUG(post("hid_close_device");); + debug_print(LOG_DEBUG,"hid_close_device"); t_int result = 0; pRecDevice pCurrentHIDDevice = hid_get_device_by_number(x->x_device_number); HIDDequeueDevice(pCurrentHIDDevice); -// this doesn't seem to be needed at all +// this doesn't seem to be needed at all, but why not use it? // result = HIDCloseReleaseInterface(pCurrentHIDDevice); return(result); } -t_int hid_build_device_list(t_hid *x) +void hid_build_device_list(void) { - DEBUG(post("hid_build_device_list");); + debug_print(LOG_DEBUG,"hid_build_device_list"); - pRecDevice pCurrentHIDDevice; - t_atom device_name_atoms[2]; - -// returns false if no device found - if(HIDBuildDeviceList (NULL, NULL)) - error("[hid]: no HID devices found\n"); - - /* send the [options( msg to set the [hid_menu] to blank */ - outlet_anything( x->x_device_name_outlet, gensym( "options" ),0,NULL ); - - pCurrentHIDDevice = HIDGetFirstDevice(); - while ( pCurrentHIDDevice != NULL ) - { - hid_output_device_name( x, pCurrentHIDDevice->manufacturer, - pCurrentHIDDevice->product ); - pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); - } - - return (0); + debug_print(LOG_WARNING,"[hid] Building device list..."); + if(HIDBuildDeviceList (0, 0)) + post("[hid]: no HID devices found\n"); + debug_print(LOG_WARNING,"[hid] completed device list."); } @@ -737,7 +775,7 @@ void hid_print(t_hid *x) void hid_platform_specific_free(t_hid *x) { - DEBUG(post("hid_platform_specific_free");); + debug_print(LOG_DEBUG,"hid_platform_specific_free"); /* only call this if the last instance is being freed */ if (hid_instance_count < 1) { diff --git a/hid_linux.c b/hid_linux.c index c1dab26..c6ea2f6 100644 --- a/hid_linux.c +++ b/hid_linux.c @@ -132,7 +132,7 @@ t_symbol* hid_convert_linux_keys(__u16 linux_code) void hid_print_element_list(t_hid *x) { - DEBUG(post("hid_print_element_list");); + debug_print(LOG_DEBUG,"hid_print_element_list"); unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)]; // char event_type_string[256]; // char event_code_string[256]; @@ -252,7 +252,7 @@ void hid_print_element_list(t_hid *x) void hid_print_device_list(void) { - DEBUG(post("hid_print_device_list");); + debug_print(LOG_DEBUG,"hid_print_device_list"); int i,fd; char device_output_string[256] = "Unknown"; char dev_handle_name[20] = "/dev/input/event0"; @@ -350,7 +350,7 @@ void hid_ff_print( t_hid *x ) t_int hid_get_events(t_hid *x) { - DEBUG(post("hid_get_events");); + debug_print(LOG_DEBUG,"hid_get_events"); /* for debugging, counts how many events are processed each time hid_read() is called */ DEBUG(t_int event_counter = 0;); @@ -411,7 +411,7 @@ void hid_print(t_hid* x) t_int hid_open_device(t_hid *x, t_int device_number) { - DEBUG(post("hid_open_device");); + debug_print(LOG_DEBUG,"hid_open_device"); char device_name[256] = "Unknown"; char dev_handle_name[20] = "/dev/input/event0"; @@ -453,7 +453,7 @@ t_int hid_open_device(t_hid *x, t_int device_number) */ t_int hid_close_device(t_hid *x) { - DEBUG(post("hid_close_device");); + debug_print(LOG_DEBUG,"hid_close_device"); if (x->x_fd <0) return 0; else @@ -462,7 +462,7 @@ t_int hid_close_device(t_hid *x) t_int hid_build_device_list(t_hid *x) { - DEBUG(post("hid_build_device_list");); + debug_print(LOG_DEBUG,"hid_build_device_list"); /* the device list should be refreshed here */ /* * since in GNU/Linux the device list is the input event devices diff --git a/hid_windows.c b/hid_windows.c index da5060d..7bc387c 100755 --- a/hid_windows.c +++ b/hid_windows.c @@ -72,7 +72,7 @@ void hid_build_element_list(t_hid *x) t_int hid_print_element_list(t_hid *x) { - DEBUG(post("hid_print_element_list");); + debug_print(LOG_DEBUG,"hid_print_element_list"); return (0); @@ -248,7 +248,7 @@ void hid_ff_print( t_hid *x ) t_int hid_get_events(t_hid *x) { - //DEBUG(post("hid_get_events");); + //debug_print(LOG_DEBUG,"hid_get_events"); return (0); } @@ -256,7 +256,7 @@ t_int hid_get_events(t_hid *x) t_int hid_open_device(t_hid *x, t_int device_number) { - DEBUG(post("hid_open_device");); + debug_print(LOG_DEBUG,"hid_open_device"); t_int result = 0; @@ -266,7 +266,7 @@ t_int hid_open_device(t_hid *x, t_int device_number) t_int hid_close_device(t_hid *x) { - DEBUG(post("hid_close_device");); + debug_print(LOG_DEBUG,"hid_close_device"); t_int result = 0; @@ -276,7 +276,7 @@ t_int hid_close_device(t_hid *x) t_int hid_build_device_list(t_hid *x) { - DEBUG(post("hid_build_device_list");); + debug_print(LOG_DEBUG,"hid_build_device_list"); /* * The Windows DDK "hid.dll" has to be loaded manually because Windows gets @@ -321,7 +321,7 @@ void hid_print(t_hid *x) void hid_platform_specific_free(t_hid *x) { - DEBUG(post("hid_platform_specific_free");); + debug_print(LOG_DEBUG,"hid_platform_specific_free"); /* only call this if the last instance is being freed */ if (hid_instance_count < 1) { diff --git a/mouse.pd b/mouse.pd index cf8e9a9..60cd067 100644 --- a/mouse.pd +++ b/mouse.pd @@ -1,4 +1,4 @@ -#N canvas 212 125 775 600 10; +#N canvas 212 125 783 608 10; #X obj 130 18 inlet; #X obj 25 521 outlet; #X obj 179 521 outlet; @@ -26,7 +26,7 @@ ; #X text 288 576 released under the GNU GPL; #X text 484 576 $Author: eighthave $; -#X text 484 563 $Revision: 1.6 $; +#X text 484 563 $Revision: 1.7 $; #X msg 193 472 0; #X obj 130 63 route poll; #X msg 100 151 poll \$1; @@ -37,7 +37,6 @@ #X msg 33 472 0; #X text 41 489 zero when no motion; #X obj 43 48 loadbang; -#X msg 43 71 25; #X obj 213 401 delay; #X obj 207 444 metro; #X msg 213 422 1; @@ -50,6 +49,7 @@ #X msg 35 422 0; #X obj 108 378 * 2; #X obj 258 378 * 2; +#X msg 43 71 5; #X connect 0 0 28 0; #X connect 6 0 5 0; #X connect 7 0 6 0; @@ -57,7 +57,7 @@ #X connect 13 0 12 0; #X connect 14 0 13 0; #X connect 15 0 1 0; -#X connect 15 0 43 0; +#X connect 15 0 42 0; #X connect 16 0 2 0; #X connect 16 0 33 0; #X connect 17 0 15 0; @@ -70,25 +70,25 @@ #X connect 28 0 30 0; #X connect 28 1 20 0; #X connect 29 0 20 0; -#X connect 31 0 49 0; +#X connect 31 0 48 0; #X connect 32 0 29 0; -#X connect 33 0 38 0; -#X connect 33 0 41 0; +#X connect 33 0 37 0; +#X connect 33 0 40 0; #X connect 34 0 1 0; -#X connect 36 0 37 0; -#X connect 37 0 30 0; -#X connect 38 0 40 0; -#X connect 39 0 27 0; -#X connect 40 0 39 0; -#X connect 41 0 39 0; -#X connect 42 0 48 0; -#X connect 43 0 44 0; -#X connect 43 0 47 0; -#X connect 44 0 46 0; -#X connect 45 0 34 0; -#X connect 46 0 45 0; -#X connect 47 0 45 0; -#X connect 48 0 44 1; -#X connect 48 0 45 1; -#X connect 49 0 38 1; -#X connect 49 0 39 1; +#X connect 36 0 49 0; +#X connect 37 0 39 0; +#X connect 38 0 27 0; +#X connect 39 0 38 0; +#X connect 40 0 38 0; +#X connect 41 0 47 0; +#X connect 42 0 43 0; +#X connect 42 0 46 0; +#X connect 43 0 45 0; +#X connect 44 0 34 0; +#X connect 45 0 44 0; +#X connect 46 0 44 0; +#X connect 47 0 43 1; +#X connect 47 0 44 1; +#X connect 48 0 37 1; +#X connect 48 0 38 1; +#X connect 49 0 30 0; -- cgit v1.2.1