From f6833c650cd755a7c9a142bf667baff8add0ea31 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Wed, 9 Aug 2006 01:14:06 +0000 Subject: added help file that shows how to use with [hid] (almost complete), and parseeventnodenum.c svn path=/trunk/externals/input_noticer/; revision=5527 --- INSTALL.TXT | 2 +- Makefile | 30 ++++++++++++------------ README.TXT | 7 ++++++ input_noticer-help.pd | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ input_noticer.c | 4 ++-- noticer_test.pd | 23 ++++++++++-------- parseeventnodenum.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 166 insertions(+), 28 deletions(-) create mode 100644 input_noticer-help.pd create mode 100644 parseeventnodenum.c diff --git a/INSTALL.TXT b/INSTALL.TXT index f7eefed..1d2afa8 100644 --- a/INSTALL.TXT +++ b/INSTALL.TXT @@ -23,5 +23,5 @@ you plug, or un-plug a joystick. Once you've got your libraries sorted out, to compile and install, you should first modify the Makefile to suit your system. Then you can type: -make +make pd_linux make install_noticer diff --git a/Makefile b/Makefile index 12401f6..5c6dde5 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,30 @@ -CC=gcc +CC=gcc -pd_linux: input_noticer.pd_linux +pd_linux: input_noticer.pd_linux parseeventnodenum.pd_linux clean: ; rm -f *.pd_linux *.o *~ - -# installs all compiled externals. -# you'll want to change this to match where your externals live -install: ; sudo cp *.pd_linux /usr/lib/pd/extra - -# installs the input_noticer -# you'll want to change this to match where your externals live -install_noticer: ; cp input_noticer.pd_linux /usr/lib/pd/extra + +# installs all compiled externals. +# you'll want to change this to match where your externals live +install: ; sudo cp *.pd_linux /usr/lib/pd/extra + +# installs the input_noticer +# you'll want to change this to match where your externals live +install_noticer: ; cp input_noticer.pd_linux /usr/lib/pd/extra # ----------------------- LINUX i386 ----------------------- .SUFFIXES: .pd_linux - -LINUXLDFLAGS = `pkg-config --libs glib-2.0 hal dbus-glib-1` -lpthread -lgthread-2.0 -lglib-2.0 -# LINUXLDFLAGS = `pkg-config --libs glib-2.0 hal dbus-glib-1 gthread-2.0` + +LINUXLDFLAGS = `pkg-config --libs glib-2.0 hal dbus-glib-1` -lpthread -lgthread-2.0 -lglib-2.0 +# LINUXLDFLAGS = `pkg-config --libs glib-2.0 hal dbus-glib-1 gthread-2.0` LINUXCFLAGS = -DUNIX -DPD -O2 -funroll-loops -fomit-frame-pointer \ -Wall -W -Wshadow -Wstrict-prototypes -Werror \ - -Wno-unused -Wno-parentheses -Wno-switch \ + -Wno-unused -Wno-parentheses -Wno-switch \ `pkg-config --cflags --libs glib-2.0 hal dbus-glib-1 gthread-2.0` -LINUXINCLUDE = -I/usr/local/lib/pd/include -I/usr/lib/pd/src -I/usr/local/include +LINUXINCLUDE = -I/usr/local/lib/pd/include -I/usr/lib/pd/src -I/usr/local/include .c.pd_linux: $(CC) $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c diff --git a/README.TXT b/README.TXT index b92bb67..1207c9f 100644 --- a/README.TXT +++ b/README.TXT @@ -39,6 +39,13 @@ source test_noticer_compile.sh Then, run test_noticer, and when it's running you should see messages when you plug, or un-plug a joystick. +dmerrill@dmerrill-t40:~/externals/input_noticer$ ./test_noticer +device added, udi = /org/freedesktop/Hal/devices/usb_device_45e_28_noserial +device added, udi = /org/freedesktop/Hal/devices/usb_device_45e_28_noserial_if0 +device added, udi = /org/freedesktop/Hal/devices/usb_device_45e_28_noserial_usbraw +device added, udi = /org/freedesktop/Hal/devices/usb_device_45e_28_noserial_if0_logicaldev_input +found the joystick at: /dev/input/event6 + Thanks to Dan Willmans, Seth Nickell, and David Zeuthen for their invaluable help with the whole dbus/hal part. Also, thanks to Hans-Christoph Steiner for his help with (and creation of) the joystick external. diff --git a/input_noticer-help.pd b/input_noticer-help.pd new file mode 100644 index 0000000..38da2ab --- /dev/null +++ b/input_noticer-help.pd @@ -0,0 +1,63 @@ +#N canvas 0 25 1367 915 10; +#X obj 49 93 print A; +#X obj 49 70 route 0 1; +#X obj 107 140 print C; +#X obj 78 116 print B; +#X obj 49 10 loadbang; +#X obj 49 45 input_noticer joystick "SideWinder Dual Strike"; +#X obj 110 10 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X text 549 12 INSTANTIATION ARGUMENTS:; +#X text 549 31 1) device type: for instance \, as I have entered here: +joystick; +#X text 658 182 This external takes the "joystick" that I have entered +\, and creates "input.joystick" from it \, and then asks HAL to look +for all devices that have that capability.; +#X text 659 275 In linux \, this references the HAL info.product field +for the device. The input_noticer will iterate through all devices +that HAL returns with the given Capabilities field (see above) \, and +look for the user-supplied substring. The corresponding linux.device_file +field is returned \, which will be something like "/dev/input/event6". +This can be used to connect to objects like [hid].; +#X text 127 10 <- BANG to scan for devices \, outputs any that are +found; +#X text 59 469 USING input_noticer output:; +#X text 63 489 Output from input_noticer is a list \, like 0 \, /dev/input/event5 +1 \, /dev/input/event6; +#X text 61 535 Use [route] to separate the messages \, and you'll have +just the second list element \, like /dev/input/event5; +#X text 109 611 5 means /dev/input/event5; +#X text 661 60 In linux \, this references the HAL (Hardware Abstraction +Layer) Capabilities field for the device. You can have a look at what +your favorite device has by using the HAL Device Manager \, and look +at the "Device" tab of the most specific entry for your input device. +In my case \, the device tree for my joystick looks like: "SideWinder +Dual Strike" -> "USB Hid Interface" -> "Microsoft SideWinder Dual Strike +USB Version 1.0". Capabilities listed are: input \, input.joystick +; +#X text 549 236 2) product substring: for instance \, as I have entered +here: "SideWinder Dual Strike"; +#X text 61 568 To feed this to [hid] \, you'll need to strip the number +from the end \, since [hid] currently wants just the number \, and +interprets the number as follows:; +#X obj 7 166 parseeventnodenum; +#X floatatom 7 188 5 0 0 0 - - -; +#X obj 37 280 hid 0; +#X msg 37 236 open \$1; +#X obj 37 301 print joystick; +#X obj 7 207 t b f; +#X msg -8 235 start; +#X connect 1 0 0 0; +#X connect 1 0 19 0; +#X connect 1 1 3 0; +#X connect 1 2 2 0; +#X connect 4 0 5 0; +#X connect 5 0 1 0; +#X connect 6 0 5 0; +#X connect 19 0 20 0; +#X connect 20 0 24 0; +#X connect 21 0 23 0; +#X connect 22 0 21 0; +#X connect 24 0 25 0; +#X connect 24 1 22 0; +#X connect 25 0 21 0; diff --git a/input_noticer.c b/input_noticer.c index ef2c91a..a462f39 100644 --- a/input_noticer.c +++ b/input_noticer.c @@ -28,7 +28,7 @@ #include #include "input_noticer.h" -static char *version = "$Revision: 1.1.1.1 $"; +static char *version = "$Revision: 1.2 $"; #define MAX_INPUT_DEVICES 32 /*------------------------------------------------------------------------------ @@ -261,7 +261,7 @@ static char *remove_quotes(char *input_str) char *rv, *tp; unsigned int i; - post ("removing quotes from %s", input_str); + // post ("removing quotes from %s", input_str); if (input_str != NULL) { diff --git a/noticer_test.pd b/noticer_test.pd index e001bc5..4ea2dcc 100644 --- a/noticer_test.pd +++ b/noticer_test.pd @@ -1,12 +1,15 @@ #N canvas 0 0 450 300 10; -#X obj 108 188 print A; -#X obj 49 45 input_noticer joystick SideWinder; -#X obj 133 137 route 0 1; -#X obj 197 186 print C; -#X obj 149 215 print B; -#X obj 50 22 loadbang; -#X connect 1 0 2 0; -#X connect 2 0 0 0; -#X connect 2 1 4 0; -#X connect 2 2 3 0; +#X obj 49 93 print A; +#X obj 49 70 route 0 1; +#X obj 107 140 print C; +#X obj 78 116 print B; +#X obj 49 10 loadbang; +#X obj 49 45 input_noticer joystick "SideWinder Dual Strike"; +#X obj 110 10 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X connect 1 0 0 0; +#X connect 1 1 3 0; +#X connect 1 2 2 0; +#X connect 4 0 5 0; #X connect 5 0 1 0; +#X connect 6 0 5 0; diff --git a/parseeventnodenum.c b/parseeventnodenum.c new file mode 100644 index 0000000..e8ddae1 --- /dev/null +++ b/parseeventnodenum.c @@ -0,0 +1,65 @@ +/* + * author: David Merrill + * based on code from Tom Schouten, found online at: + * http://lists.puredata.info/pipermail/pd-list/2002-02/004871.html + */ + +#include "m_pd.h" +#include + +#define MAXHEAD 1024 + +typedef struct{ + char buffer[MAXHEAD]; +} t_parseeventnodenum_data; + +typedef struct parseeventnodenum +{ + t_object t_ob; + t_outlet *x_out; + t_outlet *x_out_error; +} t_parseeventnodenum; + +void penn_any_method(t_parseeventnodenum *x, t_symbol *s, int argc, t_atom *argv) +{ + char* p = s->s_name; + int eventnodenum = -1, rv = 0; + + if (sscanf(p,"/dev/input/event%i",&eventnodenum)) { + + // success, send the float to the left outlet + outlet_float(x->x_out, eventnodenum); + } else { + + // failure, send the input symbol to the right outlet + outlet_symbol(x->x_out_error, gensym(p)); + } +} + +void parseeventnodenum_free(void) +{ +} + +t_class *parseeventnodenum_class; + +void *parseeventnodenum_new(void) +{ + t_parseeventnodenum *x = (t_parseeventnodenum *)pd_new(parseeventnodenum_class); + + // left outlet is where the parsed number will come out + x->x_out = outlet_new(&x->t_ob, gensym("float")); + + // right outlet is where the original string will come out if an error occured + x->x_out_error = outlet_new(&x->t_ob, gensym("symbol")); + + + return (void *)x; +} + +void parseeventnodenum_setup(void) +{ + parseeventnodenum_class = class_new(gensym("parseeventnodenum"), (t_newmethod)parseeventnodenum_new, + (t_method)parseeventnodenum_free, sizeof(t_parseeventnodenum), 0, 0); + class_addanything(parseeventnodenum_class, penn_any_method); +} + -- cgit v1.2.1