From 2edc4c4bc4f675566a4d3a640310988659654b9e Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 22 Sep 2006 05:05:51 +0000 Subject: fixed pointer bug that was preventing proper creation of the element array. Now it outputs data properly on Linux svn path=/trunk/externals/hcs/hid/; revision=5998 --- doc/hid-help.pd | 258 +++++++++++++++++++++++++++++++++----------------------- hid.c | 6 +- hid_linux.c | 29 ++++--- 3 files changed, 172 insertions(+), 121 deletions(-) diff --git a/doc/hid-help.pd b/doc/hid-help.pd index fd41bf4..c201d21 100644 --- a/doc/hid-help.pd +++ b/doc/hid-help.pd @@ -1,8 +1,8 @@ -#N canvas 59 45 913 587 10; +#N canvas 157 38 913 587 10; #X floatatom 27 439 5 0 0 0 - - -; #X floatatom 83 439 5 0 0 0 - - -; #X floatatom 63 395 6 0 0 0 - - -; -#X obj 129 77 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 0 25 +#X obj 191 164 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 0 25 ; #X floatatom 571 340 12 0 0 1 value - -; #X symbolatom 531 356 15 0 0 1 event_code - -; @@ -26,12 +26,12 @@ #X floatatom 138 343 5 0 0 1 ev_syn - -; #X obj 111 342 +; #X msg 111 322 1; -#X msg 402 102 close; -#X msg 402 81 refresh; -#X text 463 79 refresh device list; +#X msg 374 140 close; +#X msg 374 119 refresh; +#X text 435 117 refresh device list; #X text 537 487 For more info:; #X text 266 557 released under the GNU GPL; -#X text 472 544 $Revision: 1.26 $$Date: 2006-08-25 01:41:49 $; +#X text 472 544 $Revision: 1.27 $$Date: 2006-09-22 05:05:51 $; #X text 473 557 $Author: eighthave $; #X msg 436 201 poll 20; #X msg 374 201 poll 2; @@ -246,10 +246,10 @@ of it could change without notice !!!; #X floatatom 140 439 5 0 0 0 - - -; #X obj 421 394 route abs_hat0x abs_hat0y abs_hat1x abs_hat1y; #X floatatom 421 416 7 0 0 0 - - -; -#X msg 402 123 print; +#X msg 374 161 print; #X obj 304 250 hid 0; -#X text 465 103 close the device; -#X text 465 124 print the device and element lists; +#X text 437 141 close the device; +#X text 437 162 print the device and element lists; #X text 9 212 Any non-zero value starts polling \,; #X text 8 225 0 stops the polling. If the number; #X text 9 238 is greater than 1 \, then the poll; @@ -257,10 +257,6 @@ of it could change without notice !!!; #X obj 27 419 route rel_x rel_y rel_z rel_wheel; #X floatatom 196 439 5 0 0 0 - - -; #X obj 492 321 unpack s s f; -#X msg 258 110 open \$1; -#X obj 258 92 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1 --1 0; -#X floatatom 247 111 1 0 0 0 - - -; #X text 298 346 event_type event_code value; #X obj 63 374 route abs_x abs_y abs_z abs_rx abs_ry abs_rz abs_throttle ; @@ -314,12 +310,9 @@ btn_8 btn_9 btn_10 btn_11 btn_12 btn_13 btn_14 btn_15; #X obj 459 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 262 298 cyclone/prepend set; -#X msg 37 151 debug \$1; -#X obj 37 129 hradio 15 1 1 10 empty empty empty 0 -6 0 8 -262144 -1 --1 5; -#X obj 646 486 pddp/pddp_open all_about_hid; +#X msg 25 155 debug 0; #X msg 298 145 info; -#N canvas 477 37 411 235 see 0; +#N canvas 743 25 411 235 see 0; #N canvas 108 318 543 264 route 0; #X obj 27 14 inlet; #X obj 72 226 outlet; @@ -334,42 +327,42 @@ btn_8 btn_9 btn_10 btn_11 btn_12 btn_13 btn_14 btn_15; #X obj 372 204 symbol; #X obj 372 226 outlet; #X obj 122 225 outlet; -#X obj 26 63 route open device total poll product manufacturer transport -type vendorID productID; #X obj 422 204 symbol; #X obj 422 226 outlet; #X obj 472 204 symbol; #X obj 472 226 outlet; -#X connect 0 0 13 0; +#X obj 26 63 route open device poll total product manufacturer transport +type vendorID productID; +#X connect 0 0 17 0; #X connect 4 0 5 0; #X connect 6 0 7 0; #X connect 8 0 9 0; #X connect 10 0 11 0; -#X connect 13 0 2 0; -#X connect 13 1 1 0; -#X connect 13 2 12 0; -#X connect 13 3 3 0; -#X connect 13 4 4 0; -#X connect 13 5 6 0; -#X connect 13 6 8 0; -#X connect 13 7 10 0; -#X connect 13 8 14 0; -#X connect 13 9 16 0; -#X connect 14 0 15 0; -#X connect 16 0 17 0; -#X restore 55 66 pd route info; -#X obj 32 97 tgl 15 0 empty empty open 0 -6 0 8 -262144 -1 -1 0 1; -#X obj 61 23 inlet; -#X obj 74 44 print info; -#X symbolatom 255 94 0 0 0 0 productID - -; -#X symbolatom 255 113 0 0 0 0 vendorID - -; -#X symbolatom 255 152 0 0 0 0 transport - -; -#X symbolatom 255 172 0 0 0 0 manufacturer - -; -#X symbolatom 137 193 0 0 0 0 product - -; -#X floatatom 48 141 5 0 0 0 device - -; -#X floatatom 48 163 5 0 0 0 poll - -; -#X symbolatom 255 132 0 0 0 0 type - -; -#X floatatom 48 183 5 0 0 0 total - -; +#X connect 13 0 14 0; +#X connect 15 0 16 0; +#X connect 17 0 2 0; +#X connect 17 1 1 0; +#X connect 17 2 12 0; +#X connect 17 3 3 0; +#X connect 17 4 4 0; +#X connect 17 5 6 0; +#X connect 17 6 8 0; +#X connect 17 7 10 0; +#X connect 17 8 13 0; +#X connect 17 9 15 0; +#X restore 117 70 pd route info; +#X obj 81 96 tgl 15 0 empty empty open 0 -6 0 8 -262144 -1 -1 1 1; +#X obj 110 22 inlet; +#X obj 123 43 print info; +#X symbolatom 304 93 0 0 0 0 productID - -; +#X symbolatom 304 112 0 0 0 0 vendorID - -; +#X symbolatom 304 151 0 0 0 0 transport - -; +#X symbolatom 304 171 0 0 0 0 manufacturer - -; +#X symbolatom 186 192 0 0 0 0 product - -; +#X floatatom 97 140 5 0 0 0 device - -; +#X floatatom 97 162 5 0 0 0 poll - -; +#X symbolatom 304 131 0 0 0 0 type - -; +#X floatatom 97 182 5 0 0 0 total - -; #X connect 0 0 1 0; #X connect 0 1 9 0; #X connect 0 2 10 0; @@ -382,7 +375,7 @@ type vendorID productID; #X connect 0 9 4 0; #X connect 2 0 0 0; #X connect 2 0 3 0; -#X restore 418 271 pd see device info; +#X restore 420 271 pd see device info; #N canvas 0 22 380 450 open 0; #X obj 77 61 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1 -1 0; @@ -440,20 +433,20 @@ IDs (it is not case sensitive):; #X connect 2 0 4 0; #X connect 7 0 4 0; #X restore 174 37 pd open by vendor/product ID; -#N canvas 114 93 527 436 test 0; -#X obj 122 5 inlet; -#X obj 66 64 route DESKTOP; -#X obj 65 118 route DESKTOP57; -#X obj 48 167 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +#N canvas 114 93 467 346 test 0; +#X obj 144 45 inlet; +#X obj 88 104 route DESKTOP; +#X obj 87 158 route DESKTOP57; +#X obj 70 207 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; -#X floatatom 73 172 5 0 0 0 - - -; -#X obj 126 175 spigot; -#X obj 124 216 print test; -#X obj 167 152 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +#X floatatom 95 212 5 0 0 0 - - -; +#X obj 148 215 spigot; +#X obj 146 256 print test; +#X obj 189 192 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; -#X obj 270 82 spigot; -#X obj 268 123 print test; -#X obj 311 59 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +#X obj 292 122 spigot; +#X obj 290 163 print test; +#X obj 333 99 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 ; #X connect 0 0 1 0; #X connect 0 0 8 0; @@ -467,9 +460,67 @@ IDs (it is not case sensitive):; #X connect 10 0 8 1; #X restore 197 303 pd test; #X msg 504 201 poll 200; -#X msg 261 317 key btn_0 0; +#X msg 261 317 key key_leftctrl 1; #X text 49 543 (C) Copyright 2004 Hans-Christoph Steiner ; +#N canvas 162 133 570 420 serin 0; +#X obj 209 61 cnv 15 15 15 empty \$0-debug-canvas 0 4 8 0 14 -233017 +-1 0; +#X obj 60 61 hradio 15 1 1 10 empty empty empty 0 -6 0 8 -261689 -1 +-1 0; +#X obj 60 13 inlet; +#X msg 200 202 label \$1; +#X obj 200 180 makefilename %d; +#X obj 59 108 int; +#X obj 59 337 outlet; +#X msg 201 306 set \$1 \$2; +#X obj 59 266 trigger bang anything; +#X obj 201 286 list; +#X msg 60 210 debug \$1; +#X obj 200 225 send \$0-debug-canvas; +#X connect 1 0 5 0; +#X connect 2 0 1 0; +#X connect 3 0 11 0; +#X connect 4 0 3 0; +#X connect 5 0 4 0; +#X connect 5 0 10 0; +#X connect 7 0 6 0; +#X connect 8 0 6 0; +#X connect 8 1 9 0; +#X connect 9 0 7 0; +#X connect 10 0 8 0; +#X coords 0 -1 1 1 165 17 1 60 60; +#X restore 25 134 pd serin; +#X msg 262 114 open 1; +#N canvas 162 133 570 420 serin 0; +#X obj 209 61 cnv 15 15 15 empty \$0-open-canvas 1 4 8 0 14 -233017 +-1 0; +#X obj 60 61 hradio 15 1 1 10 empty empty empty 0 -6 0 8 -225271 -1 +-1 1; +#X obj 60 13 inlet; +#X msg 200 202 label \$1; +#X obj 200 180 makefilename %d; +#X obj 59 108 int; +#X obj 59 337 outlet; +#X msg 201 306 set \$1 \$2; +#X obj 59 266 trigger bang anything; +#X obj 201 286 list; +#X msg 60 210 open \$1; +#X obj 200 225 send \$0-open-canvas; +#X connect 1 0 5 0; +#X connect 2 0 1 0; +#X connect 3 0 11 0; +#X connect 4 0 3 0; +#X connect 5 0 4 0; +#X connect 5 0 10 0; +#X connect 7 0 6 0; +#X connect 8 0 6 0; +#X connect 8 1 9 0; +#X connect 9 0 7 0; +#X connect 10 0 8 0; +#X coords 0 -1 1 1 165 17 1 60 60; +#X restore 262 93 pd serin; +#X obj 646 486 pddp/open all_about_hid; #X connect 3 0 45 0; #X connect 22 0 23 1; #X connect 23 0 22 0; @@ -478,21 +529,21 @@ IDs (it is not case sensitive):; #X connect 26 0 45 0; #X connect 32 0 45 0; #X connect 33 0 45 0; -#X connect 36 0 86 0; +#X connect 36 0 83 0; #X connect 36 1 52 0; -#X connect 36 2 59 0; +#X connect 36 2 56 0; #X connect 36 3 24 0; #X connect 42 0 43 0; -#X connect 42 1 61 0; -#X connect 42 2 63 0; -#X connect 42 3 65 0; -#X connect 43 0 60 0; +#X connect 42 1 58 0; +#X connect 42 2 60 0; +#X connect 42 3 62 0; +#X connect 43 0 57 0; #X connect 44 0 45 0; #X connect 45 0 36 0; #X connect 45 0 54 0; -#X connect 45 0 89 0; -#X connect 45 0 97 0; -#X connect 45 1 94 0; +#X connect 45 0 86 0; +#X connect 45 0 92 0; +#X connect 45 1 89 0; #X connect 52 0 0 0; #X connect 52 1 1 0; #X connect 52 2 41 0; @@ -500,40 +551,39 @@ IDs (it is not case sensitive):; #X connect 54 0 6 0; #X connect 54 1 5 0; #X connect 54 2 4 0; -#X connect 55 0 45 0; -#X connect 56 0 55 0; -#X connect 56 0 57 0; -#X connect 59 0 2 0; -#X connect 59 1 67 0; -#X connect 59 2 68 0; -#X connect 59 3 69 0; -#X connect 59 4 70 0; -#X connect 59 5 71 0; -#X connect 59 6 72 0; -#X connect 59 7 42 0; -#X connect 61 0 62 0; -#X connect 63 0 64 0; -#X connect 65 0 66 0; -#X connect 86 0 37 0; -#X connect 86 1 73 0; -#X connect 86 2 74 0; -#X connect 86 3 75 0; -#X connect 86 4 76 0; -#X connect 86 5 77 0; -#X connect 86 6 78 0; -#X connect 86 7 79 0; -#X connect 86 8 80 0; -#X connect 86 9 81 0; -#X connect 86 10 82 0; -#X connect 86 11 83 0; -#X connect 86 12 84 0; -#X connect 86 13 85 0; -#X connect 86 14 87 0; -#X connect 86 15 88 0; -#X connect 89 0 99 0; +#X connect 56 0 2 0; +#X connect 56 1 64 0; +#X connect 56 2 65 0; +#X connect 56 3 66 0; +#X connect 56 4 67 0; +#X connect 56 5 68 0; +#X connect 56 6 69 0; +#X connect 56 7 42 0; +#X connect 58 0 59 0; +#X connect 60 0 61 0; +#X connect 62 0 63 0; +#X connect 83 0 37 0; +#X connect 83 1 70 0; +#X connect 83 2 71 0; +#X connect 83 3 72 0; +#X connect 83 4 73 0; +#X connect 83 5 74 0; +#X connect 83 6 75 0; +#X connect 83 7 76 0; +#X connect 83 8 77 0; +#X connect 83 9 78 0; +#X connect 83 10 79 0; +#X connect 83 11 80 0; +#X connect 83 12 81 0; +#X connect 83 13 82 0; +#X connect 83 14 84 0; +#X connect 83 15 85 0; +#X connect 86 0 94 0; +#X connect 87 0 45 0; +#X connect 88 0 45 0; #X connect 90 0 45 0; -#X connect 91 0 90 0; +#X connect 91 0 45 0; #X connect 93 0 45 0; -#X connect 95 0 45 0; -#X connect 96 0 45 0; -#X connect 98 0 45 0; +#X connect 96 0 87 0; +#X connect 97 0 45 0; +#X connect 98 0 97 0; diff --git a/hid.c b/hid.c index 4cc120f..5711ea3 100644 --- a/hid.c +++ b/hid.c @@ -35,8 +35,8 @@ * LOCAL DEFINES */ -//#define DEBUG(x) -#define DEBUG(x) x +#define DEBUG(x) +//#define DEBUG(x) x unsigned short global_debug_level = 0; @@ -224,7 +224,7 @@ void hid_output_event(t_hid *x, t_hid_element *output_data) SETFLOAT(event_data + 2, output_data->value); outlet_anything(x->x_data_outlet,output_data->type,3,event_data); #endif - } + } } diff --git a/hid_linux.c b/hid_linux.c index f69e664..ff298ef 100644 --- a/hid_linux.c +++ b/hid_linux.c @@ -15,8 +15,8 @@ #include "hid.h" -//#define DEBUG(x) -#define DEBUG(x) x +#define DEBUG(x) +//#define DEBUG(x) x #define LINUX_BLOCK_DEVICE "/dev/input/event" @@ -25,12 +25,11 @@ * from evtest.c from the ff-utils package */ +/* from asm/types.h and linux/input.h __kernel__ sections */ #define BITS_PER_LONG (sizeof(long) * 8) -#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) -#define OFF(x) ((x)%BITS_PER_LONG) -#define BIT(x) (1UL<> OFF(bit)) & 1) +#define test_bit(bit, array) ((array[LONG(bit)] >> (bit%BITS_PER_LONG)) & 1) /* @@ -294,7 +293,7 @@ void hid_print_device_list(void) static void hid_build_element_list(t_hid *x) { - post("hid_build_element_list"); + debug_print(LOG_DEBUG,"hid_build_element_list"); unsigned long element_bitmask[EV_MAX][NBITS(KEY_MAX)]; uint8_t abs_bitmask[ABS_MAX/8 + 1]; struct input_absinfo abs_features; @@ -304,7 +303,6 @@ static void hid_build_element_list(t_hid *x) element_count[x->x_device_number] = 0; if( x->x_fd ) { - new_element = getbytes(sizeof(t_hid_element)); /* get bitmask representing supported elements (axes, keys, etc.) */ memset(element_bitmask, 0, sizeof(element_bitmask)); if( ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), element_bitmask[0]) < 0 ) @@ -316,8 +314,6 @@ static void hid_build_element_list(t_hid *x) { if(test_bit(i, element_bitmask[0])) { - new_element->linux_type = i; - new_element->type = gensym(ev[i] ? ev[i] : "?"); /* get bitmask representing supported button types */ ioctl(x->x_fd, EVIOCGBIT(i, KEY_MAX), element_bitmask[i]); /* cycle through all possible event codes (axes, keys, etc.) @@ -326,6 +322,7 @@ static void hid_build_element_list(t_hid *x) */ for(j = 0; j < KEY_MAX; j++) { + new_element = getbytes(sizeof(t_hid_element)); if( (i == EV_ABS) && (test_bit(j, abs_bitmask)) ) { /* this means that the bit is set in the axes list */ @@ -341,6 +338,8 @@ static void hid_build_element_list(t_hid *x) } if(test_bit(j, element_bitmask[i])) { + new_element->linux_type = i; /* the int from linux/input.h */ + new_element->type = gensym(ev[i] ? ev[i] : "?"); /* the symbol */ new_element->linux_code = j; if((i == EV_KEY) && (j >= BTN_MISC) && (j < KEY_OK) ) { @@ -378,7 +377,7 @@ static void hid_build_element_list(t_hid *x) void hid_get_events(t_hid *x) { - debug_print(LOG_DEBUG,"hid_get_events"); + debug_print(9,"hid_get_events"); /* for debugging, counts how many events are processed each time hid_read() is called */ DEBUG(t_int event_counter = 0;); @@ -398,12 +397,14 @@ void hid_get_events(t_hid *x) { for( i=0; i < element_count[x->x_device_number]; ++i ) { - output_element = element[x->x_device_number][i]; + output_element = element[x->x_device_number][i]; if( (hid_input_event.type == output_element->linux_type) && \ (hid_input_event.code == output_element->linux_code) ) { output_element->value = hid_input_event.value; - post("output %d",output_element->value); + debug_print(9,"i: %d linux_type: %d linux_code: %d", i, + output_element->linux_type, output_element->linux_code); + debug_print(9,"value to output: %d",output_element->value); break; } } @@ -414,7 +415,7 @@ void hid_get_events(t_hid *x) } DEBUG( if(event_counter > 0) - post("output %d events",event_counter); + debug_print(8,"output %d events",event_counter); ); return; -- cgit v1.2.1