[PD-cvs] SF.net SVN: pure-data: [10109] branches/pd-extended/v0-40/externals/hcs/hid
eighthave at users.sourceforge.net
eighthave at users.sourceforge.net
Thu Jun 26 18:22:29 CEST 2008
Revision: 10109
http://pure-data.svn.sourceforge.net/pure-data/?rev=10109&view=rev
Author: eighthave
Date: 2008-06-26 09:22:29 -0700 (Thu, 26 Jun 2008)
Log Message:
-----------
- fixed GNU/Linux implementation of get_device_number_by_id() and it works
- removed some debug messages
Modified Paths:
--------------
branches/pd-extended/v0-40/externals/hcs/hid/doc/hid-help.pd
branches/pd-extended/v0-40/externals/hcs/hid/hid_linux.c
Modified: branches/pd-extended/v0-40/externals/hcs/hid/doc/hid-help.pd
===================================================================
--- branches/pd-extended/v0-40/externals/hcs/hid/doc/hid-help.pd 2008-06-26 15:51:50 UTC (rev 10108)
+++ branches/pd-extended/v0-40/externals/hcs/hid/doc/hid-help.pd 2008-06-26 16:22:29 UTC (rev 10109)
@@ -1,10 +1,9 @@
-#N canvas 369 41 715 555 10;
-#X declare -lib hid;
+#N canvas 272 51 715 555 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 25
-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 - -;
#X symbolatom 492 372 15 0 0 1 event_type - -;
@@ -296,7 +295,7 @@
1;
#X msg 25 155 debug 0;
#X msg 298 145 info;
-#N canvas 743 25 411 235 see 0;
+#N canvas 752 103 411 235 see 0;
#N canvas 108 318 543 264 route 0;
#X obj 27 14 inlet;
#X obj 72 226 outlet;
@@ -360,7 +359,7 @@
#X connect 2 0 0 0;
#X connect 2 0 3 0;
#X restore 420 271 pd see device info;
-#N canvas 0 22 380 450 open 0;
+#N canvas 553 77 380 450 open 0;
#X obj 77 61 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1
-1 0;
#X msg 78 81 open mouse \$1;
@@ -403,7 +402,7 @@
#X connect 16 0 5 0;
#X connect 17 0 5 0;
#X restore 203 59 pd open by device type;
-#N canvas 88 102 470 320 open 0;
+#N canvas 796 51 470 320 open 0;
#X text 217 82 Gravis/Destroyer Tiltpad;
#X msg 76 81 open 0x047D 0x4008;
#X msg 73 53 open 0x046d 0xc01d;
@@ -413,9 +412,12 @@
IDs (it is not case sensitive):;
#X text 221 111 Overtone CUI v1.0;
#X msg 80 110 open 0x1043 0x0015;
+#X msg 83 136 open 0x06a3 0xff12;
+#X text 221 134 Saitek Cyborgforce;
#X connect 1 0 4 0;
#X connect 2 0 4 0;
#X connect 7 0 4 0;
+#X connect 8 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;
@@ -474,12 +476,13 @@
#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 6;
+#X msg 262 114 open 10;
+#X obj 249 300 pddp/print;
#N canvas 162 133 570 420 serin 0;
-#X obj 209 61 cnv 15 15 15 empty \$0-open-canvas 6 4 8 0 14 -233017
+#X obj 286 61 cnv 15 30 15 empty \$0-open-canvas 10 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 6;
+#X obj 60 61 hradio 15 1 1 15 empty empty empty 0 -6 0 8 -225271 -1
+-1 10;
#X obj 60 13 inlet;
#X msg 200 202 label \$1;
#X obj 200 180 makefilename %d;
@@ -501,9 +504,8 @@
#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 249 300 pddp/print;
+#X coords 0 -1 1 1 257 17 1 60 60;
+#X restore 262 92 pd serin;
#X connect 3 0 29 0;
#X connect 9 0 10 1;
#X connect 10 0 9 0;
@@ -525,7 +527,7 @@
#X connect 29 0 20 0;
#X connect 29 0 38 0;
#X connect 29 0 75 0;
-#X connect 29 0 81 0;
+#X connect 29 0 80 0;
#X connect 29 1 72 0;
#X connect 36 0 0 0;
#X connect 36 1 1 0;
@@ -568,4 +570,4 @@
#X connect 76 0 29 0;
#X connect 78 0 70 0;
#X connect 79 0 29 0;
-#X connect 80 0 79 0;
+#X connect 81 0 79 0;
Modified: branches/pd-extended/v0-40/externals/hcs/hid/hid_linux.c
===================================================================
--- branches/pd-extended/v0-40/externals/hcs/hid/hid_linux.c 2008-06-26 15:51:50 UTC (rev 10108)
+++ branches/pd-extended/v0-40/externals/hcs/hid/hid_linux.c 2008-06-26 16:22:29 UTC (rev 10109)
@@ -65,7 +65,7 @@
snprintf(hid_code, MAXPDSTRING,"btn_%d",linux_code - BTN_WHEEL);
else return 0;
}
- return gensym(hid_code ? hid_code : "?");
+ return gensym(hid_code);
}
/* Georg Holzmann: implementation of the keys */
@@ -261,30 +261,27 @@
debug_print(LOG_DEBUG,"hid_print_device_list");
int i,fd;
char device_output_string[MAXPDSTRING] = "Unknown";
- char dev_handle_name[MAXPDSTRING] = "/dev/input/event0";
+ char dev_handle_name[FILENAME_MAX] = "/dev/input/event0";
post("");
- for(i=0;i<128;++i)
+ for(i=0;i<MAX_DEVICES;++i)
{
- snprintf(dev_handle_name, MAXPDSTRING, "/dev/input/event%d", i);
- if(dev_handle_name)
- {
- /* open the device read-only, non-exclusive */
- fd = open (dev_handle_name, O_RDONLY | O_NONBLOCK);
- /* test if device open */
- if(fd < 0 )
- {
- fd = -1;
- }
- else
- {
- /* get name of device */
- ioctl(fd, EVIOCGNAME(sizeof(device_output_string)), device_output_string);
- post("Device %d: '%s' on '%s'", i, device_output_string, dev_handle_name);
+ snprintf(dev_handle_name, FILENAME_MAX, "/dev/input/event%d", i);
+ /* open the device read-only, non-exclusive */
+ fd = open (dev_handle_name, O_RDONLY | O_NONBLOCK);
+ /* test if device open */
+ if(fd < 0 )
+ {
+ fd = -1;
+ }
+ else
+ {
+ /* get name of device */
+ ioctl(fd, EVIOCGNAME(sizeof(device_output_string)), device_output_string);
+ post("Device %d: '%s' on '%s'", i, device_output_string, dev_handle_name);
- close (fd);
- }
- }
+ close (fd);
+ }
}
post("");
}
@@ -353,15 +350,6 @@
new_element->relative = 1;
else
new_element->relative = 0;
- // fill in the t_hid_element struct here
- post("x->x_device_number: %d element_count[]: %d",
- x->x_device_number, element_count[x->x_device_number]);
- post("linux_type/linux_code: %d/%d type/name: %s/%s max: %d min: %d ",
- new_element->linux_type, new_element->linux_code,
- new_element->type->s_name, new_element->name->s_name,
- new_element->max, new_element->min);
- post("\tpolled: %d relative: %d",
- new_element->polled, new_element->relative);
element[x->x_device_number][element_count[x->x_device_number]] = new_element;
++element_count[x->x_device_number];
}
@@ -377,8 +365,6 @@
void hid_get_events(t_hid *x)
{
- 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;);
unsigned short i;
@@ -434,27 +420,24 @@
debug_print(LOG_DEBUG,"hid_open_device");
char device_name[MAXPDSTRING] = "Unknown";
- char block_device[MAXPDSTRING] = "/dev/input/event0";
+ char block_device[FILENAME_MAX] = "/dev/input/event0";
struct input_event hid_input_event;
x->x_fd = -1;
x->x_device_number = device_number;
- snprintf(block_device,MAXPDSTRING,"/dev/input/event%d",x->x_device_number);
+ snprintf(block_device,FILENAME_MAX,"/dev/input/event%d",x->x_device_number);
- if(block_device)
- {
- /* open the device read-only, non-exclusive */
- x->x_fd = open(block_device, O_RDONLY | O_NONBLOCK);
- /* test if device open */
- if(x->x_fd < 0 )
- {
- error("[hid] open %s failed",block_device);
- x->x_fd = -1;
- return 1;
- }
- }
-
+ /* open the device read-only, non-exclusive */
+ x->x_fd = open(block_device, O_RDONLY | O_NONBLOCK);
+ /* test if device open */
+ if(x->x_fd < 0 )
+ {
+ error("[hid] open %s failed",block_device);
+ x->x_fd = -1;
+ return 1;
+ }
+
/* read input_events from the HID_DEVICE stream
* It seems that is just there to flush the input event queue
*/
@@ -495,7 +478,7 @@
unsigned int i;
unsigned int last_active_device = 0;
char device_name[MAXPDSTRING] = "Unknown";
- char block_device[MAXPDSTRING] = "/dev/input/event0";
+ char block_device[FILENAME_MAX] = "/dev/input/event0";
struct input_event x_input_event;
debug_print(LOG_DEBUG,"hid_build_device_list");
@@ -550,7 +533,7 @@
char product_id_string[7];
t_atom *output_atom = getbytes(sizeof(t_atom));
- ioctl(x->x_fd, EVIOCGID);
+ ioctl(x->x_fd, EVIOCGID, &my_id);
snprintf(vendor_id_string,7,"0x%04x", my_id.vendor);
SETSYMBOL(output_atom, gensym(vendor_id_string));
outlet_anything( x->x_status_outlet, gensym("vendorID"),
@@ -569,6 +552,23 @@
short get_device_number_by_id(unsigned short vendor_id, unsigned short product_id)
{
+ int i, fd;
+ char dev_handle_name[FILENAME_MAX];
+ struct input_id my_id;
+
+ for(i=0;i<MAX_DEVICES;++i)
+ {
+ snprintf(dev_handle_name, FILENAME_MAX, "/dev/input/event%d", i);
+ /* open the device read-only, non-exclusive */
+ fd = open (dev_handle_name, O_RDONLY | O_NONBLOCK);
+ /* test if device open */
+ if(fd > -1 )
+ {
+ ioctl(fd, EVIOCGID, &my_id);
+ if( (vendor_id == my_id.vendor) && (product_id == my_id.product) )
+ return i;
+ }
+ }
return -1;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Pd-cvs
mailing list