Update of /cvsroot/pure-data/externals/hcs/hid In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2687
Modified Files: Makefile TODO hid.c hid.h hid_darwin.c Log Message:
- got ff_autocenter and ff_gain working fine, now its time for some actual effects!!
Index: TODO =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/TODO,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** TODO 6 Jun 2005 22:39:50 -0000 1.18 --- TODO 10 Jun 2005 20:17:42 -0000 1.19 *************** *** 28,36 ****
============================================================================== ! = make second outlet for device name ! ! just output the USB device name to the second outlet
! - maybe the manufacturer too?
--- 28,34 ----
============================================================================== ! = Report available FF effects
! - check against HID Utilities Source/PID.h
Index: hid_darwin.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid_darwin.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** hid_darwin.c 10 Jun 2005 03:45:31 -0000 1.17 --- hid_darwin.c 10 Jun 2005 20:17:42 -0000 1.18 *************** *** 44,47 **** --- 44,48 ----
#include "HID_Utilities_External.h" + #include "ImmrHIDUtilAddOn.h"
#include <IOKit/hid/IOHIDUsageTables.h> *************** *** 208,215 **** }
- t_int hid_print_element_list(t_hid *x) { ! DEBUG(post("hid_build_element_list"););
UInt32 i; --- 209,215 ---- }
t_int hid_print_element_list(t_hid *x) { ! DEBUG(post("hid_print_element_list"););
UInt32 i; *************** *** 263,266 **** --- 263,291 ----
+ void hid_ff_print( t_hid *x ) + { + DEBUG(post("hid_ff_print");); + HRESULT result; + UInt32 value; + + if ( x->x_has_ff ) + { + result = FFDeviceGetForceFeedbackProperty( (FFDeviceObjectReference) x->x_ff_device, + FFPROP_AUTOCENTER, + &value, + (IOByteCount) sizeof( value ) ); + if ( result == FF_OK ) post( "autocenter: %d",value ); + + result = FFDeviceGetForceFeedbackProperty( (FFDeviceObjectReference) x->x_ff_device, + FFPROP_FFGAIN, + &value, + (IOByteCount) sizeof( value ) ); + if ( result == FF_OK ) post( "gain: %d", value ); + } + + // FFEffectGetParameters( ); + } + + void hid_print_device_list(t_hid *x) { *************** *** 268,272 **** t_int i,numdevs; UInt32 usagePage, usage; ! pRecDevice pCurrentHIDDevice;
if( HIDHaveDeviceList() ) --- 293,297 ---- t_int i,numdevs; UInt32 usagePage, usage; ! pRecDevice pCurrentHIDDevice = NULL;
if( HIDHaveDeviceList() ) *************** *** 309,312 **** --- 334,470 ---- }
+ /* ============================================================================== + * FORCE FEEDBACK + * ============================================================================== */ + + /* -------------------------------------------------------------------------- + * FF "Properties" + * autocenter ( 0/1 ), ffgain (overall feedback gain 0-10000) + */ + + t_int hid_ff_autocenter(t_hid *x, t_float value) + { + DEBUG(post("hid_ff_autocenter");); + HRESULT result; + UInt32 autocenter_value; + + if( x->x_has_ff ) + { + if ( value > 0 ) autocenter_value = 1; + else if ( value <= 0 ) autocenter_value = 0; + /* FFPROP_AUTOCENTER is either 0 or 1 */ + result = FFDeviceSetForceFeedbackProperty( + (FFDeviceObjectReference) x->x_ff_device, + FFPROP_AUTOCENTER, + &autocenter_value ); + if ( result != FF_OK ) + { + post("[hid]: ff_autocenter failed!"); + } + } + + return(0); + } + + t_int hid_ff_gain(t_hid *x, t_float value) + { + DEBUG(post("hid_ff_gain");); + HRESULT result; + UInt32 ffgain_value; + + if( x->x_has_ff ) + { + if ( value > 1 ) value = 1; + else if ( value < 0 ) value = 0; + ffgain_value = value * 10000; + /* FFPROP_FFGAIN has a integer range of 0-10000 */ + result = FFDeviceSetForceFeedbackProperty( + (FFDeviceObjectReference)x->x_ff_device, FFPROP_FFGAIN, &ffgain_value ); + if ( result != FF_OK ) + { + post("[hid]: ff_gain failed!"); + } + } + + return(0); + } + + /* -------------------------------------------------------------------------- + * FF "Commands" + * continue, pause, reset, setactuatorsoff, setactuatorson, stopall + */ + + t_int hid_ff_send_ff_command (t_hid *x, UInt32 ff_command) + { + HRESULT result = 0; + + if( x->x_has_ff ) + { + result = FFDeviceSendForceFeedbackCommand( x->x_ff_device, ff_command ); + } + + return ( (t_int) result ); + } + + t_int hid_ff_continue( t_hid *x ) + { + DEBUG(post("hid_ff_continue");); + return( hid_ff_send_ff_command( x, FFSFFC_CONTINUE ) ); + } + + t_int hid_ff_pause( t_hid *x ) + { + DEBUG(post("hid_ff_pause");); + return( hid_ff_send_ff_command( x, FFSFFC_PAUSE ) ); + } + + t_int hid_ff_reset( t_hid *x ) + { + DEBUG(post("hid_ff_reset");); + return( hid_ff_send_ff_command( x, FFSFFC_RESET ) ); + } + + t_int hid_ff_setactuatorsoff( t_hid *x ) + { + DEBUG(post("hid_ff_setactuatorsoff");); + return( hid_ff_send_ff_command( x, FFSFFC_SETACTUATORSOFF ) ); + } + + t_int hid_ff_setactuatorson( t_hid *x ) + { + DEBUG(post("hid_ff_setactuatorson");); + return( hid_ff_send_ff_command( x, FFSFFC_SETACTUATORSON ) ); + } + + t_int hid_ff_stopall( t_hid *x ) + { + DEBUG(post("hid_ff_stopall");); + return( hid_ff_send_ff_command( x, FFSFFC_STOPALL ) ); + } + + t_int hid_ff_motors( t_hid *x, t_float value ) + { + if ( value > 0 ) + { + return ( hid_ff_setactuatorson( x ) ); + } + else + { + return ( hid_ff_setactuatorsoff( x ) ); + } + } + + + /* -------------------------------------------------------------------------- + * FF test functions + */ + + t_int hid_ff_fftest ( t_hid *x, t_float value) + { + DEBUG(post("hid_get_events");); + + return( 0 ); + } + /* ============================================================================== */ /* Pd [hid] FUNCTIONS */ *************** *** 472,476 ****
io_service_t hidDevice = NULL; ! FFDeviceObjectReference *pDeviceReference = NULL;
/* rebuild device list to make sure the list is current */ --- 630,634 ----
io_service_t hidDevice = NULL; ! FFDeviceObjectReference ffDeviceReference = NULL;
/* rebuild device list to make sure the list is current */ *************** *** 500,509 **** hid_build_element_list(x);
if ( FFIsForceFeedback(hidDevice) == FF_OK ) { ! post("device has Force Feedback support"); ! if ( FFCreateDevice(hidDevice,pDeviceReference) == FF_OK ) { ! post("created FF device"); } } --- 658,675 ---- hid_build_element_list(x);
+ hidDevice = AllocateHIDObjectFromRecDevice( pCurrentHIDDevice ); if ( FFIsForceFeedback(hidDevice) == FF_OK ) { ! post("\tdevice has Force Feedback support"); ! if ( FFCreateDevice(hidDevice,&ffDeviceReference) == FF_OK ) { ! x->x_has_ff = 1; ! x->x_ff_device = ffDeviceReference; ! } ! else ! { ! x->x_has_ff = 0; ! post("[hid]: FF device creation failed!"); ! return( -1 ); } } *************** *** 549,553 **** while ( pCurrentHIDDevice != NULL ) { ! hid_output_device_name( x, pCurrentHIDDevice->manufacturer, pCurrentHIDDevice->product ); pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); } --- 715,720 ---- while ( pCurrentHIDDevice != NULL ) { ! hid_output_device_name( x, pCurrentHIDDevice->manufacturer, ! pCurrentHIDDevice->product ); pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); } *************** *** 561,566 **** hid_print_device_list(x); ! if(x->x_device_open) hid_print_element_list(x); }
--- 728,736 ---- hid_print_device_list(x); ! if(x->x_device_open) ! { hid_print_element_list(x); + hid_ff_print( x ); + } }
Index: Makefile =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/Makefile,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Makefile 6 Jun 2005 22:39:50 -0000 1.9 --- Makefile 10 Jun 2005 20:17:42 -0000 1.10 *************** *** 22,26 **** .SUFFIXES: .pd_darwin
! all: input_arrays pd_darwin pd_darwin: hid.pd_darwin
--- 22,26 ---- .SUFFIXES: .pd_darwin
! all: input_arrays hid_utilities pd_darwin pd_darwin: hid.pd_darwin
*************** *** 32,38 ****
# generic optimization ! OPT_FLAGS = -O3 ! # G4 7450 optimization (gives errors) ! #OPT_FLAGS = -fast -mcpu=7450 -maltivec
CFLAGS = $(OPT_FLAGS) -Wall -W -Wno-shadow -Wstrict-prototypes -Wno-unused --- 32,40 ----
# generic optimization ! #OPT_FLAGS = -O3 -ffast-math ! # G4 optimization ! OPT_FLAGS = -O3 -mcpu=7400 -faltivec -ffast-math -fPIC ! # faster G4 7450 optimization (gives errors) ! #OPT_FLAGS = -ffast -mcpu=7450 -faltivec -ffast-math -fPIC
CFLAGS = $(OPT_FLAGS) -Wall -W -Wno-shadow -Wstrict-prototypes -Wno-unused *************** *** 49,57 **** ld $(LDFLAGS) -o $*.pd_linux *.o -lc -lm strip --strip-unneeded $*.pd_linux - # rm $*.o
input_arrays: ! ./make-arrays-from-input.h.pl
clean: ; rm -f *.pd_* *.o *~ input_arrays.? doc/ev*-list.pd --- 51,61 ---- ld $(LDFLAGS) -o $*.pd_linux *.o -lc -lm strip --strip-unneeded $*.pd_linux
input_arrays: ! test -f input_arrays.h || ./make-arrays-from-input.h.pl
+ hid_utilities: + test -f ./HID\ Utilities\ Source/build/libHIDUtilities.a || \ + ( cd ./HID\ Utilities\ Source && pbxbuild )
clean: ; rm -f *.pd_* *.o *~ input_arrays.? doc/ev*-list.pd
Index: hid.h =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** hid.h 6 Jun 2005 22:39:50 -0000 1.15 --- hid.h 10 Jun 2005 20:17:42 -0000 1.16 *************** *** 27,30 **** --- 27,32 ---- t_int x_fd; t_int x_device_number; + t_int x_has_ff; + void *x_ff_device; t_clock *x_clock; t_int x_delay; *************** *** 59,71 ****
/* support functions */ ! void hid_output_event(t_hid *x, char *type, char *code, t_float value);
- /* generic, cross-platform functions */ - t_int hid_open_device(t_hid *x, t_int device_number); - t_int hid_close_device(t_hid *x); - t_int hid_build_device_list(t_hid* x); - t_int hid_get_events(t_hid *x) ; - void hid_print(t_hid* x); - void hid_platform_specific_free(t_hid *x);
#endif /* #ifndef _HID_H */ --- 61,93 ----
/* support functions */ ! void hid_output_event( t_hid *x, char *type, char *code, t_float value ); ! ! /* generic, cross-platform functions implemented in a separate file for each ! * platform ! */ ! t_int hid_open_device( t_hid *x, t_int device_number ); ! t_int hid_close_device( t_hid *x ); ! t_int hid_build_device_list( t_hid* x ); ! t_int hid_get_events( t_hid *x ) ; ! void hid_print( t_hid* x ); ! void hid_platform_specific_free( t_hid *x ); ! ! /* cross-platform force feedback functions */ ! t_int hid_ff_autocenter( t_hid *x, t_float value ); ! t_int hid_ff_gain( t_hid *x, t_float value ); ! t_int hid_ff_motors( t_hid *x, t_float value ); ! t_int hid_ff_continue( t_hid *x ); ! t_int hid_ff_pause( t_hid *x ); ! t_int hid_ff_reset( t_hid *x ); ! t_int hid_ff_stopall( t_hid *x ); ! // these are just for testing... ! t_int hid_ff_fftest ( t_hid *x, t_float value); ! ! #include "HID_Utilities_External.h" ! void hid_ff_print( t_hid *x ); ! ! !
#endif /* #ifndef _HID_H */
Index: hid.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** hid.c 6 Jun 2005 22:39:50 -0000 1.19 --- hid.c 10 Jun 2005 20:17:42 -0000 1.20 *************** *** 239,242 **** --- 239,243 ----
/* init vars */ + x->x_has_ff = 0; x->x_device_open = 0; x->x_started = 0; *************** *** 286,289 **** --- 287,302 ---- class_addmethod(hid_class,(t_method) hid_stop,gensym("stop"),0); class_addmethod(hid_class,(t_method) hid_stop,gensym("nopoll"),0); + /* force feedback messages */ + class_addmethod(hid_class,(t_method) hid_ff_autocenter, + gensym("ff_autocenter"),A_DEFFLOAT,0); + class_addmethod(hid_class,(t_method) hid_ff_gain,gensym("ff_gain"),A_DEFFLOAT,0); + class_addmethod(hid_class,(t_method) hid_ff_motors,gensym("ff_motors"),A_DEFFLOAT,0); + class_addmethod(hid_class,(t_method) hid_ff_continue,gensym("ff_continue"),0); + class_addmethod(hid_class,(t_method) hid_ff_pause,gensym("ff_pause"),0); + class_addmethod(hid_class,(t_method) hid_ff_reset,gensym("ff_reset"),0); + class_addmethod(hid_class,(t_method) hid_ff_stopall,gensym("ff_stopall"),0); + /* ff tests */ + class_addmethod(hid_class,(t_method) hid_ff_fftest,gensym("fftest"),A_DEFFLOAT,0); + class_addmethod(hid_class,(t_method) hid_ff_print,gensym("ff_print"),0); }