[PD-cvs] externals/io/hidio hidio.c, 1.16, 1.17 hidio.h, 1.14, 1.15 hidio_darwin.c, 1.7, 1.8 hidio_linux.c, 1.5, 1.6 hidio_windows.c, 1.2, 1.3
Hans-Christoph Steiner
eighthave at users.sourceforge.net
Tue Jan 2 06:37:09 CET 2007
Update of /cvsroot/pure-data/externals/io/hidio
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12320
Modified Files:
hidio.c hidio.h hidio_darwin.c hidio_linux.c hidio_windows.c
Log Message:
I cleaned up the return values. This is what I used:
* EXIT_SUCCESS for successful conditions
* -1 for failure when a device number is being returned
* EXIT_FAILURE for all other failures
EXIT_SUCCESS and EXIT_FAILURE are defined in stdlib.h
Index: hidio.h
===================================================================
RCS file: /cvsroot/pure-data/externals/io/hidio/hidio.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** hidio.h 1 Jan 2007 02:17:27 -0000 1.14
--- hidio.h 2 Jan 2007 05:37:06 -0000 1.15
***************
*** 71,87 ****
#define MAX_EVENTS_PER_POLL 50
- /*------------------------------------------------------------------------------
- * THREADING RELATED DEFINES
- */
-
- #define REQUEST_NOTHING 0
- #define REQUEST_OPEN 1
- #define REQUEST_READ 2
- #define REQUEST_SEND 3
- #define REQUEST_PRINT 4
- #define REQUEST_INFO 5
- #define REQUEST_CLOSE 6
- #define REQUEST_QUIT 7
-
/*------------------------------------------------------------------------------
--- 71,74 ----
***************
*** 92,96 ****
{
t_object x_obj;
! #ifndef PD
void *x_obex;
#endif
--- 79,83 ----
{
t_object x_obj;
! #ifndef PD /* Max */
void *x_obex;
#endif
***************
*** 147,151 ****
t_symbol *type; // Linux "type"; HID "usagePage", but using the hidio scheme
t_symbol *name; // Linux "code"; HID "usage", but using the hidio scheme
! unsigned char polled; // is it polled or queued? (maybe only on Mac OS X?)
unsigned char relative; // relative data gets output everytime
t_int min; // from device report
--- 134,138 ----
t_symbol *type; // Linux "type"; HID "usagePage", but using the hidio scheme
t_symbol *name; // Linux "code"; HID "usage", but using the hidio scheme
! unsigned char polled; // is it polled or queued?
unsigned char relative; // relative data gets output everytime
t_int min; // from device report
***************
*** 165,168 ****
--- 152,171 ----
extern unsigned short element_count[MAX_DEVICES];
+
+ /* Each instance registers itself with a hidio_instances[] linked list when it
+ * opens a device. Whichever instance gets the events from the OS will then
+ * go thru this linked list and call its output function. */
+
+ /* basic element of a linked list of hidio instances */
+ typedef struct _hidio_instance
+ {
+ t_hidio *x;
+ struct _hidio_instance *x_next;
+ } t_hidio_instance;
+
+ /* array of linked lists of instances wanting events from a given device. */
+ extern t_hidio_instance *hidio_instances[MAX_DEVICES];
+
+
/*------------------------------------------------------------------------------
* FUNCTION PROTOTYPES FOR DIFFERENT PLATFORMS
***************
*** 192,197 ****
/* cross-platform force feedback functions */
! extern t_int hidio_ff_autocenter(t_hidio *x, t_float value);
! extern t_int hidio_ff_gain(t_hidio *x, t_float value);
extern t_int hidio_ff_motors(t_hidio *x, t_float value);
extern t_int hidio_ff_continue(t_hidio *x);
--- 195,200 ----
/* cross-platform force feedback functions */
! extern void hidio_ff_autocenter(t_hidio *x, t_float value);
! extern void hidio_ff_gain(t_hidio *x, t_float value);
extern t_int hidio_ff_motors(t_hidio *x, t_float value);
extern t_int hidio_ff_continue(t_hidio *x);
Index: hidio.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/hidio/hidio.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** hidio.c 1 Jan 2007 02:17:27 -0000 1.16
--- hidio.c 2 Jan 2007 05:37:06 -0000 1.17
***************
*** 87,91 ****
//static void hidio_poll(t_hidio *x, t_float f);
static void hidio_open(t_hidio *x, t_symbol *s, int argc, t_atom *argv);
! //static t_int hidio_close(t_hidio *x);
//static void hidio_float(t_hidio* x, t_floatarg f);
--- 87,91 ----
//static void hidio_poll(t_hidio *x, t_float f);
static void hidio_open(t_hidio *x, t_symbol *s, int argc, t_atom *argv);
! //static void hidio_close(t_hidio *x);
//static void hidio_float(t_hidio* x, t_floatarg f);
***************
*** 130,134 ****
#ifdef PD
SETFLOAT(output_atom, output_value);
! #else
atom_setlong(output_atom, (long)output_value);
#endif /* PD */
--- 130,134 ----
#ifdef PD
SETFLOAT(output_atom, output_value);
! #else /* Max */
atom_setlong(output_atom, (long)output_value);
#endif /* PD */
***************
*** 185,196 ****
static unsigned int name_to_usage(char *usage_name)
{ // output usagepage << 16 + usage
! if(strcmp(usage_name,"pointer") == 0) return(0x00010001);
! if(strcmp(usage_name,"mouse") == 0) return(0x00010002);
! if(strcmp(usage_name,"joystick") == 0) return(0x00010004);
! if(strcmp(usage_name,"gamepad") == 0) return(0x00010005);
! if(strcmp(usage_name,"keyboard") == 0) return(0x00010006);
! if(strcmp(usage_name,"keypad") == 0) return(0x00010007);
! if(strcmp(usage_name,"multiaxiscontroller") == 0) return(0x00010008);
! return(0);
}
--- 185,196 ----
static unsigned int name_to_usage(char *usage_name)
{ // output usagepage << 16 + usage
! if(strcmp(usage_name,"pointer") == 0) return 0x00010001;
! if(strcmp(usage_name,"mouse") == 0) return 0x00010002;
! if(strcmp(usage_name,"joystick") == 0) return 0x00010004;
! if(strcmp(usage_name,"gamepad") == 0) return 0x00010005;
! if(strcmp(usage_name,"keyboard") == 0) return 0x00010006;
! if(strcmp(usage_name,"keypad") == 0) return 0x00010007;
! if(strcmp(usage_name,"multiaxiscontroller") == 0) return 0x00010008;
! return 0;
}
***************
*** 283,287 ****
}
}
! return(device_number);
}
--- 283,287 ----
}
}
! return device_number;
}
***************
*** 373,377 ****
/* close the device */
! t_int hidio_close(t_hidio *x)
{
debug_post(LOG_DEBUG,"hidio_close");
--- 373,377 ----
/* close the device */
! static void hidio_close(t_hidio *x)
{
debug_post(LOG_DEBUG,"hidio_close");
***************
*** 384,391 ****
debug_post(LOG_INFO,"[hidio] closed device %d",x->x_device_number);
x->x_device_open = 0;
- return (0);
}
-
- return (1);
}
--- 384,388 ----
***************
*** 415,424 ****
if (!x->x_device_open)
{
! if(hidio_open_device(x, new_device_number))
! {
! x->x_device_number = -1;
! error("[hidio] can not open device %d",new_device_number);
! }
! else
{
x->x_device_open = 1;
--- 412,416 ----
if (!x->x_device_open)
{
! if(hidio_open_device(x, new_device_number) == EXIT_SUCCESS)
{
x->x_device_open = 1;
***************
*** 432,435 ****
--- 424,432 ----
output_device_number(x);
}
+ else
+ {
+ x->x_device_number = -1;
+ error("[hidio] can not open device %d",new_device_number);
+ }
}
}
***************
*** 567,571 ****
hidio_instance_count++;
! return (x);
}
--- 564,568 ----
hidio_instance_count++;
! return x;
}
***************
*** 726,730 ****
generate_event_symbols();
! return 0;
}
#endif /* PD */
--- 723,727 ----
generate_event_symbols();
! return EXIT_SUCCESS;
}
#endif /* PD */
Index: hidio_darwin.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/hidio/hidio_darwin.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** hidio_darwin.c 1 Jan 2007 02:17:27 -0000 1.7
--- hidio_darwin.c 2 Jan 2007 05:37:06 -0000 1.8
***************
*** 65,72 ****
// temp hack for measuring latency
! #define LATENCY_MAX 8192
int latency[LATENCY_MAX];
int latency_i;
int latency_average;
// this stuff is moving to the t_hid_element struct
--- 65,74 ----
// temp hack for measuring latency
! /*#define LATENCY_MAX 8192
int latency[LATENCY_MAX];
int latency_i;
int latency_average;
+ //end latency hack
+ */
// this stuff is moving to the t_hid_element struct
***************
*** 282,285 ****
--- 284,289 ----
/* ============================================================================== */
+ /*
+ // temp hack for measuring latency
double calculate_event_latency( uint64_t endTime, uint64_t startTime )
{
***************
*** 299,303 ****
return conversion * (double) difference;
}
!
short get_device_number_by_id(unsigned short vendor_id, unsigned short product_id)
--- 303,307 ----
return conversion * (double) difference;
}
! //end latency hack */
short get_device_number_by_id(unsigned short vendor_id, unsigned short product_id)
***************
*** 380,386 ****
}
if(i < total_devices)
! return(return_device_number);
else
! return(-1);
}
--- 384,390 ----
}
if(i < total_devices)
! return return_device_number;
else
! return -1;
}
***************
*** 677,682 ****
timestamp = * (uint64_t *) &(event.timestamp);
now = mach_absolute_time();
difference = calculate_event_latency(now, timestamp);
- // temp hack to measure latency
if( latency_i < LATENCY_MAX)
{
--- 681,687 ----
timestamp = * (uint64_t *) &(event.timestamp);
now = mach_absolute_time();
+ /*
+ // temp hack for measuring latency
difference = calculate_event_latency(now, timestamp);
if( latency_i < LATENCY_MAX)
{
***************
*** 693,696 ****
--- 698,703 ----
latency_average = 0;
}
+ // end latency hack
+ */
}
/* absolute axes don't need to be queued, they can just be polled */
***************
*** 707,722 ****
}
- // TODO: return the same as POSIX open()/close() - 0=success, -1=fail
t_int hidio_open_device(t_hidio *x, short device_number)
{
debug_post(LOG_DEBUG,"hidio_open_device");
- t_int result = 0;
pRecDevice pCurrentHIDDevice = NULL;
-
io_service_t hidDevice = 0;
FFDeviceObjectReference ffDeviceReference = NULL;
! latency_i = 0;latency_average = 0; // temp hack, to be removed
/* rebuild device list to make sure the list is current */
--- 714,726 ----
}
t_int hidio_open_device(t_hidio *x, short device_number)
{
debug_post(LOG_DEBUG,"hidio_open_device");
pRecDevice pCurrentHIDDevice = NULL;
io_service_t hidDevice = 0;
FFDeviceObjectReference ffDeviceReference = NULL;
! // latency_i = 0;latency_average = 0; // temp hack for measuring latency
/* rebuild device list to make sure the list is current */
***************
*** 732,736 ****
{
debug_error(x,LOG_ERR,"[hidio]: device %d is not a valid device\n",device_number);
! return(1);
}
debug_post(LOG_WARNING,"[hidio] opened device %d: %s %s",
--- 736,740 ----
{
debug_error(x,LOG_ERR,"[hidio]: device %d is not a valid device\n",device_number);
! return EXIT_FAILURE;
}
debug_post(LOG_WARNING,"[hidio] opened device %d: %s %s",
***************
*** 752,775 ****
x->x_has_ff = 0;
post("[hidio]: FF device creation failed!");
! return( -1 );
}
}
! return(result);
}
! // TODO: return the same as POSIX open()/close() - 0=success, -1=fail
t_int hidio_close_device(t_hidio *x)
{
debug_post(LOG_DEBUG,"hidio_close_device");
- t_int result = 0;
- // pRecDevice pCurrentHIDDevice = hidio_get_device_by_number(x->x_device_number);
pRecDevice pCurrentHIDDevice = device_pointer[x->x_device_number];
!
! HIDDequeueDevice(pCurrentHIDDevice);
! // this doesn't seem to be needed at all, but why not use it?
! // result = HIDCloseReleaseInterface(pCurrentHIDDevice);
!
! return(result);
}
--- 756,772 ----
x->x_has_ff = 0;
post("[hidio]: FF device creation failed!");
! return EXIT_FAILURE;
}
}
! return EXIT_SUCCESS;
}
!
t_int hidio_close_device(t_hidio *x)
{
debug_post(LOG_DEBUG,"hidio_close_device");
pRecDevice pCurrentHIDDevice = device_pointer[x->x_device_number];
! return HIDDequeueDevice(pCurrentHIDDevice);
}
***************
*** 829,833 ****
{
fprintf(stderr,"%d ",latency[j]);
! }*/
}
--- 826,831 ----
{
fprintf(stderr,"%d ",latency[j]);
! x }
! */
}
***************
*** 842,846 ****
*/
! t_int hidio_ff_autocenter(t_hidio *x, t_float value)
{
debug_post(LOG_DEBUG,"hidio_ff_autocenter");
--- 840,844 ----
*/
! void hidio_ff_autocenter(t_hidio *x, t_float value)
{
debug_post(LOG_DEBUG,"hidio_ff_autocenter");
***************
*** 862,870 ****
}
}
-
- return(0);
}
! t_int hidio_ff_gain(t_hidio *x, t_float value)
{
debug_post(LOG_DEBUG,"hidio_ff_gain");
--- 860,866 ----
}
}
}
! void hidio_ff_gain(t_hidio *x, t_float value)
{
debug_post(LOG_DEBUG,"hidio_ff_gain");
***************
*** 886,891 ****
}
}
-
- return(0);
}
--- 882,885 ----
***************
*** 964,968 ****
debug_post(LOG_DEBUG,"hidio_ff_fftest");
! return( 0 );
}
--- 958,962 ----
debug_post(LOG_DEBUG,"hidio_ff_fftest");
! return EXIT_SUCCESS;
}
Index: hidio_windows.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/hidio/hidio_windows.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** hidio_windows.c 1 Jan 2007 01:06:11 -0000 1.2
--- hidio_windows.c 2 Jan 2007 05:37:07 -0000 1.3
***************
*** 60,69 ****
/* ============================================================================== */
- void hidio_get_device_by_number(t_int device_number)
- {
-
- }
-
-
void hidio_build_element_list(t_hidio *x)
{
--- 60,63 ----
***************
*** 71,83 ****
}
! t_int hidio_print_element_list(t_hidio *x)
{
debug_post(LOG_DEBUG,"hidio_print_element_list");
! return (0);
}
! t_int hidio_print_device_list(t_hidio *x)
{
struct _GUID GUID;
--- 65,77 ----
}
! static void hidio_print_element_list(t_hidio *x)
{
debug_post(LOG_DEBUG,"hidio_print_element_list");
! return EXIT_SUCCESS;
}
! static t_int hidio_print_device_list(t_hidio *x)
{
struct _GUID GUID;
***************
*** 166,170 ****
SetupDiDestroyDeviceInfoList(PnPHandle);
#endif
! return 0;
}
--- 160,164 ----
SetupDiDestroyDeviceInfoList(PnPHandle);
#endif
! return EXIT_SUCCESS;
}
***************
*** 191,195 ****
t_int hidio_ff_autocenter( t_hidio *x, t_float value )
{
! return ( 0 );
}
--- 185,189 ----
t_int hidio_ff_autocenter( t_hidio *x, t_float value )
{
! return EXIT_SUCCESS;
}
***************
*** 197,201 ****
t_int hidio_ff_gain( t_hidio *x, t_float value )
{
! return ( 0 );
}
--- 191,195 ----
t_int hidio_ff_gain( t_hidio *x, t_float value )
{
! return EXIT_SUCCESS;
}
***************
*** 203,207 ****
t_int hidio_ff_motors( t_hidio *x, t_float value )
{
! return ( 0 );
}
--- 197,201 ----
t_int hidio_ff_motors( t_hidio *x, t_float value )
{
! return EXIT_SUCCESS;
}
***************
*** 209,213 ****
t_int hidio_ff_continue( t_hidio *x )
{
! return ( 0 );
}
--- 203,207 ----
t_int hidio_ff_continue( t_hidio *x )
{
! return EXIT_SUCCESS;
}
***************
*** 215,219 ****
t_int hidio_ff_pause( t_hidio *x )
{
! return ( 0 );
}
--- 209,213 ----
t_int hidio_ff_pause( t_hidio *x )
{
! return EXIT_SUCCESS;
}
***************
*** 221,225 ****
t_int hidio_ff_reset( t_hidio *x )
{
! return ( 0 );
}
--- 215,219 ----
t_int hidio_ff_reset( t_hidio *x )
{
! return EXIT_SUCCESS;
}
***************
*** 227,231 ****
t_int hidio_ff_stopall( t_hidio *x )
{
! return ( 0 );
}
--- 221,225 ----
t_int hidio_ff_stopall( t_hidio *x )
{
! return EXIT_SUCCESS;
}
***************
*** 235,239 ****
t_int hidio_ff_fftest ( t_hidio *x, t_float value)
{
! return ( 0 );
}
--- 229,233 ----
t_int hidio_ff_fftest ( t_hidio *x, t_float value)
{
! return EXIT_SUCCESS;
}
***************
*** 247,255 ****
/* ============================================================================== */
! t_int hidio_get_events(t_hidio *x)
{
//debug_post(LOG_DEBUG,"hidio_get_events");
-
- return (0);
}
--- 241,247 ----
/* ============================================================================== */
! void hidio_get_events(t_hidio *x)
{
//debug_post(LOG_DEBUG,"hidio_get_events");
}
***************
*** 258,265 ****
{
debug_post(LOG_DEBUG,"hidio_open_device");
- t_int result = 0;
-
! return(result);
}
--- 250,255 ----
{
debug_post(LOG_DEBUG,"hidio_open_device");
! return EXIT_SUCCESS;
}
***************
*** 269,279 ****
debug_post(LOG_DEBUG,"hidio_close_device");
! t_int result = 0;
!
! return(result);
}
! t_int hidio_build_device_list(t_hidio *x)
{
debug_post(LOG_DEBUG,"hidio_build_device_list");
--- 259,267 ----
debug_post(LOG_DEBUG,"hidio_close_device");
! return EXIT_SUCCESS;
}
! void hidio_build_device_list(t_hidio *x)
{
debug_post(LOG_DEBUG,"hidio_build_device_list");
***************
*** 293,297 ****
{
error("[hidio] ERROR: cannot get SystemRoot");
- return 0;
}
strcat(hidDllPath,"\\hid.dll");
--- 281,284 ----
***************
*** 301,308 ****
{
error("[hidio] ERROR: couldn't load %s: error %d",hidDllPath,GetLastError());
- return 0;
}
-
- return 1;
}
--- 288,292 ----
Index: hidio_linux.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/hidio/hidio_linux.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** hidio_linux.c 1 Jan 2007 02:17:27 -0000 1.5
--- hidio_linux.c 2 Jan 2007 05:37:07 -0000 1.6
***************
*** 437,441 ****
}
! // TODO: return the same as POSIX open()/close() - 0=success, -1=fail
t_int hidio_open_device(t_hidio *x, short device_number)
{
--- 437,441 ----
}
!
t_int hidio_open_device(t_hidio *x, short device_number)
{
***************
*** 460,464 ****
error("[hidio] open %s failed",block_device);
x->x_fd = -1;
! return 1;
}
}
--- 460,464 ----
error("[hidio] open %s failed",block_device);
x->x_fd = -1;
! return EXIT_FAILURE;
}
}
***************
*** 477,481 ****
hidio_build_element_list(x);
! return (0);
}
--- 477,481 ----
hidio_build_element_list(x);
! return EXIT_SUCCESS;
}
***************
*** 485,492 ****
{
debug_post(LOG_DEBUG,"hidio_close_device");
! if(x->x_fd <0)
! return 0;
! else
return (close(x->x_fd));
}
--- 485,492 ----
{
debug_post(LOG_DEBUG,"hidio_close_device");
! if(x->x_fd > -1)
return (close(x->x_fd));
+ else
+ return EXIT_SUCCESS;
}
***************
*** 520,529 ****
/* post("Nothing on %s.", &block_device); */
fd = -1;
- /* return 0; */
} else {
/* read input_events from the LINUX_BLOCK_DEVICE stream
! * It seems that is just there to flush the event input buffer?
! */
! while (read (fd, &(x_input_event), sizeof(struct input_event)) > -1);
/* get name of device */
--- 520,527 ----
/* post("Nothing on %s.", &block_device); */
fd = -1;
} else {
/* read input_events from the LINUX_BLOCK_DEVICE stream
! * It seems that is just there to flush the event input buffer? */
! while( read(fd, &(x_input_event),sizeof(struct input_event)) > -1 );
/* get name of device */
***************
*** 599,603 ****
t_int hidio_ff_autocenter( t_hidio *x, t_float value )
{
! return ( 0 );
}
--- 597,601 ----
t_int hidio_ff_autocenter( t_hidio *x, t_float value )
{
! return EXIT_SUCCESS;
}
***************
*** 605,609 ****
t_int hidio_ff_gain( t_hidio *x, t_float value )
{
! return ( 0 );
}
--- 603,607 ----
t_int hidio_ff_gain( t_hidio *x, t_float value )
{
! return EXIT_SUCCESS;
}
***************
*** 611,615 ****
t_int hidio_ff_motors( t_hidio *x, t_float value )
{
! return ( 0 );
}
--- 609,613 ----
t_int hidio_ff_motors( t_hidio *x, t_float value )
{
! return EXIT_SUCCESS;
}
***************
*** 617,621 ****
t_int hidio_ff_continue( t_hidio *x )
{
! return ( 0 );
}
--- 615,619 ----
t_int hidio_ff_continue( t_hidio *x )
{
! return EXIT_SUCCESS;
}
***************
*** 623,627 ****
t_int hidio_ff_pause( t_hidio *x )
{
! return ( 0 );
}
--- 621,625 ----
t_int hidio_ff_pause( t_hidio *x )
{
! return EXIT_SUCCESS;
}
***************
*** 629,633 ****
t_int hidio_ff_reset( t_hidio *x )
{
! return ( 0 );
}
--- 627,631 ----
t_int hidio_ff_reset( t_hidio *x )
{
! return EXIT_SUCCESS;
}
***************
*** 635,639 ****
t_int hidio_ff_stopall( t_hidio *x )
{
! return ( 0 );
}
--- 633,637 ----
t_int hidio_ff_stopall( t_hidio *x )
{
! return EXIT_SUCCESS;
}
***************
*** 643,647 ****
t_int hidio_ff_fftest ( t_hidio *x, t_float value)
{
! return ( 0 );
}
--- 641,645 ----
t_int hidio_ff_fftest ( t_hidio *x, t_float value)
{
! return EXIT_SUCCESS;
}
More information about the Pd-cvs
mailing list