[PD-cvs] externals/io/hidio hidio.c, 1.2, 1.3 hidio.h, 1.1, 1.2 hidio_darwin.c, 1.1, 1.2 input_arrays.h, 1.1, 1.2

Olaf Matthes olafmatt at users.sourceforge.net
Fri Dec 1 16:07:48 CET 2006


Update of /cvsroot/pure-data/externals/io/hidio
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9543

Modified Files:
	hidio.c hidio.h hidio_darwin.c input_arrays.h 
Log Message:
initial Max port for Max 4.5 on OS 


Index: input_arrays.h
===================================================================
RCS file: /cvsroot/pure-data/externals/io/hidio/input_arrays.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** input_arrays.h	30 Nov 2006 05:53:40 -0000	1.1
--- input_arrays.h	1 Dec 2006 15:07:46 -0000	1.2
***************
*** 3,40 ****
  
  
! char *ev[32];
! char *ev_syn[512];
! char *ev_key[512];
! char *ev_rel[16];
! char *ev_abs[64];
! char *ev_msc[8];
! char *ev_led[16];
! char *ev_snd[8];
! char *ev_rep[2];
! char *ev_ff[128];
! char *ev_pwr[1];
! char *ev_ff_status[2];
! char *ev_5[16];
! char *ev_6[16];
! char *ev_7[16];
! char *ev_8[16];
! char *ev_9[16];
! char *ev_10[16];
! char *ev_11[16];
! char *ev_12[16];
! char *ev_13[16];
! char *ev_14[16];
! char *ev_15[16];
! char *ev_16[16];
! char *ev_19[16];
! char *ev_24[16];
! char *ev_25[16];
! char *ev_26[16];
! char *ev_27[16];
! char *ev_28[16];
! char *ev_29[16];
! char *ev_30[16];
! char *ev_31[16];
! char **event_names[32];
  
  
--- 3,40 ----
  
  
! extern char *ev[32];
! extern char *ev_syn[512];
! extern char *ev_key[512];
! extern char *ev_rel[16];
! extern char *ev_abs[64];
! extern char *ev_msc[8];
! extern char *ev_led[16];
! extern char *ev_snd[8];
! extern char *ev_rep[2];
! extern char *ev_ff[128];
! extern char *ev_pwr[1];
! extern char *ev_ff_status[2];
! extern char *ev_5[16];
! extern char *ev_6[16];
! extern char *ev_7[16];
! extern char *ev_8[16];
! extern char *ev_9[16];
! extern char *ev_10[16];
! extern char *ev_11[16];
! extern char *ev_12[16];
! extern char *ev_13[16];
! extern char *ev_14[16];
! extern char *ev_15[16];
! extern char *ev_16[16];
! extern char *ev_19[16];
! extern char *ev_24[16];
! extern char *ev_25[16];
! extern char *ev_26[16];
! extern char *ev_27[16];
! extern char *ev_28[16];
! extern char *ev_29[16];
! extern char *ev_30[16];
! extern char *ev_31[16];
! extern char **event_names[32];
  
  

Index: hidio_darwin.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/hidio/hidio_darwin.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** hidio_darwin.c	30 Nov 2006 05:53:40 -0000	1.1
--- hidio_darwin.c	1 Dec 2006 15:07:46 -0000	1.2
***************
*** 409,413 ****
  							pCurrentHIDElement->usage, usage_name);
  
! 			new_element = getbytes(sizeof(t_hid_element));
  			new_element->pHIDElement = (void *) pCurrentHIDElement;
  			get_usage_symbols(pCurrentHIDElement, new_element);
--- 409,413 ----
  							pCurrentHIDElement->usage, usage_name);
  
! 			new_element = (t_hid_element *)getbytes(sizeof(t_hid_element));
  			new_element->pHIDElement = (void *) pCurrentHIDElement;
  			get_usage_symbols(pCurrentHIDElement, new_element);
***************
*** 563,567 ****
  	char device_type_buffer[256];
  	t_symbol *output_symbol;
! 	t_atom *output_atom = getbytes(sizeof(t_atom));
  
  	if(x->x_device_number > -1)
--- 563,567 ----
  	char device_type_buffer[256];
  	t_symbol *output_symbol;
! 	t_atom *output_atom = (t_atom *)getbytes(sizeof(t_atom));
  
  	if(x->x_device_number > -1)
