aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2006-12-08 06:33:26 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2006-12-08 06:33:26 +0000
commit732d359c182794df20e78b4e00db4c5bf123dfec (patch)
tree34e8012dff92877d5edd7bbe73c57587496fa4c6
parent33ed52de6e66c8767044454b1cf26de1e1b569a7 (diff)
- laid out new event labeling scheme based more on USB HID rather than Linux
input.h. It works on my devices on my Mac OS X. I probably broke Linux support. The scheme is in a new file, hidio_types.c - all event symbols except the vendor-defined usage are generated in hidio_setup(). The symbols for vendor-defined usages are generated when the device's element list is built. - changed macros to work cleanly when compiled on Windows using MinGW gcc - fixed up help file to better represent the state of things (still could be much better) svn path=/trunk/externals/io/hidio/; revision=6718
-rw-r--r--Makefile11
-rw-r--r--hidio-help.pd327
-rw-r--r--hidio.c252
-rw-r--r--hidio.h83
-rw-r--r--hidio_darwin.c98
-rw-r--r--hidio_linux.c6
-rw-r--r--hidio_types.c163
7 files changed, 553 insertions, 387 deletions
diff --git a/Makefile b/Makefile
index 341c55b..78d1860 100644
--- a/Makefile
+++ b/Makefile
@@ -15,11 +15,18 @@ test_locations:
# for emacs
etags:
+ etags ../../../pd/src/*.h *.[ch] linux/input.h
make etags_`uname -s`
etags_Darwin:
- etags *.[ch] linux/input.h HID\ Utilities\ Source/*.[ch] \
+ etags -a HID\ Utilities\ Source/*.[ch] \
+ /System/Library/Frameworks/ForceFeedback.framework/Headers/*.h \
+ /System/Library/Frameworks/Carbon.framework/Headers/*.h \
/System/Library/Frameworks/IOKit.framework/Headers/hid*/*.[ch]
etags_Linux:
- etags *.[ch] /usr/include/*.h linux/input.h /usr/include/sys/*.h
+ etags -a /usr/include/*.h linux/input.h /usr/include/sys/*.h
+
+etags_MINGW:
+ etags -a /usr/include/*.h /usr/include/sys/*.h \
+ /usr/local/include/*.h /usr/local/include/sys/*.h
diff --git a/hidio-help.pd b/hidio-help.pd
index 9f1a291..0cace51 100644
--- a/hidio-help.pd
+++ b/hidio-help.pd
@@ -1,45 +1,27 @@
-#N canvas 157 38 925 599 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 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 - -;
-#X symbolatom 492 372 15 0 0 1 event_type - -;
-#X obj 2 2 cnv 15 900 20 empty empty [hid] 2 11 1 18 -233017 -66577
+#N canvas 157 38 862 587 10;
+#X floatatom 27 445 5 0 0 0 - - -;
+#X floatatom 83 445 5 0 0 0 - - -;
+#X obj 191 164 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 25
+25;
+#X floatatom 765 335 5 0 0 1 value - -;
+#X symbolatom 631 360 15 0 0 1 event_code - -;
+#X symbolatom 544 377 15 0 0 1 event_type - -;
+#X obj 2 2 cnv 15 900 20 empty empty [hidio] 2 11 1 18 -233017 -66577
0;
-#X text 274 332 outlet message format:;
-#X obj 772 99 ev-list;
-#X obj 772 150 ev_syn-list;
-#X obj 772 172 ev_key-list;
-#X obj 772 194 ev_rel-list;
-#X obj 772 216 ev_abs-list;
-#X obj 772 238 ev_msc-list;
-#X obj 772 260 ev_led-list;
-#X obj 772 282 ev_snd-list;
-#X obj 772 304 ev_rep-list;
-#X obj 772 326 ev_ff-list;
-#X obj 772 348 ev_ff_status-list;
-#X text 740 80 Event Types:;
-#X text 740 131 Event Codes:;
-#X floatatom 138 343 5 0 0 1 ev_syn - -;
-#X obj 111 342 +;
-#X msg 111 322 1;
+#X text 224 324 outlet message format:;
#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.2 $$Date: 2006-11-30 06:14:59 $;
+#X text 472 544 $Revision: 1.3 $$Date: 2006-12-08 06:33:26 $;
#X text 473 557 $Author: eighthave $;
#X msg 436 201 poll 20;
#X msg 374 201 poll 2;
#X text 370 186 start polling and set the poll delay in ms;
-#X text 462 33 !!! This software is very much alpha \, so any aspect
+#X text 425 33 !!! This software is very much alpha \, so any aspect
of it could change without notice !!!;
-#X obj 16 291 route key rel abs syn;
-#X obj 9 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1
+#X obj 9 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1
;
#N canvas 278 328 631 544 Event_Codes 0;
#X text 28 48 (For a complete listing of Linux Input Events \, see
@@ -193,7 +175,7 @@ of it could change without notice !!!;
#X text 138 476 BTN_BASE6;
#X text 245 463 298;
#X text 245 477 299;
-#X restore 774 414 pd Event_Codes;
+#X restore 698 94 pd Event_Codes;
#N canvas 50 289 469 317 Event_Types 0;
#X text 28 48 (For a complete listing of Linux Input Events \, see
/usr/include/linux/input.h.);
@@ -236,16 +218,14 @@ of it could change without notice !!!;
#X text 331 255 22;
#X text 230 255 EV_PWR;
#X text 61 255 Power Events (for UPS);
-#X restore 774 394 pd Event_Types;
+#X restore 698 74 pd Event_Types;
#N canvas 0 22 450 300 Event_Values 0;
#X text 28 48 (For a complete listing of Linux Input Events \, see
/usr/include/linux/input.h.);
#X obj 11 9 cnv 15 400 30 empty empty Event_Values 20 12 1 14 -261681
-66577 0;
-#X restore 774 434 pd Event_Values;
-#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 restore 698 114 pd Event_Values;
+#X floatatom 140 445 5 0 0 0 - - -;
#X msg 374 161 print;
#X text 437 141 close the device;
#X text 437 162 print the device and element lists;
@@ -253,62 +233,43 @@ of it could change without notice !!!;
#X text 8 225 0 stops the polling. If the number;
#X text 9 238 is greater than 1 \, then the poll;
#X text 9 251 delay is set to that number.;
-#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 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
-;
-#X obj 421 432 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
--1;
-#X floatatom 498 416 7 0 0 0 - - -;
-#X obj 498 432 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
-#X floatatom 576 416 7 0 0 0 - - -;
-#X obj 576 432 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
-#X floatatom 653 416 7 0 0 0 - - -;
-#X obj 653 432 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
-#X floatatom 113 395 6 0 0 0 - - -;
-#X floatatom 163 395 6 0 0 0 - - -;
-#X floatatom 213 395 6 0 0 0 - - -;
-#X floatatom 263 395 6 0 0 0 - - -;
-#X floatatom 313 395 6 0 0 0 - - -;
-#X floatatom 363 395 6 0 0 0 - - -;
-#X obj 39 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1
+#X floatatom 196 445 5 0 0 0 - - -;
+#X floatatom 113 401 6 0 0 0 - - -;
+#X floatatom 163 401 6 0 0 0 - - -;
+#X floatatom 213 401 6 0 0 0 - - -;
+#X floatatom 263 401 6 0 0 0 - - -;
+#X floatatom 313 401 6 0 0 0 - - -;
+#X floatatom 363 401 6 0 0 0 - - -;
+#X obj 39 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1
;
-#X obj 69 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1
+#X obj 69 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1
;
-#X obj 99 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1
+#X obj 99 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1
;
-#X obj 129 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 129 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 159 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 159 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 189 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 189 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 219 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 219 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 249 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 249 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 279 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 279 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 309 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 309 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 339 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 339 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 369 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 369 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 399 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 399 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 9 460 route btn_0 btn_1 btn_2 btn_3 btn_4 btn_5 btn_6 btn_7
-btn_8 btn_9 btn_10 btn_11 btn_12 btn_13 btn_14 btn_15;
-#X obj 429 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 429 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 459 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
+#X obj 459 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0
1;
-#X obj 262 298 cyclone/prepend set;
#X msg 25 155 debug 0;
#X msg 298 145 info;
#N canvas 743 25 411 235 see 0;
@@ -350,7 +311,7 @@ type vendorID productID;
#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 0 1;
+#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 - -;
@@ -374,7 +335,7 @@ type vendorID productID;
#X connect 0 9 4 0;
#X connect 2 0 0 0;
#X connect 2 0 3 0;
-#X restore 420 271 pd see device info;
+#X restore 575 278 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;
@@ -432,34 +393,8 @@ 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 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 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 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;
-#X connect 1 0 2 0;
-#X connect 2 0 3 0;
-#X connect 2 0 4 0;
-#X connect 2 0 5 0;
-#X connect 5 0 6 0;
-#X connect 7 0 5 1;
-#X connect 8 0 9 0;
-#X connect 10 0 8 1;
-#X restore 197 303 pd test;
#X msg 504 201 poll 200;
-#X msg 261 317 key key_leftctrl 1;
+#X msg 225 309 relative y 0 1;
#X text 49 543 (C) Copyright 2004 Hans-Christoph Steiner <hans@at.or.at>
;
#N canvas 162 133 570 420 serin 0;
@@ -490,12 +425,12 @@ IDs (it is not case sensitive):;
#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;
+#X msg 262 114 open 2;
#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
+#X obj 209 61 cnv 15 15 15 empty \$0-open-canvas 2 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;
+-1 2;
#X obj 60 13 inlet;
#X msg 200 202 label \$1;
#X obj 200 180 makefilename %d;
@@ -520,70 +455,108 @@ IDs (it is not case sensitive):;
#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 obj 304 250 hidio;
-#X connect 3 0 99 0;
-#X connect 22 0 23 1;
-#X connect 23 0 22 0;
-#X connect 24 0 23 0;
-#X connect 25 0 99 0;
-#X connect 26 0 99 0;
-#X connect 32 0 99 0;
-#X connect 33 0 99 0;
-#X connect 36 0 82 0;
-#X connect 36 1 51 0;
-#X connect 36 2 55 0;
-#X connect 36 3 24 0;
-#X connect 42 0 43 0;
-#X connect 42 1 57 0;
-#X connect 42 2 59 0;
-#X connect 42 3 61 0;
-#X connect 43 0 56 0;
-#X connect 44 0 99 0;
-#X connect 51 0 0 0;
-#X connect 51 1 1 0;
-#X connect 51 2 41 0;
-#X connect 51 3 52 0;
-#X connect 53 0 6 0;
-#X connect 53 1 5 0;
-#X connect 53 2 4 0;
-#X connect 55 0 2 0;
-#X connect 55 1 63 0;
-#X connect 55 2 64 0;
-#X connect 55 3 65 0;
-#X connect 55 4 66 0;
-#X connect 55 5 67 0;
-#X connect 55 6 68 0;
-#X connect 55 7 42 0;
-#X connect 57 0 58 0;
-#X connect 59 0 60 0;
-#X connect 61 0 62 0;
-#X connect 82 0 37 0;
-#X connect 82 1 69 0;
-#X connect 82 2 70 0;
-#X connect 82 3 71 0;
-#X connect 82 4 72 0;
-#X connect 82 5 73 0;
-#X connect 82 6 74 0;
-#X connect 82 7 75 0;
-#X connect 82 8 76 0;
-#X connect 82 9 77 0;
-#X connect 82 10 78 0;
-#X connect 82 11 79 0;
-#X connect 82 12 80 0;
-#X connect 82 13 81 0;
-#X connect 82 14 83 0;
-#X connect 82 15 84 0;
-#X connect 85 0 93 0;
-#X connect 86 0 99 0;
-#X connect 87 0 99 0;
-#X connect 89 0 99 0;
-#X connect 90 0 99 0;
-#X connect 92 0 99 0;
-#X connect 95 0 86 0;
-#X connect 96 0 99 0;
-#X connect 97 0 96 0;
-#X connect 99 0 36 0;
-#X connect 99 0 53 0;
-#X connect 99 0 85 0;
-#X connect 99 0 91 0;
-#X connect 99 1 88 0;
+#X obj 306 235 hidio;
+#X obj 226 290 flatspace/prepend set;
+#X obj 544 315 unpack symbol symbol float float;
+#X floatatom 683 336 2 0 0 1 instance - -;
+#X obj 65 368 route x y z rx ry rz slider dial;
+#X obj 27 425 route x y wheel;
+#X obj 10 314 route key relative absolute;
+#X text 218 341 [event_type event_code instance value(;
+#N canvas 0 22 454 304 remove 0;
+#X obj 134 12 inlet;
+#X obj 109 60 unpack symbol symbol float float;
+#X obj 110 107 pack symbol symbol float;
+#X obj 110 135 list trim;
+#X obj 116 196 outlet;
+#X connect 0 0 1 0;
+#X connect 1 0 2 0;
+#X connect 1 1 2 1;
+#X connect 1 3 2 2;
+#X connect 2 0 3 0;
+#X connect 3 0 4 0;
+#X restore 10 293 pd remove instance numbers;
+#X obj 9 466 route a_key b_key c_key d_key e_key f_key g_key h_key
+i_key j_key k_key l_key m_key n_key o_key p_key;
+#N canvas 114 93 471 350 raw 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 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 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;
+#X connect 1 0 2 0;
+#X connect 2 0 3 0;
+#X connect 2 0 4 0;
+#X connect 2 0 5 0;
+#X connect 5 0 6 0;
+#X connect 7 0 5 1;
+#X connect 8 0 9 0;
+#X connect 10 0 8 1;
+#X restore 408 294 pd raw;
+#X floatatom 63 401 6 0 0 0 - - -;
+#X connect 2 0 65 0;
+#X connect 8 0 65 0;
+#X connect 9 0 65 0;
+#X connect 15 0 65 0;
+#X connect 16 0 65 0;
+#X connect 24 0 65 0;
+#X connect 53 0 65 0;
+#X connect 54 0 65 0;
+#X connect 56 0 65 0;
+#X connect 57 0 65 0;
+#X connect 58 0 65 0;
+#X connect 61 0 53 0;
+#X connect 62 0 65 0;
+#X connect 63 0 62 0;
+#X connect 65 0 75 0;
+#X connect 65 0 67 0;
+#X connect 65 0 66 0;
+#X connect 65 0 73 0;
+#X connect 65 1 55 0;
+#X connect 66 0 59 0;
+#X connect 67 0 5 0;
+#X connect 67 1 4 0;
+#X connect 67 2 68 0;
+#X connect 67 3 3 0;
+#X connect 69 0 76 0;
+#X connect 69 1 32 0;
+#X connect 69 2 33 0;
+#X connect 69 3 34 0;
+#X connect 69 4 35 0;
+#X connect 69 5 36 0;
+#X connect 69 6 37 0;
+#X connect 70 0 0 0;
+#X connect 70 1 1 0;
+#X connect 70 2 23 0;
+#X connect 70 3 31 0;
+#X connect 71 0 74 0;
+#X connect 71 1 70 0;
+#X connect 71 2 69 0;
+#X connect 73 0 71 0;
+#X connect 74 0 19 0;
+#X connect 74 1 38 0;
+#X connect 74 2 39 0;
+#X connect 74 3 40 0;
+#X connect 74 4 41 0;
+#X connect 74 5 42 0;
+#X connect 74 6 43 0;
+#X connect 74 7 44 0;
+#X connect 74 8 45 0;
+#X connect 74 9 46 0;
+#X connect 74 10 47 0;
+#X connect 74 11 48 0;
+#X connect 74 12 49 0;
+#X connect 74 13 50 0;
+#X connect 74 14 51 0;
+#X connect 74 15 52 0;
diff --git a/hidio.c b/hidio.c
index 3a93938..9ec25fb 100644
--- a/hidio.c
+++ b/hidio.c
@@ -2,7 +2,7 @@
/* */
/* interface to native HID (Human Interface Devices) API */
/* Written by Hans-Christoph Steiner <hans@at.or.at> */
-/* Max/MSP port by Olaf Matthes <olaf.matthes@gmx.de> */
+/* Max/MSP port by Olaf Matthes <olaf.matthes@gmx.de> */
/* */
/* Copyright (c) 2004-2006 Hans-Christoph Steiner */
/* */
@@ -23,19 +23,19 @@
/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* */
/* --------------------------------------------------------------------------*/
-
-#ifdef _WINDOWS
-/* any Windows specific includes go in here */
-#ifdef PD
-#include <windows.h>
-#endif /* PD */
+
+#ifdef _WIN32
+/* any Windows specific includes go in here */
+#ifdef PD
+#include <windows.h>
+#endif /* PD */
#else
#include <unistd.h>
-#include <ctype.h>
-#endif
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
+#include <ctype.h>
+#endif /* _WIN32 */
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
#include "hidio.h"
@@ -72,6 +72,13 @@ unsigned short element_count[MAX_DEVICES];
/* pre-generated symbols */
t_symbol *ps_open, *ps_device, *ps_poll, *ps_total, *ps_range;
+t_symbol *ps_absolute, *ps_button, *ps_key, *ps_led, *ps_pid, *ps_relative;
+t_symbol *absolute_symbols[ABSOLUTE_ARRAY_MAX];
+t_symbol *button_symbols[BUTTON_ARRAY_MAX];
+t_symbol *key_symbols[KEY_ARRAY_MAX];
+t_symbol *led_symbols[LED_ARRAY_MAX];
+t_symbol *pid_symbols[PID_ARRAY_MAX];
+t_symbol *relative_symbols[RELATIVE_ARRAY_MAX];
/*------------------------------------------------------------------------------
* FUNCTION PROTOTYPES
@@ -91,14 +98,14 @@ static void hidio_open(t_hidio *x, t_symbol *s, int argc, t_atom *argv);
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);
+ va_end(ap);
}
}
@@ -125,7 +132,7 @@ static void output_status(t_hidio *x, t_symbol *selector, t_float output_value)
SETFLOAT(output_atom, output_value);
#else
atom_setlong(output_atom, output_value);
-#endif
+#endif /* PD */
outlet_anything( x->x_status_outlet, selector, 1, output_atom);
freebytes(output_atom,sizeof(t_atom));
}
@@ -167,7 +174,7 @@ static void output_element_ranges(t_hidio *x)
#else
atom_setlong(output_data + 2, element[x->x_device_number][i]->min);
atom_setlong(output_data + 3, element[x->x_device_number][i]->max);
-#endif
+#endif /* PD */
outlet_anything(x->x_status_outlet, ps_range, 4, output_data);
}
}
@@ -197,7 +204,7 @@ static short get_device_number_from_arguments(int argc, t_atom *argv)
long device_number = -1;
char *device_type_string;
long device_type_instance;
-#endif
+#endif /* PD */
unsigned int usage;
unsigned short vendor_id;
unsigned short product_id;
@@ -212,14 +219,14 @@ static short get_device_number_from_arguments(int argc, t_atom *argv)
#else
atom_arg_getsym(&first_argument, 0,argc,argv);
if(first_argument == _sym_nothing)
-#endif
+#endif /* PD */
{ // single float arg means device #
post("first_argument == &s_");
#ifdef PD
device_number = (short) atom_getfloatarg(0,argc,argv);
#else
atom_arg_getlong(&device_number, 0, argc, argv);
-#endif
+#endif /* PD */
if(device_number < 0) device_number = -1;
debug_print(LOG_DEBUG,"[hidio] setting device# to %d",device_number);
}
@@ -230,7 +237,7 @@ static short get_device_number_from_arguments(int argc, t_atom *argv)
#else
device_type_string = atom_string(argv);
// LATER do we have to free this string manually???
-#endif
+#endif /* PD */
usage = name_to_usage(device_type_string);
device_number = get_device_number_from_usage(0, usage >> 16,
usage & 0xffff);
@@ -248,7 +255,7 @@ static short get_device_number_from_arguments(int argc, t_atom *argv)
atom_arg_getsym(&first_argument, 0,argc,argv);
atom_arg_getsym(&second_argument, 1,argc,argv);
if( second_argument == _sym_nothing )
-#endif
+#endif /* PD */
{ /* a symbol then a float means match on usage */
#ifdef PD
atom_string(argv, device_type_string, MAXPDSTRING-1);
@@ -258,7 +265,7 @@ static short get_device_number_from_arguments(int argc, t_atom *argv)
device_type_string = atom_string(argv);
usage = name_to_usage(device_type_string);
atom_arg_getlong(&device_type_instance, 1, argc, argv);
-#endif
+#endif /* PD */
debug_print(LOG_DEBUG,"[hidio] looking for %s at #%d",
device_type_string, device_type_instance);
device_number = get_device_number_from_usage(device_type_instance,
@@ -280,8 +287,8 @@ static short get_device_number_from_arguments(int argc, t_atom *argv)
void hidio_output_event(t_hidio *x, t_hid_element *output_data)
{
- if( (output_data->value != output_data->previous_value) ||
- (output_data->relative) ) // relative data should always be output
+ if( (output_data->relative) || // relative data should always be output
+ (output_data->value != output_data->previous_value) )
{
t_atom event_data[3];
SETSYMBOL(event_data, output_data->name);
@@ -389,11 +396,11 @@ t_int hidio_close(t_hidio *x)
* closed / same device open
* open / same device no action
* closed / different device open
- * open / different device close open
+ * open / different device close, open
*/
static void hidio_open(t_hidio *x, t_symbol *s, int argc, t_atom *argv)
{
- short device_number;
+ short device_number;
debug_print(LOG_DEBUG,"hid_%s",s->s_name);
pthread_mutex_lock(&x->x_mutex);
@@ -417,8 +424,11 @@ t_int hidio_child_read(t_hidio *x)
#ifdef PD
double right_now = clock_getlogicaltime();
#else
+/* TODO: this should use gettime() not systime_ms(). This needs to be logical
+ * time, not system time because the idea is that only one instance should get
+ * events from the OS in each slice of logical time <hans@at.or.at> */
double right_now = (double)systime_ms();
-#endif
+#endif /* PD */
t_hid_element *current_element;
if(right_now > last_execute_time[x->x_device_number])
@@ -481,13 +491,13 @@ static void hidio_int(t_hidio* x, long l)
hidio_set_from_float(x, (float)l);
}
-#endif
+#endif /* NOT PD */
static void hidio_debug(t_hidio *x, t_float f)
{
- pthread_mutex_lock(&x->x_mutex);
+ pthread_mutex_lock(&x->x_mutex);
global_debug_level = f;
- pthread_mutex_unlock(&x->x_mutex);
+ pthread_mutex_unlock(&x->x_mutex);
}
@@ -497,7 +507,7 @@ static void hidio_debug(t_hidio *x, t_float f)
static void *hidio_child(void *zz)
{
- t_hidio *x = zz;
+ t_hidio *x = zz;
short device_number = -1;
pthread_mutex_lock(&x->x_mutex);
@@ -513,19 +523,19 @@ static void *hidio_child(void *zz)
short new_device_number = x->x_device_number;
/* store running state to be restored after the device has been opened */
t_int started = x->x_started;
- int ret;
- /* check whether we have to close previous device */
- if (x->x_device_open && device_number != x->x_device_number)
- {
- pthread_mutex_unlock(&x->x_mutex);
- stop_poll(x);
- ret = hidio_close_device(x);
- pthread_mutex_lock(&x->x_mutex);
- x->x_device_open = 0;
- device_number = -1;
- }
- /* no device open, so open one now */
- if (!x->x_device_open)
+ int ret;
+ /* check whether we have to close previous device */
+ if (x->x_device_open && device_number != x->x_device_number)
+ {
+ pthread_mutex_unlock(&x->x_mutex);
+ stop_poll(x);
+ ret = hidio_close_device(x);
+ pthread_mutex_lock(&x->x_mutex);
+ x->x_device_open = 0;
+ device_number = -1;
+ }
+ /* no device open, so open one now */
+ if (!x->x_device_open)
{
pthread_mutex_unlock(&x->x_mutex);
ret = hidio_open_device(x, new_device_number);
@@ -537,7 +547,7 @@ static void *hidio_child(void *zz)
}
else
{
- x->x_device_open = 1;
+ x->x_device_open = 1;
device_number = x->x_device_number; /* keep local copy */
pthread_mutex_unlock(&x->x_mutex);
/* restore the polling state so that when I [tgl] is used to start/stop [hidio],
@@ -548,7 +558,7 @@ static void *hidio_child(void *zz)
output_open_status(x);
output_device_number(x);
pthread_mutex_lock(&x->x_mutex);
- }
+ }
}
if (x->x_requestcode == REQUEST_OPEN)
x->x_requestcode = REQUEST_NOTHING;
@@ -618,45 +628,45 @@ static void *hidio_child(void *zz)
return (0);
}
-/* change priority of child thread */
-#ifdef PD
-static void hidio_priority(t_hidio *x, t_floatarg p)
-#else
-static void hidio_priority(t_hidio *x, long p)
-#endif
-{
- pthread_mutex_lock(&x->x_mutex);
- p = 2 * (CLIP(p, 0, 10) - 5);
- if (x->x_thread)
- {
- struct sched_param parm;
- int policy;
- if (pthread_getschedparam(x->x_thread, &policy, &parm) < 0)
- {
- post("hidio: warning: failed to get thread priority");
- }
- else
- {
- parm.sched_priority = x->x_priority + (int)p; /* adjust priority */
-
- if (parm.sched_priority < sched_get_priority_min(policy))
- {
- parm.sched_priority = sched_get_priority_min(policy);
- }
- else if (parm.sched_priority > sched_get_priority_max(policy))
- {
- parm.sched_priority = sched_get_priority_max(policy);
- }
-
- if (pthread_setschedparam(x->x_thread, policy, &parm) < 0)
- {
- post("hidio: warning: failed to change thread priority to %d", parm.sched_priority);
- }
- }
- }
- pthread_mutex_unlock(&x->x_mutex);
-}
-
+/* change priority of child thread */
+#ifdef PD
+static void hidio_priority(t_hidio *x, t_floatarg p)
+#else
+static void hidio_priority(t_hidio *x, long p)
+#endif
+{
+ pthread_mutex_lock(&x->x_mutex);
+ p = 2 * (CLIP(p, 0, 10) - 5);
+ if (x->x_thread)
+ {
+ struct sched_param parm;
+ int policy;
+ if (pthread_getschedparam(x->x_thread, &policy, &parm) < 0)
+ {
+ post("hidio: warning: failed to get thread priority");
+ }
+ else
+ {
+ parm.sched_priority = x->x_priority + (int)p; /* adjust priority */
+
+ if (parm.sched_priority < sched_get_priority_min(policy))
+ {
+ parm.sched_priority = sched_get_priority_min(policy);
+ }
+ else if (parm.sched_priority > sched_get_priority_max(policy))
+ {
+ parm.sched_priority = sched_get_priority_max(policy);
+ }
+
+ if (pthread_setschedparam(x->x_thread, policy, &parm) < 0)
+ {
+ post("hidio: warning: failed to change thread priority to %d", parm.sched_priority);
+ }
+ }
+ }
+ pthread_mutex_unlock(&x->x_mutex);
+}
+
/*------------------------------------------------------------------------------
* system functions
@@ -699,12 +709,12 @@ static void hidio_free(t_hidio* x)
pthread_cond_destroy(&x->x_requestcondition);
pthread_cond_destroy(&x->x_answercondition);
pthread_mutex_destroy(&x->x_mutex);
-}
+}
/* create a new instance of this class */
static void *hidio_new(t_symbol *s, int argc, t_atom *argv)
{
- unsigned int i;
+ unsigned int i;
#ifdef PD
t_hidio *x = (t_hidio *)pd_new(hidio_class);
@@ -721,19 +731,19 @@ static void *hidio_new(t_symbol *s, int argc, t_atom *argv)
/* create anything outlet used for HID data */
x->x_status_outlet = outlet_new(x, "anything");
x->x_data_outlet = outlet_new(x, "anything");
-#endif
+#endif /* PD */
+
+ /* 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;
+ x->x_delay = DEFAULT_DELAY;
+ for(i=0; i<MAX_DEVICES; ++i) last_execute_time[i] = 0;
+#ifdef _WIN32
+ x->x_fd = INVALID_HANDLE_VALUE;
+#endif /* _WIN32 */
- /* 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;
- x->x_delay = DEFAULT_DELAY;
- for(i=0; i<MAX_DEVICES; ++i) last_execute_time[i] = 0;
-#ifdef _WINDOWS
- x->x_fd = INVALID_HANDLE_VALUE;
-#endif
-
pthread_mutex_init(&x->x_mutex, 0);
pthread_cond_init(&x->x_requestcondition, 0);
pthread_cond_init(&x->x_answercondition, 0);
@@ -744,8 +754,8 @@ static void *hidio_new(t_symbol *s, int argc, t_atom *argv)
hidio_instance_count++;
x->x_requestcode = REQUEST_NOTHING;
- pthread_create(&x->x_thread, 0, hidio_child, x);
-
+ pthread_create(&x->x_thread, 0, hidio_child, x);
+
return (x);
}
@@ -767,6 +777,7 @@ void hidio_setup(void)
/* add inlet message methods */
class_addmethod(hidio_class,(t_method) hidio_debug,gensym("debug"),A_DEFFLOAT,0);
class_addmethod(hidio_class,(t_method) hidio_build_device_list,gensym("refresh"),0);
+/* TODO: [print( should be dumped for [devices( and [elements( messages */
class_addmethod(hidio_class,(t_method) hidio_print,gensym("print"),0);
class_addmethod(hidio_class,(t_method) hidio_info,gensym("info"),0);
class_addmethod(hidio_class,(t_method) hidio_open,gensym("open"),A_GIMME,0);
@@ -783,9 +794,9 @@ void hidio_setup(void)
class_addmethod(hidio_class,(t_method) hidio_ff_stopall,gensym("ff_stopall"),0);
/* ff tests */
class_addmethod(hidio_class,(t_method) hidio_ff_fftest,gensym("fftest"),A_DEFFLOAT,0);
- class_addmethod(hidio_class,(t_method) hidio_ff_print,gensym("ff_print"),0);
-
- class_addmethod(hidio_class,(t_method) hidio_priority, gensym("priority"), A_FLOAT, A_NULL);
+ class_addmethod(hidio_class,(t_method) hidio_ff_print,gensym("ff_print"),0);
+
+ class_addmethod(hidio_class,(t_method) hidio_priority, gensym("priority"), A_FLOAT, A_NULL);
post("[hidio] %d.%d, written by Hans-Christoph Steiner <hans@eds.org>",
@@ -799,6 +810,8 @@ void hidio_setup(void)
ps_total = gensym("total");
ps_range = gensym("range");
+ generate_type_symbols();
+ generate_event_symbols();
}
#else /* Max */
static void hidio_notify(t_hidio *x, t_symbol *s, t_symbol *msg, void *sender, void *data)
@@ -814,15 +827,15 @@ static void hidio_assist(t_hidio *x, void *b, long m, long a, char *s)
{
if (m == 2)
{
- switch (a)
- {
- case 0:
- sprintf(s, "(list) Received Events");
- break;
- case 1:
- sprintf(s, "(list) Status Info");
- break;
- }
+ switch (a)
+ {
+ case 0:
+ sprintf(s, "(list) Received Events");
+ break;
+ case 1:
+ sprintf(s, "(list) Status Info");
+ break;
+ }
}
else
{
@@ -859,6 +872,7 @@ int main()
/* add inlet message methods */
class_addmethod(c, (method)hidio_debug, "debug",A_DEFFLOAT,0);
class_addmethod(c, (method)hidio_build_device_list, "refresh",0);
+/* TODO: [print( should be dumped for [devices( and [elements( messages */
class_addmethod(c, (method)hidio_print, "print",0);
class_addmethod(c, (method)hidio_info, "info",0);
class_addmethod(c, (method)hidio_open, "open",A_GIMME,0);
@@ -875,8 +889,8 @@ int main()
/* ff tests */
class_addmethod(c, (method)hidio_ff_fftest, "fftest",A_DEFFLOAT,0);
class_addmethod(c, (method)hidio_ff_print, "ff_print",0);
- /* perfomrance / system stuff */
- class_addmethod(c, (method)hidio_priority, "priority", A_LONG,0);
+ /* perfomrance / system stuff */
+ class_addmethod(c, (method)hidio_priority, "priority", A_LONG,0);
class_addmethod(c, (method)hidio_assist, "assist", A_CANT, 0);
@@ -891,9 +905,9 @@ int main()
hidio_class = c;
finder_addclass("Devices", "hidio");
- post("hidio %d.%d: 2006 by Hans-Christoph Steiner & Olaf Matthes",
+ post("hidio %d.%d: 2006 by Hans-Christoph Steiner & Olaf Matthes",
HIDIO_MAJOR_VERSION, HIDIO_MINOR_VERSION);
- post("hidio: compiled on "__DATE__" at "__TIME__ " ");
+ post("hidio: compiled on "__DATE__" at "__TIME__ " ");
/* pre-generate often used symbols */
ps_open = gensym("open");
@@ -902,7 +916,9 @@ int main()
ps_total = gensym("total");
ps_range = gensym("range");
+ generate_event_symbols();
+
return 0;
}
-#endif
+#endif /* PD */
diff --git a/hidio.h b/hidio.h
index 4bb6f18..1b63aba 100644
--- a/hidio.h
+++ b/hidio.h
@@ -2,21 +2,21 @@
#define _HIDIO_H
#include <stdio.h>
-#ifdef _WINDOWS
+#ifdef _WIN32
#include "pthread.h" /* needs pthread library */
#define LOG_DEBUG 7
#define LOG_INFO 6
#define LOG_WARNING 4
-#define LOG_ERR 3
+#define LOG_ERR 3
#define vsnprintf _vsnprintf
#else
#include <sys/syslog.h>
#include <pthread.h>
-#endif
+#endif /* _WIN32 */
#ifdef _MSC_VER /* this only applies to Microsoft compilers */
#pragma warning (disable: 4305 4244 4761)
-#endif
+#endif /* _MSC_VER */
#ifdef __linux__
#include <linux/types.h>
@@ -24,7 +24,7 @@
#ifdef PD
#include <m_pd.h>
-#else
+#else /* Max */
#include "ext.h"
#include "ext_obex.h"
#include "commonsyms.h"
@@ -37,26 +37,20 @@ typedef void t_clock;
#define MAXPDSTRING 512
#define pd_error(x, b) error(b)
#define SETSYMBOL SETSYM
-#endif
-
-/*
- * this is automatically generated from linux/input.h by
- * make-arrays-from-input.h.pl to be the cross-platform event types and codes
- */
-#include "input_arrays.h"
+#endif /* PD */
#define HIDIO_MAJOR_VERSION 0
#define HIDIO_MINOR_VERSION 0
-/* static char *version = "$Revision: 1.8 $"; */
-
-/*------------------------------------------------------------------------------
- * MACRO DEFINES
- */
-
-#ifndef CLIP
-#define CLIP(a, lo, hi) ( (a)>(lo)?( (a)<(hi)?(a):(hi) ):(lo) )
-#endif
+/* static char *version = "$Revision: 1.9 $"; */
+
+/*------------------------------------------------------------------------------
+ * MACRO DEFINES
+ */
+
+#ifndef CLIP
+#define CLIP(a, lo, hi) ( (a)>(lo)?( (a)<(hi)?(a):(hi) ):(lo) )
+#endif /* NOT CLIP */
/*------------------------------------------------------------------------------
* GLOBAL DEFINES
@@ -96,13 +90,13 @@ typedef struct _hidio
t_object x_obj;
#ifndef PD
void *x_obex;
-#endif
-#ifdef _WINDOWS
- HANDLE x_fd;
-#endif
+#endif /* PD */
+#ifdef _WIN32
+ HANDLE x_fd;
+#endif /* _WIN32 */
#ifdef __linux__
- t_int x_fd;
-#endif
+ t_int x_fd;
+#endif /* __linux */
void *x_ff_device;
short x_device_number;
short x_instance;
@@ -117,7 +111,7 @@ typedef struct _hidio
pthread_mutex_t x_mutex;
pthread_cond_t x_requestcondition;
pthread_cond_t x_answercondition;
- pthread_t x_thread;
+ pthread_t x_thread;
t_int x_priority;
} t_hidio;
@@ -146,9 +140,9 @@ typedef struct _hid_element
__u16 linux_code;
#endif /* __linux__ */
#ifdef _WIN32
- /* this stores the UsagePage and UsageID */
+ /* this stores the UsagePage and UsageID */
unsigned short usage_page;
- unsigned short usage_id;
+ unsigned short usage_id;
#endif /* _WIN32 */
#ifdef __APPLE__
void *pHIDElement; // pRecElement on Mac OS X
@@ -212,8 +206,35 @@ t_int hidio_ff_stopall(t_hidio *x);
t_int hidio_ff_fftest (t_hidio *x, t_float value);
void hidio_ff_print(t_hidio *x);
+/*==============================================================================
+ * event symbols array sizes
+ *==============================================================================
+ */
+
+#define ABSOLUTE_ARRAY_MAX 16
+#define BUTTON_ARRAY_MAX 128
+#define KEY_ARRAY_MAX 256
+#define LED_ARRAY_MAX 77
+#define PID_ARRAY_MAX 256
+#define RELATIVE_ARRAY_MAX 16
+
+
+/*==============================================================================
+ * symbol pointers for pre-generated event symbols
+ *==============================================================================
+ */
+
+extern t_symbol *ps_absolute, *ps_button, *ps_key, *ps_led, *ps_pid, *ps_relative;
+extern t_symbol *absolute_symbols[ABSOLUTE_ARRAY_MAX];
+extern t_symbol *button_symbols[BUTTON_ARRAY_MAX];
+extern t_symbol *key_symbols[KEY_ARRAY_MAX];
+extern t_symbol *led_symbols[LED_ARRAY_MAX];
+extern t_symbol *pid_symbols[PID_ARRAY_MAX];
+extern t_symbol *relative_symbols[RELATIVE_ARRAY_MAX];
+void generate_event_symbols();
+void generate_type_symbols();
-#endif /* #ifndef _HIDIO_H */
+#endif /* NOT _HIDIO_H */
diff --git a/hidio_darwin.c b/hidio_darwin.c
index 29a62f1..d85093b 100644
--- a/hidio_darwin.c
+++ b/hidio_darwin.c
@@ -90,24 +90,21 @@ static char *convertEventsFromDarwinToLinux(pRecElement element);
* This function is needed to translate the USB HID relative flag into the
* [hidio]/linux style events
*/
-static void convert_axis_to_symbols(pRecElement pCurrentHIDElement, t_hid_element *new_element, char *axis)
+static void convert_axis_to_symbols(pRecElement pCurrentHIDElement,
+ t_hid_element *new_element, int array_index)
{
- char buffer[MAXPDSTRING];
if (pCurrentHIDElement->relative)
{
- new_element->type = gensym("rel");
- snprintf(buffer, sizeof(buffer), "rel_%s", axis);
- new_element->name = gensym(buffer);
+ new_element->type = ps_relative;
+ new_element->name = relative_symbols[array_index];
}
else
{
- new_element->type = gensym("abs");
- snprintf(buffer, sizeof(buffer), "abs_%s", axis);
- new_element->name = gensym(buffer);
+ new_element->type = ps_absolute;
+ new_element->name = absolute_symbols[array_index];
}
}
-
static void get_usage_symbols(pRecElement pCurrentHIDElement, t_hid_element *new_element)
{
// debug_print(LOG_DEBUG,"get_usage_symbols");
@@ -124,39 +121,24 @@ static void get_usage_symbols(pRecElement pCurrentHIDElement, t_hid_element *new
return;
}
- switch(pCurrentHIDElement->type)
- {
- case kIOHIDElementTypeInput_Button:
- new_element->type = gensym("key");
- break;
- }
switch (pCurrentHIDElement->usagePage)
{
case kHIDPage_GenericDesktop:
switch (pCurrentHIDElement->usage)
{
- case kHIDUsage_GD_X: convert_axis_to_symbols(pCurrentHIDElement, new_element, "x"); break;
- case kHIDUsage_GD_Y: convert_axis_to_symbols(pCurrentHIDElement, new_element, "y"); break;
- case kHIDUsage_GD_Z: convert_axis_to_symbols(pCurrentHIDElement, new_element, "z"); break;
- case kHIDUsage_GD_Rx: convert_axis_to_symbols(pCurrentHIDElement, new_element, "rx"); break;
- case kHIDUsage_GD_Ry: convert_axis_to_symbols(pCurrentHIDElement, new_element, "ry"); break;
- case kHIDUsage_GD_Rz: convert_axis_to_symbols(pCurrentHIDElement, new_element, "rz"); break;
- case kHIDUsage_GD_Slider:
- new_element->type = gensym("abs");
- new_element->name = gensym("abs_throttle");
- break;
- case kHIDUsage_GD_Dial:
- new_element->type = gensym("abs");
- new_element->name = gensym("abs_ry");
- break;
- case kHIDUsage_GD_Wheel:
- new_element->type = gensym("rel");
- new_element->name = gensym("rel_wheel");
- break;
- case kHIDUsage_GD_Hatswitch:
+ case kHIDUsage_GD_X: convert_axis_to_symbols(pCurrentHIDElement, new_element, 0); break;
+ case kHIDUsage_GD_Y: convert_axis_to_symbols(pCurrentHIDElement, new_element, 1); break;
+ case kHIDUsage_GD_Z: convert_axis_to_symbols(pCurrentHIDElement, new_element, 2); break;
+ case kHIDUsage_GD_Rx: convert_axis_to_symbols(pCurrentHIDElement, new_element, 3); break;
+ case kHIDUsage_GD_Ry: convert_axis_to_symbols(pCurrentHIDElement, new_element, 4); break;
+ case kHIDUsage_GD_Rz: convert_axis_to_symbols(pCurrentHIDElement, new_element, 5); break;
+ case kHIDUsage_GD_Slider: convert_axis_to_symbols(pCurrentHIDElement, new_element, 6); break;
+ case kHIDUsage_GD_Dial: convert_axis_to_symbols(pCurrentHIDElement, new_element, 7); break;
+ case kHIDUsage_GD_Wheel: convert_axis_to_symbols(pCurrentHIDElement, new_element, 8); break;
+ case kHIDUsage_GD_Hatswitch:
// this is still a mystery how to handle
- new_element->type = gensym("abs");
- new_element->name = gensym("hatswitch");
+ new_element->type = ps_absolute;
+ new_element->name = absolute_symbols[9]; /* hatswitch */
break;
default:
new_element->type = gensym("DESKTOP");
@@ -168,12 +150,12 @@ static void get_usage_symbols(pRecElement pCurrentHIDElement, t_hid_element *new
switch (pCurrentHIDElement->usage)
{
case kHIDUsage_Sim_Rudder:
- new_element->type = gensym("abs");
- new_element->name = gensym("abs_rz");
+ new_element->type = ps_absolute;
+ new_element->name = absolute_symbols[5]; /* rz */
break;
case kHIDUsage_Sim_Throttle:
- new_element->type = gensym("abs");
- new_element->name = gensym("abs_throttle");
+ new_element->type = ps_absolute;
+ new_element->name = absolute_symbols[6]; /* slider */
break;
default:
new_element->type = gensym("SIMULATION");
@@ -182,28 +164,24 @@ static void get_usage_symbols(pRecElement pCurrentHIDElement, t_hid_element *new
}
break;
case kHIDPage_KeyboardOrKeypad:
- new_element->type = gensym("key");
- /* temporary kludge until I feel like writing the translation table */
- snprintf(buffer, sizeof(buffer), "key_%ld", pCurrentHIDElement->usage);
- new_element->name = gensym(buffer);
+ new_element->type = ps_key;
+ if( (pCurrentHIDElement->usage > -1) &&
+ (pCurrentHIDElement->usage < KEY_ARRAY_MAX) )
+ new_element->name = key_symbols[pCurrentHIDElement->usage];
+ else /* PowerBook ADB keyboard reports 0xffffffff */
+ new_element->name = key_symbols[0];
break;
case kHIDPage_Button:
- new_element->type = gensym("key");
- /* HID Manager button numbers start at 1, [hidio] start at 0 */
- snprintf(buffer, sizeof(buffer), "btn_%ld", pCurrentHIDElement->usage - 1);
- new_element->name = gensym(buffer);
+ new_element->type = ps_button;
+ new_element->name = button_symbols[pCurrentHIDElement->usage];
break;
case kHIDPage_LEDs:
- /* temporary kludge until I feel like writing the translation table */
- new_element->type = gensym("led");
- snprintf(buffer, sizeof(buffer), "led_%ld", pCurrentHIDElement->usage);
- new_element->name = gensym(buffer);
+ new_element->type = ps_led;
+ new_element->name = led_symbols[pCurrentHIDElement->usage];
break;
case kHIDPage_PID:
- /* temporary kludge until I feel like writing the translation table */
- new_element->type = gensym("ff");
- snprintf(buffer, sizeof(buffer), "ff_%ld", pCurrentHIDElement->usage);
- new_element->name = gensym(buffer);
+ new_element->type = ps_pid;
+ new_element->name = pid_symbols[pCurrentHIDElement->usage];
break;
default:
/* the rest are "vendor defined" so no translation table is possible */
@@ -214,7 +192,8 @@ static void get_usage_symbols(pRecElement pCurrentHIDElement, t_hid_element *new
}
}
-
+/* this functions checks to see if there are any existing instances of a given
+ * type/code and assigns an number to this instance */
static t_float get_type_name_instance(t_symbol *type, t_symbol *name,
int argc, t_hid_element **argv)
{
@@ -758,7 +737,7 @@ void hidio_build_device_list(void)
debug_print(LOG_WARNING,"[hidio] completed device list.");
}
-
+/* TODO: this should be dumped for [devices( and [elements( messages */
void hidio_print(t_hidio *x)
{
if( !HIDHaveDeviceList() ) hidio_build_device_list();
@@ -830,7 +809,8 @@ t_int hidio_ff_gain(t_hidio *x, t_float value)
ffgain_value = value * 10000;
/* FFPROP_FFGAIN has a integer range of 0-10000 */
result = FFDeviceSetForceFeedbackProperty(
- (FFDeviceObjectReference)x->x_ff_device, FFPROP_FFGAIN, &ffgain_value );
+ (FFDeviceObjectReference)x->x_ff_device, FFPROP_FFGAIN,
+ &ffgain_value );
if ( result != FF_OK )
{
post("[hidio]: ff_gain failed!");
diff --git a/hidio_linux.c b/hidio_linux.c
index a7e1c1c..7da4ff9 100644
--- a/hidio_linux.c
+++ b/hidio_linux.c
@@ -15,6 +15,12 @@
#include "hidio.h"
+/*
+ * this is automatically generated from linux/input.h by
+ * make-arrays-from-input.h.pl to be the cross-platform event types and codes
+ */
+#include "input_arrays.h"
+
#define DEBUG(x)
//#define DEBUG(x) x
diff --git a/hidio_types.c b/hidio_types.c
new file mode 100644
index 0000000..43c0708
--- /dev/null
+++ b/hidio_types.c
@@ -0,0 +1,163 @@
+
+#include "m_pd.h"
+#include "hidio.h"
+
+//#define DEBUG(x)
+#define DEBUG(x) x
+
+
+/*==============================================================================
+ * "codes" for elements
+ *==============================================================================
+ */
+
+/* absolute axes (joysticks, gamepads, tablets, etc.) */
+static char *absolute_strings[ABSOLUTE_ARRAY_MAX] = {
+ "x","y","z","rx","ry","rz","slider","dial",
+ "wheel","hatswitch","absolute_10","absolute_11","absolute_12","absolute_13",
+ "absolute_14","absolute_15"
+};
+
+/* keys (keyboards, keypads) */
+static char *key_strings[KEY_ARRAY_MAX] = {
+ "key_0","errorrollover","postfail","errorundefined","a_key","b_key","c_key","d_key","e_key","f_key","g_key","h_key","i_key","j_key","k_key","l_key","m_key","n_key","o_key","p_key","q_key","r_key","s_key","t_key","u_key","v_key","w_key","x_key","y_key","z_key","1_key","2_key","3_key","4_key","5_key","6_key","7_key","8_key","9_key","0_key","enter","escape","deleteorbackspace","tab","spacebar","hyphen","equalsign","openbracket","closebracket","backslash","nonuspound","semicolon","quote","graveaccentandtilde","comma","period","slash","capslock","F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","printscreen","scrolllock","pause","insert","home","pageup","deleteforward","end","pagedown","rightarrow","leftarrow","downarrow","uparrow","keypad_numlock","keypad_slash","keypad_asterisk","keypad_hyphen","keypad_plus","keypad_enter","keypad_1","keypad_2","keypad_3","keypad_4","keypad_5","keypad_6","keypad_7","keypad_8","keypad_9","keypad_0","keypad_period","nonusbackslash","application","power","keypad_equalsign","f13","f14","f15","f16","f17","f18","f19","f20","f21","f22","f23","f24","execute","help","menu","select","stop","again","undo","cut","copy","paste","find","mute","volumeup","volumedown","lockingcapslock","lockingnumlock","lockingscrolllock","keypad_comma","keypad_equalsignas400","international1","international2","international3","international4","international5","international6","international7","international8","international9","lang1","lang2","lang3","lang4","lang5","lang6","lang7","lang8","lang9","alternateerase","sysreqorattention","cancel","clear","prior","return","separator","out","oper","clearoragain","crselorprops","exsel","key_165","key_166","key_167","key_168","key_169","key_170","key_171","key_172","key_173","key_174","key_175","key_176","key_177","key_178","key_179","key_180","key_181","key_182","key_183","key_184","key_185","key_186","key_187","key_188","key_189","key_190","key_191","key_192","key_193","key_194","key_195","key_196","key_197","key_198","key_199","key_200","key_201","key_202","key_203","key_204","key_205","key_206","key_207","key_208","key_209","key_210","key_211","key_212","key_213","key_214","key_215","key_216","key_217","key_218","key_219","key_220","key_221","key_222","key_223","leftcontrol","leftshift","leftalt","leftgui","rightcontrol","rightshift","rightalt","rightgui","key_232","key_233","key_234","key_235","key_236","key_237","key_238","key_239","key_240","key_241","key_242","key_243","key_244","key_245","key_246","key_247","key_248","key_249","key_250","key_251","key_252","key_253","key_254","key_255"
+
+};
+
+
+/* LEDs (keyboards, gamepads, etc.) */
+static char *led_strings[LED_ARRAY_MAX] = {
+ "numlock","capslock","scrolllock","compose","kana","power","shift",
+ "donotdisturb","mute","toneenable","highcutfilter","lowcutfilter",
+ "equalizerenable","soundfieldon","surroundon","repeat","stereo",
+ "samplingratedetect","spinning","cav","clv","recordingformatdetect",
+ "offhook","ring","messagewaiting","datamode","batteryoperation","batteryok",
+ "batterylow","speaker","headset","hold","microphone","coverage","nightmode",
+ "sendcalls","callpickup","conference","standby","cameraon","cameraoff",
+ "online","offline","busy","ready","paperout","paperjam","remote","forward",
+ "reverse","stop","rewind","fastforward","play","pause","record","error",
+ "usage","usageinuseindicator","usagemultimodeindicator","indicatoron",
+ "indicatorflash","indicatorslowblink","indicatorfastblink","indicatoroff",
+ "flashontime","slowblinkontime","slowblinkofftime","fastblinkontime",
+ "fastblinkofftime","usageindicatorcolor","indicatorred","indicatorgreen",
+ "indicatoramber","genericindicator","systemsuspend","externalpowerconnected"
+};
+
+
+/* PID, Physical Interface Devices (force feedback joysticks, mice, etc.) */
+static char *pid_strings[PID_ARRAY_MAX] = {
+ "pid_0","physicalinterfacedevice","pid_2","pid_3","pid_4","pid_5","pid_6","pid_7",
+ "pid_8","pid_9","pid_10","pid_11","pid_12","pid_13","pid_14","pid_15",
+ "pid_16","pid_17","pid_18","pid_19","pid_20","pid_21","pid_22","pid_23",
+ "pid_24","pid_25","pid_26","pid_27","pid_28","pid_29","pid_30","pid_31",
+ "normal","seteffectreport","effectblockindex","paramblockoffset","rom_flag",
+ "effecttype","constantforce","ramp","customforcedata","pid_41","pid_42",
+ "pid_43","pid_44","pid_45","pid_46","pid_47","square","sine","triangle",
+ "sawtoothup","sawtoothdown","pid_53","pid_54","pid_55","pid_56","pid_57",
+ "pid_58","pid_59","pid_60","pid_61","pid_62","pid_63","spring","damper",
+ "inertia","friction","pid_68","pid_69","pid_70","pid_71","pid_72","pid_73",
+ "pid_74","pid_75","pid_76","pid_77","pid_78","pid_79","duration",
+ "sampleperiod","gain","triggerbutton","triggerrepeatinterval","axesenable",
+ "directionenable","direction","typespecificblockoffset","blocktype",
+ "setenvelopereport","attacklevel","attacktime","fadelevel","fadetime",
+ "setconditionreport","cp_offset","positivecoefficient",
+ "negativecoefficient","positivesaturation","negativesaturation","deadband",
+ "downloadforcesample","isochcustomforceenable","customforcedatareport",
+ "customforcedata","customforcevendordefineddata","setcustomforcereport",
+ "customforcedataoffset","samplecount","setperiodicreport","offset",
+ "magnitude","phase","period","setconstantforcereport","setrampforcereport",
+ "rampstart","rampend","effectoperationreport","effectoperation",
+ "opeffectstart","opeffectstartsolo","opeffectstop","loopcount",
+ "devicegainreport","devicegain","poolreport","ram_poolsize",
+ "rom_poolsize","rom_effectblockcount","simultaneouseffectsmax",
+ "poolalignment","poolmovereport","movesource","movedestination",
+ "movelength","blockloadreport","pid_138","blockloadstatus",
+ "blockloadsuccess","blockloadfull","blockloaderror","blockhandle",
+ "blockfreereport","typespecificblockhandle","statereport","pid_147",
+ "effectplaying","devicecontrolreport","devicecontrol","dc_enableactuators",
+ "dc_disableactuators","dc_stopalleffects","dc_devicereset","dc_devicepause",
+ "dc_devicecontinue","pid_157","pid_158","devicepaused","actuatorsenabled",
+ "pid_161","pid_162","pid_163","safetyswitch","actuatoroverrideswitch",
+ "actuatorpower","startdelay","parameterblocksize","devicemanagedpool",
+ "sharedparameterblocks","createneweffectreport","ram_poolavailable",
+ "pid_173","pid_174","pid_175","pid_176","pid_177","pid_178","pid_179",
+ "pid_180","pid_181","pid_182","pid_183","pid_184","pid_185","pid_186",
+ "pid_187","pid_188","pid_189","pid_190","pid_191","pid_192","pid_193",
+ "pid_194","pid_195","pid_196","pid_197","pid_198","pid_199","pid_200",
+ "pid_201","pid_202","pid_203","pid_204","pid_205","pid_206","pid_207",
+ "pid_208","pid_209","pid_210","pid_211","pid_212","pid_213","pid_214",
+ "pid_215","pid_216","pid_217","pid_218","pid_219","pid_220","pid_221",
+ "pid_222","pid_223","pid_224","pid_225","pid_226","pid_227","pid_228",
+ "pid_229","pid_230","pid_231","pid_232","pid_233","pid_234","pid_235",
+ "pid_236","pid_237","pid_238","pid_239","pid_240","pid_241","pid_242",
+ "pid_243","pid_244","pid_245","pid_246","pid_247","pid_248","pid_249",
+ "pid_250","pid_251","pid_252","pid_253","pid_254","pid_255"
+};
+
+
+/* relative axes (mice) */
+static char *relative_strings[RELATIVE_ARRAY_MAX] = {
+ "x","y","z","rx","ry","rz",
+ "hwheel","dial","wheel","misc","relative_10","relative_11",
+ "relative_12","relative_13","relative_14","relative_15"
+};
+
+
+/*==============================================================================
+ * conversion functions
+ *==============================================================================
+ */
+
+static void generate_button_symbols(t_symbol *symbols[], unsigned int size)
+{
+ unsigned int i;
+ char string_buffer[MAXPDSTRING];
+
+ for(i = 0; i < size; ++i)
+ {
+ sprintf(string_buffer,"button_%d",i);
+ symbols[i] = gensym(string_buffer);
+ }
+}
+
+static void generate_symbols_from_strings(t_symbol *symbols[], char *strings[],
+ unsigned int size)
+{
+ unsigned int i;
+
+ for(i = 0; i < size; ++i) symbols[i] = gensym(strings[i]);
+}
+
+
+void generate_event_symbols()
+{
+ DEBUG(post("generate_event_symbols"););
+ generate_button_symbols(button_symbols, BUTTON_ARRAY_MAX);
+ DEBUG(post("button"););
+ generate_symbols_from_strings(absolute_symbols, absolute_strings,
+ ABSOLUTE_ARRAY_MAX);
+ DEBUG(post("absolute"););
+ generate_symbols_from_strings(key_symbols, key_strings,
+ KEY_ARRAY_MAX);
+ DEBUG(post("key"););
+ generate_symbols_from_strings(led_symbols, led_strings,
+ LED_ARRAY_MAX);
+ DEBUG(post("led"););
+ generate_symbols_from_strings(pid_symbols, pid_strings,
+ PID_ARRAY_MAX);
+ DEBUG(post("pid"););
+ generate_symbols_from_strings(relative_symbols, relative_strings,
+ RELATIVE_ARRAY_MAX);
+ DEBUG(post("relative %s",relative_symbols[4]->s_name););
+ DEBUG(post("generate_event_symbols"););
+}
+
+void generate_type_symbols()
+{
+ ps_absolute = gensym("absolute");
+ ps_button = gensym("button");
+ ps_key = gensym("key");
+ ps_led = gensym("led");
+ ps_pid = gensym("pid");
+ ps_relative = gensym("relative");
+}