[PD-cvs] externals/hcs/hid hid_linux.c,1.7,1.8

Hans-Christoph Steiner eighthave at users.sourceforge.net
Sun Nov 28 03:49:30 CET 2004


Update of /cvsroot/pure-data/externals/hcs/hid
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2782

Modified Files:
	hid_linux.c 
Log Message:
code cleanup and [print( msg implementation

Index: hid_linux.c
===================================================================
RCS file: /cvsroot/pure-data/externals/hcs/hid/hid_linux.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** hid_linux.c	28 Nov 2004 01:27:47 -0000	1.7
--- hid_linux.c	28 Nov 2004 02:49:28 -0000	1.8
***************
*** 39,50 ****
  
  
! /* ============================================================================== */
  /* LINUX-SPECIFIC SUPPORT FUNCTIONS */
! /* ============================================================================== */
  
  void hid_print_element_list(t_hid *x)
  {
  	unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)];
! 	char devicename[256] = "Unknown";
  	t_int event_type, event_code;
  	char *event_type_name = "";
--- 39,71 ----
  
  
! /* ------------------------------------------------------------------------------ */
  /* LINUX-SPECIFIC SUPPORT FUNCTIONS */
! /* ------------------------------------------------------------------------------ */
! 
! void hid_convert_linux_buttons_to_numbers(__u16 linux_code, char *hid_code)
! {
! 	if(linux_code >= 0x100) 
! 	{
! 		if(linux_code < BTN_MOUSE)   
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_MISC);  /* numbered buttons */
! 		else if(linux_code < BTN_JOYSTICK)
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_MOUSE);  /* mouse buttons */
! 		else if(linux_code < BTN_GAMEPAD)
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_JOYSTICK);  /* joystick buttons */
! 		else if(linux_code < BTN_DIGI)
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_GAMEPAD);  /* gamepad buttons */
! 		else if(linux_code < BTN_WHEEL)
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_DIGI);  /* tablet buttons */
! 		else if(linux_code < KEY_OK)
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_WHEEL);  /* wheel buttons */
! 	}
! }
! 
  
  void hid_print_element_list(t_hid *x)
  {
  	unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)];
! 	char device_name[256] = "Unknown";
! 	char dev_handle_name[20] = "/dev/input/event0";
  	t_int event_type, event_code;
  	char *event_type_name = "";
***************
*** 52,60 ****
  	t_int synCount,keyCount,relCount,absCount,mscCount,ledCount,sndCount,repCount,ffCount,pwrCount,ff_statusCount;
  
-   /* get name of device */
-   ioctl(x->x_fd, EVIOCGNAME(sizeof(devicename)), devicename);
-   post ("\nConfiguring device %d as %s (%s)",
- 		  x->x_device_number,devicename,device_name);
- 
    /* get bitmask representing supported events (axes, keys, etc.) */
    memset(bitmask, 0, sizeof(bitmask));
--- 73,76 ----
***************
*** 112,116 ****
  				  }
  				  else
! 					  post("  %s\t\t%s\t%s",
  							 ev[event_type] ? ev[event_type] : "?", 
  							 event_names[event_type] ? (event_names[event_type][event_code] ? event_names[event_type][event_code] : "?") : "?", 
--- 128,132 ----
  				  }
  				  else