***************
*** 583,587 ****
--- 583,591 ----
  			{
  				output_symbol = gensym(pCurrentHIDDevice->serial);
+ #ifdef PD
  				if( output_symbol != &s_ )
+ #else
+ 				if( output_symbol != _sym_nothing )
+ #endif
  				{ /* the serial is rarely used on USB devices, so test for it */
  					SETSYMBOL(output_atom, output_symbol);

Index: hidio.h
===================================================================
RCS file: /cvsroot/pure-data/externals/io/hidio/hidio.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** hidio.h	30 Nov 2006 05:53:40 -0000	1.1
--- hidio.h	1 Dec 2006 15:07:46 -0000	1.2
***************
*** 9,13 ****
--- 9,28 ----
  #endif /* __linux__ */
  
+ #ifdef PD
  #include <m_pd.h>
+ #else
+ #include "ext.h"
+ #include "ext_obex.h"
+ #include "commonsyms.h"
+ /* some Pd specific types need definition in Max */
+ typedef long t_int;
+ typedef double t_float;
+ typedef double t_floatarg;
+ typedef void t_outlet;
+ typedef void t_clock;
+ #define MAXPDSTRING 512
+ #define pd_error(x, b) error(b)
+ #define SETSYMBOL SETSYM
+ #endif
  
  /* 
***************
*** 45,48 ****
--- 60,66 ----
  {
  	t_object            x_obj;
+ #ifndef PD
+ 	void				*x_obex;
+ #endif
  	t_int               x_fd;
  	void                *x_ff_device;
***************
*** 67,74 ****
   * functions can be called only after the final instance is detroyed.
   */
! t_int hidio_instance_count;
  
  /* this is used to test for the first instance to execute */
! double last_execute_time[MAX_DEVICES];
  
  extern unsigned short global_debug_level;
--- 85,92 ----
   * functions can be called only after the final instance is detroyed.
   */
! extern t_int hidio_instance_count;
  
  /* this is used to test for the first instance to execute */
! extern double last_execute_time[MAX_DEVICES];
  
  extern unsigned short global_debug_level;
***************
*** 100,109 ****
  
  /* mostly for status querying */
! unsigned short device_count;
  
  /* store element structs to eliminate symbol table lookups, etc. */
! t_hid_element *element[MAX_DEVICES][MAX_ELEMENTS];
  /* number of active elements per device */
! unsigned short element_count[MAX_DEVICES]; 
  
  /*------------------------------------------------------------------------------
--- 118,127 ----
  
  /* mostly for status querying */
! extern unsigned short device_count;
  
  /* store element structs to eliminate symbol table lookups, etc. */
! extern t_hid_element *element[MAX_DEVICES][MAX_ELEMENTS];
  /* number of active elements per device */
! extern unsigned short element_count[MAX_DEVICES]; 
  
  /*------------------------------------------------------------------------------

Index: hidio.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/hidio/hidio.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** hidio.c	30 Nov 2006 06:14:59 -0000	1.2
--- hidio.c	1 Dec 2006 15:07:46 -0000	1.3
***************
*** 41,46 ****
--- 41,66 ----
  unsigned short global_debug_level = 0;
  
+ /*------------------------------------------------------------------------------
+  *  GLOBAL VARIABLES
+  */
+ 
+ /* count the number of instances of this object so that certain free()
+  * functions can be called only after the final instance is detroyed.
+  */
+ t_int hidio_instance_count;
+ 
+ /* this is used to test for the first instance to execute */
+ double last_execute_time[MAX_DEVICES];
+ 
  static t_class *hidio_class;
  
+ /* mostly for status querying */
+ unsigned short device_count;
+ 
+ /* store element structs to eliminate symbol table lookups, etc. */
+ t_hid_element *element[MAX_DEVICES][MAX_ELEMENTS];
+ /* number of active elements per device */
+ unsigned short element_count[MAX_DEVICES]; 
+ 
  /*------------------------------------------------------------------------------
   * FUNCTION PROTOTYPES
***************
*** 89,93 ****
  static void output_status(t_hidio *x, t_symbol *selector, t_float output_value)
  {
! 	t_atom *output_atom = getbytes(sizeof(t_atom));
  	SETFLOAT(output_atom, output_value);
  	outlet_anything( x->x_status_outlet, selector, 1, output_atom);
--- 109,113 ----
  static void output_status(t_hidio *x, t_symbol *selector, t_float output_value)
  {
! 	t_atom *output_atom = (t_atom *)getbytes(sizeof(t_atom));
  	SETFLOAT(output_atom, output_value);
  	outlet_anything( x->x_status_outlet, selector, 1, output_atom);
***************
*** 149,158 ****
  static short get_device_number_from_arguments(int argc, t_atom *argv)
  {
  	short device_number = -1;
  	unsigned short device_type_instance;
  	unsigned int usage;
  	unsigned short vendor_id;
  	unsigned short product_id;
- 	char device_type_string[MAXPDSTRING] = "";
  	t_symbol *first_argument;
  	t_symbol *second_argument;
--- 169,184 ----
  static short get_device_number_from_arguments(int argc, t_atom *argv)
  {
+ #ifdef PD
  	short device_number = -1;
+ 	char device_type_string[MAXPDSTRING] = "";
  	unsigned short device_type_instance;
+ #else
+ 	long device_number = -1;
+ 	char *device_type_string;
+ 	long device_type_instance;
+ #endif
  	unsigned int usage;
  	unsigned short vendor_id;
  	unsigned short product_id;
  	t_symbol *first_argument;
  	t_symbol *second_argument;
***************
*** 160,168 ****
--- 186,203 ----
  	if(argc == 1)
  	{
+ #ifdef PD
  		first_argument = atom_getsymbolarg(0,argc,argv);
  		if(first_argument == &s_) 
+ #else
+ 		atom_arg_getsym(&first_argument, 0,argc,argv);
+ 		if(first_argument == _sym_nothing) 
+ #endif
  		{ // 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
  			if(device_number < 0) device_number = -1;
  			debug_print(LOG_DEBUG,"[hidio] setting device# to %d",device_number);
***************
*** 170,174 ****
--- 205,214 ----
  		else
  		{ // single symbol arg means first instance of a device type
+ #ifdef PD
  			atom_string(argv, device_type_string, MAXPDSTRING-1);
+ #else
+ 			device_type_string = atom_string(argv);
+ 			// LATER do we have to free this string manually???
+ #endif
  			usage = name_to_usage(device_type_string);
  			device_number = get_device_number_from_usage(0, usage >> 16, 
***************
*** 180,190 ****
--- 220,242 ----
  	else if(argc == 2)
  	{ 
+ #ifdef PD
  		first_argument = atom_getsymbolarg(0,argc,argv);
  		second_argument = atom_getsymbolarg(1,argc,argv);
  		if( second_argument == &s_ ) 
+ #else
+ 		atom_arg_getsym(&first_argument, 0,argc,argv);
+ 		atom_arg_getsym(&second_argument, 1,argc,argv);
+ 		if( second_argument == _sym_nothing ) 
+ #endif
  		{ /* a symbol then a float means match on usage */
+ #ifdef PD
  			atom_string(argv, device_type_string, MAXPDSTRING-1);
  			usage = name_to_usage(device_type_string);
  			device_type_instance = atom_getfloatarg(1,argc,argv);
+ #else
+ 			device_type_string = atom_string(argv);
+ 			usage = name_to_usage(device_type_string);
+ 			atom_arg_getlong(&device_type_instance, 1, argc, argv);
+ #endif
  			debug_print(LOG_DEBUG,"[hidio] looking for %s at #%d",
  						device_type_string, device_type_instance);
***************
*** 341,345 ****
--- 393,401 ----
  //	debug_print(LOG_DEBUG,"hidio_read");
  	unsigned int i;
+ #ifdef PD
  	double right_now = clock_getlogicaltime();
+ #else
+ 	double right_now = (double)systime_ms();
+ #endif
  	t_hid_element *current_element;
  	
***************
*** 387,390 ****
--- 443,455 ----
  }
  
+ #ifndef PD
+ static void hidio_int(t_hidio* x, long l) 
+ {
+ 	debug_print(LOG_DEBUG,"hid_int");
+ 
+ 	hidio_set_from_float(x, (float)l);
+ }
+ #endif
+ 
  static void hidio_debug(t_hidio *x, t_float f)
  {
***************
*** 410,413 ****
--- 475,479 ----
  static void *hidio_new(t_symbol *s, int argc, t_atom *argv) 
  {
+ #ifdef PD
  	t_hidio *x = (t_hidio *)pd_new(hidio_class);
  	unsigned int i;
***************
*** 432,435 ****
--- 498,519 ----
    x->x_data_outlet = outlet_new(&x->x_obj, 0);
    x->x_status_outlet = outlet_new(&x->x_obj, 0);
+ #else /* Max */
+ 	t_hidio *x = (t_hidio *)object_alloc(hidio_class);
+ 	unsigned int i;
+ 	
+   /* 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;
+ 
+   x->x_clock = clock_new(x, (method)hidio_read);
+ 
+   /* create anything outlet used for HID data */ 
+   x->x_status_outlet = outlet_new(x, "anything");
+   x->x_data_outlet = outlet_new(x, "anything");
+ #endif
  
    x->x_device_number = get_device_number_from_arguments(argc, argv);
***************
*** 441,444 ****
--- 525,529 ----
  }
  
+ #ifdef PD
  void hidio_setup(void) 
  {
***************
*** 481,483 ****
--- 566,654 ----
  	post("\tcompiled on "__DATE__" at "__TIME__ " ");
  }
+ #else /* Max */
+ static void hidio_notify(t_hidio *x, t_symbol *s, t_symbol *msg, void *sender, void *data)
+ {
+ 	if (msg == _sym_free)	// this message is sent when a child object is freeing
+ 	{
+ 		object_detach(gensym("_obex_hidio"), s, x);
+ 		object_unregister(sender); 
+ 	}
+ }
+ 
+ static void hidio_assist(t_hidio *x, void *b, long m, long a, char *s)
+ {
+ 	if (m == 2)
+ 	{
+ 		sprintf(s, "hidio outlet");
+ 	}
+ 	else
+ 	{
+ 		switch (a)
+ 		{	
+ 		case 0:
+ 			sprintf(s, "inlet 1");
+ 			break;
+ 		case 1:
+ 			sprintf(s, "inlet 2");
+ 			break;
+ 		}
+ 	}
+ }
+ 
+ int main()
+ {
+ 	t_class	*c;
+ 	
+ 	c = class_new("hidio", (method)hidio_new, (method)hidio_free, (short)sizeof(t_hidio), 
+ 		0L, A_GIMME, 0);
+ 	
+ 	/* initialize the common symbols, since we want to use them */
+ 	common_symbols_init();
+ 
+ 	/* register the byte offset of obex with the class */
+ 	class_obexoffset_set(c, calcoffset(t_hidio, x_obex));
+ 	
+ 	/* add methods to the class */
+ 	class_addmethod(c, (method)hidio_int, 			"int",	 		A_LONG, 0);  
+ 	class_addmethod(c, (method)hidio_float,			"float", 		A_FLOAT, 0);  
+ 	class_addmethod(c, (method)hidio_read, 			"bang",	 		A_GIMME, 0); 
+ 	
+ 	/* add inlet message methods */
+ 	class_addmethod(c, (method)hidio_debug, "debug",A_DEFFLOAT,0);
+ 	class_addmethod(c, (method)hidio_build_device_list, "refresh",0);
+ 	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);
+ 	class_addmethod(c, (method)hidio_close, "close",0);
+ 	class_addmethod(c, (method)hidio_poll, "poll",A_DEFFLOAT,0);
+    /* force feedback messages */
+ 	class_addmethod(c, (method)hidio_ff_autocenter, "ff_autocenter",A_DEFFLOAT,0);
+ 	class_addmethod(c, (method)hidio_ff_gain, "ff_gain",A_DEFFLOAT,0);
+ 	class_addmethod(c, (method)hidio_ff_motors, "ff_motors",A_DEFFLOAT,0);
+ 	class_addmethod(c, (method)hidio_ff_continue, "ff_continue",0);
+ 	class_addmethod(c, (method)hidio_ff_pause, "ff_pause",0);
+ 	class_addmethod(c, (method)hidio_ff_reset, "ff_reset",0);
+ 	class_addmethod(c, (method)hidio_ff_stopall, "ff_stopall",0);
+ 	/* ff tests */
+ 	class_addmethod(c, (method)hidio_ff_fftest, "fftest",A_DEFFLOAT,0);
+ 	class_addmethod(c, (method)hidio_ff_print, "ff_print",0);
+ 
+ 	class_addmethod(c, (method)hidio_assist, 		"assist",	 	A_CANT, 0);  
+ 
+ 	/* add a notify method, so we get notifications from child objects */
+ 	class_addmethod(c, (method)hidio_notify,		"notify",		A_CANT, 0); 
+ 	// add methods for dumpout and quickref	
+ 	class_addmethod(c, (method)object_obex_dumpout,		"dumpout",		A_CANT, 0); 
+ 	class_addmethod(c, (method)object_obex_quickref,	"quickref",		A_CANT, 0);
+ 
+ 	/* we want this class to instantiate inside of the Max UI; ergo CLASS_BOX */
+ 	class_register(CLASS_BOX, c);
+ 	hidio_class = c;
+ 
+ 	finder_addclass("Devices", "hidio");
+ 	post("hidio: © 2006 by Olaf Matthes");
+ 
+ 	return 0;
+ }
+ #endif
  





More information about the Pd-cvs mailing list