! 					  post("  %s\t%s\t%s",
  							 ev[event_type] ? ev[event_type] : "?", 
  							 event_names[event_type] ? (event_names[event_type][event_code] ? event_names[event_type][event_code] : "?") : "?", 
***************
*** 163,176 ****
  	int i,fd;
  	char device_output_string[256] = "Unknown";
! 	char device_name[20] = "/dev/input/event0";
  
  	post("");
  	for (i=0;i<128;++i) 
  	{
! 		sprintf(device_name,"/dev/input/event%d",i);
! 		if (device_name) 
  		{
  			/* open the device read-only, non-exclusive */
! 			fd = open (device_name, O_RDONLY | O_NONBLOCK);
  			/* test if device open */
  			if (fd < 0 ) 
--- 179,192 ----
  	int i,fd;
  	char device_output_string[256] = "Unknown";
! 	char dev_handle_name[20] = "/dev/input/event0";
  
  	post("");
  	for (i=0;i<128;++i) 
  	{
! 		sprintf(dev_handle_name,"/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 ) 
***************
*** 182,186 ****
  				/* get name of device */
  				ioctl(fd, EVIOCGNAME(sizeof(device_output_string)), device_output_string);
! 				post("Device %d: '%s' on '%s'", i, device_output_string, device_name);
  			  
  				close (fd);
--- 198,202 ----
  				/* 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);
***************
*** 191,216 ****
  }
  
! void hid_convert_linux_buttons_to_numbers(__u16 linux_code, char *hid_code)
! {
! 	if(linux_code >= 0x100) 
! 	{
! 		if(linux_code < BTN_MOUSE)   
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_MISC);  /* numbered buttons */
! 		else if(linux_code < BTN_JOYSTICK)
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_MOUSE);  /* mouse buttons */
! 		else if(linux_code < BTN_GAMEPAD)
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_JOYSTICK);  /* joystick buttons */
! 		else if(linux_code < BTN_DIGI)
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_GAMEPAD);  /* gamepad buttons */
! 		else if(linux_code < BTN_WHEEL)
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_DIGI);  /* tablet buttons */
! 		else if(linux_code < KEY_OK)
! 			sprintf(hid_code,"btn_%d",linux_code - BTN_WHEEL);  /* wheel buttons */
! 	}
! }
! 
! /* ============================================================================== */
  /* Pd [hid] FUNCTIONS */
! /* ============================================================================== */
  
  t_int hid_get_events(t_hid *x)
--- 207,213 ----
  }
  
! /* ------------------------------------------------------------------------------ */
  /* Pd [hid] FUNCTIONS */
! /* ------------------------------------------------------------------------------ */
  
  t_int hid_get_events(t_hid *x)
***************
*** 266,269 ****
--- 263,267 ----
  {
  	hid_print_device_list();
+ 	hid_print_element_list(x);
  }
  
***************
*** 273,277 ****
  	DEBUG(post("hid_open_device"););
  
! 	char device_name[20];
  	struct input_event hid_input_event;
  
--- 271,276 ----
  	DEBUG(post("hid_open_device"););
  
! 	char device_name[256] = "Unknown";
! 	char dev_handle_name[20] = "/dev/input/event0";
  	struct input_event hid_input_event;
  
***************
*** 279,292 ****
    
  	x->x_device_number = device_number;
! 	sprintf(device_name,"/dev/input/event%d",x->x_device_number);
  
!   if (device_name) 
    {
  	  /* open the device read-only, non-exclusive */
! 	  x->x_fd = open(device_name, O_RDONLY | O_NONBLOCK);
  	  /* test if device open */
  	  if (x->x_fd < 0 ) 
  	  { 
! 		  error("[hid] open %s failed",device_name);
  		  x->x_fd = -1;
  		  return 1;
--- 278,291 ----
    
  	x->x_device_number = device_number;
! 	sprintf(dev_handle_name,"/dev/input/event%d",x->x_device_number);
  
!   if (dev_handle_name) 
    {
  	  /* open the device read-only, non-exclusive */
! 	  x->x_fd = open(dev_handle_name, O_RDONLY | O_NONBLOCK);
  	  /* test if device open */
  	  if (x->x_fd < 0 ) 
  	  { 
! 		  error("[hid] open %s failed",dev_handle_name);
  		  x->x_fd = -1;
  		  return 1;
***************
*** 299,302 ****
--- 298,306 ----
    while (read (x->x_fd, &(hid_input_event), sizeof(struct input_event)) > -1);
  
+   /* get name of device */
+   ioctl(x->x_fd, EVIOCGNAME(sizeof(device_name)), device_name);
+   post ("[hid] opened device %d (%s): %s",
+ 		  x->x_device_number,dev_handle_name,device_name);
+ 
    return (0);
  }





More information about the Pd-cvs mailing list