Update of /cvsroot/pure-data/externals/hcs/hid In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28430/hcs/hid
Modified Files: Makefile hid.c hid.h hid_darwin.c hid_linux.c Log Message: everything is building, the element array is being properly populated, I just need to fix the data output to use the new element array
Index: Makefile =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/Makefile,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Makefile 2 Jun 2006 20:06:50 -0000 1.16 --- Makefile 22 Aug 2006 04:13:14 -0000 1.17 *************** *** 16,19 **** --- 16,25 ---- # for emacs etags: + make etags_`uname -s` + + etags_Darwin: etags *.[ch] linux/input.h HID\ Utilities\ Source/*.[ch] \ /System/Library/Frameworks/IOKit.framework/Headers/hid*/*.[ch] + + etags_Linux: + etags *.[ch] /usr/include/*.h linux/input.h /usr/include/sys/*.h
Index: hid_darwin.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid_darwin.c,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** hid_darwin.c 15 Aug 2006 01:50:17 -0000 1.27 --- hid_darwin.c 22 Aug 2006 04:13:14 -0000 1.28 *************** *** 80,84 ****
/* conversion functions */ ! char *convertEventsFromDarwinToLinux(pRecElement element);
/*============================================================================== --- 80,84 ----
/* conversion functions */ ! static char *convertEventsFromDarwinToLinux(pRecElement element);
/*============================================================================== *************** *** 91,95 **** * [hid]/linux style events */ ! void convert_axis_to_symbols(pRecElement pCurrentHIDElement, t_hid_element *new_element, char *axis) { char buffer[MAXPDSTRING]; --- 91,95 ---- * [hid]/linux style events */ ! static void convert_axis_to_symbols(pRecElement pCurrentHIDElement, t_hid_element *new_element, char *axis) { char buffer[MAXPDSTRING]; *************** *** 109,113 ****
! void get_usage_symbols(pRecElement pCurrentHIDElement, t_hid_element *new_element) { // debug_print(LOG_DEBUG,"get_usage_symbols"); --- 109,113 ----
! static void get_usage_symbols(pRecElement pCurrentHIDElement, t_hid_element *new_element) { // debug_print(LOG_DEBUG,"get_usage_symbols"); *************** *** 300,304 **** /* ============================================================================== */
! short get_device_number_by_id(unsigned short vendor_id, unsigned short product_id) { debug_print(LOG_DEBUG,"get_device_number_from_usage"); --- 300,304 ---- /* ============================================================================== */
! static short get_device_number_by_id(unsigned short vendor_id, unsigned short product_id) { debug_print(LOG_DEBUG,"get_device_number_from_usage"); *************** *** 332,336 **** }
! short get_device_number_from_usage(short device_number, unsigned short usage_page, unsigned short usage) --- 332,336 ---- }
! static short get_device_number_from_usage(short device_number, unsigned short usage_page, unsigned short usage) *************** *** 385,389 ****
! void hid_build_element_list(t_hid *x) { char type_name[256]; --- 385,389 ----
! static void hid_build_element_list(t_hid *x) { char type_name[256]; *************** *** 459,463 **** }
! void hid_print_element_list(t_hid *x) { // debug_print(LOG_DEBUG,"hid_print_element_list"); --- 459,463 ---- }
! static void hid_print_element_list(t_hid *x) { // debug_print(LOG_DEBUG,"hid_print_element_list"); *************** *** 518,522 ****
! void hid_print_device_list(t_hid *x) { char device_type_buffer[256]; --- 518,522 ----
! static void hid_print_device_list(t_hid *x) { char device_type_buffer[256];
Index: hid.h =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid.h,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** hid.h 15 Aug 2006 01:50:17 -0000 1.27 --- hid.h 22 Aug 2006 04:13:14 -0000 1.28 *************** *** 5,8 **** --- 5,12 ---- #include <sys/syslog.h>
+ #ifdef __linux__ + #include <linux/types.h> + #endif /* __linux__ */ + #include <m_pd.h>
*************** *** 73,89 **** { #ifdef __linux__ ! //GNU/Linux store type and code to compare against #else ! void *os_pointer; // pRecElement on Mac OS X; #endif /* __linux__ */ ! t_symbol *type; // Linux "type"; HID "usagePage" ! t_symbol *name; // Linux "code"; HID "usage" ! 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 ! t_int max; // from device report ! t_float instance; // usage page/usage instance # ([absolute throttle 2 163( ! t_int value; // output the sum of events in a poll for relative axes ! t_int previous_value; //only output on change on abs and buttons } t_hid_element;
--- 77,95 ---- { #ifdef __linux__ ! /* GNU/Linux store type and code to compare against */ ! __u16 linux_type; ! __u16 linux_code; #else ! void *os_pointer; // pRecElement on Mac OS X; ... on Windows #endif /* __linux__ */ ! t_symbol *type; // Linux "type"; HID "usagePage" ! t_symbol *name; // Linux "code"; HID "usage" ! 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 ! t_int max; // from device report ! t_float instance; // usage page/usage instance # ([absolute throttle 2 163( ! t_int value; // output the sum of events in a poll for relative axes ! t_int previous_value; //only output on change on abs and buttons } t_hid_element;
Index: hid_linux.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid_linux.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** hid_linux.c 15 Aug 2006 01:50:17 -0000 1.19 --- hid_linux.c 22 Aug 2006 04:13:14 -0000 1.20 *************** *** 12,15 **** --- 12,16 ---- #include <sys/fcntl.h> #include <unistd.h> + #include <stdint.h>
#include "hid.h" *************** *** 18,21 **** --- 19,25 ---- //#define DEBUG(x) x
+ #define LINUX_BLOCK_DEVICE "/dev/input/event" + + /*------------------------------------------------------------------------------ * from evtest.c from the ff-utils package *************** *** 44,62 **** /* ------------------------------------------------------------------------------ */
- /* JMZ: i changed the convert functions (and the get-event function too!) to - * return t_symbol* instead of writing into a fixed-sized buffer (which was - * way too small and those made this object crash) in order to change as - * little lines as possible the callback functions to the hid-object still use - * (char*): so we convert a char[] into a symbol and then extract the (char*) - * out of it to make it a symbol again LATER: use t_symbol's all over, since - * it is very flexible (with respect to length) and sooner or later the - * strings are converted to t_symbol anyhow... - * - * Why? bug-fixing - */ - t_symbol* hid_convert_linux_buttons_to_numbers(__u16 linux_code) { ! char hid_code[10]; if(linux_code >= 0x100) { --- 48,54 ---- /* ------------------------------------------------------------------------------ */
t_symbol* hid_convert_linux_buttons_to_numbers(__u16 linux_code) { ! char hid_code[10]; if(linux_code >= 0x100) { *************** *** 75,79 **** else return 0; } ! return gensym(hid_code); }
--- 67,71 ---- else return 0; } ! return gensym(hid_code ? hid_code : "?"); }
*************** *** 92,138 **** static char key_names[227][20] = { ! "key_reserved", "key_esc", "key_1", "key_2", "key_3", "key_4", "key_5", "key_6", "key_7", ! "key_8", "key_9", "key_0", "key_minus", "key_equal", "key_backspace", "key_tab", ! "key_q", "key_w", "key_e", "key_r", "key_t", "key_y", "key_u", "key_i", "key_o", "key_p", ! "key_leftbrace", "key_rightbrace", "key_enter", "key_leftctrl", "key_a", ! "key_s", "key_d", "key_f", "key_g", "key_h", "key_j", "key_k", "key_l", "key_semicolon", ! "key_apostrophe", "key_grave", "key_leftshift", "key_backslash", "key_z", ! "key_x", "key_c", "key_v", "key_b", "key_n", "key_m", "key_comma", "key_dot", "key_slash", ! "key_rightshift", "key_kpasterisk", "key_leftalt", "key_space", "key_capslock", ! "key_f1", "key_f2", "key_f3", "key_f4", "key_f5", "key_f6", "key_f7", "key_f8", "key_f9", "key_f10", ! "key_numlock", "key_scrolllock", "key_kp7", "key_kp8", "key_kp9", "key_kpminus", ! "key_kp4", "key_kp5", "key_kp6", "key_kpplus", "key_kp1", "key_kp2", "key_kp3", "key_kp3", "key_kpdot", ! "key_103rd", "key_f13", "key_102nd", "key_f11", "key_f12", "key_f14", "key_f15", "key_f16", ! "key_f17", "key_f18", "key_f19", "key_f20", "key_kpenter", "key_rightctrl", "key_kpslash", ! "key_sysrq", "key_rightalt", "key_linefeed", "key_home", "key_up", "key_pageup", "key_left", ! "key_right", "key_end", "key_down", "key_pagedown", "key_insert", "key_delete", "key_macro", ! "key_mute", "key_volumedown", "key_volumeup", "key_power", "key_kpequal", "key_kpplusminus", ! "key_pause", "key_f21", "key_f22", "key_f23", "key_f24", "key_kpcomma", "key_leftmeta", ! "key_rightmeta", "key_compose", ! ! "key_stop", "key_again", "key_props", "key_undo", "key_front", "key_copy", "key_open", ! "key_paste", "key_find", "key_cut", "key_help", "key_menu", "key_calc", "key_setup", "key_sleep", "key_wakeup", ! "key_file", "key_sendfile", "key_deletefile", "key_xfer", "key_prog1", "key_prog2", "key_www", ! "key_msdos", "key_coffee", "key_direction", "key_cyclewindows", "key_mail", "key_bookmarks", ! "key_computer", "key_back", "key_forward", "key_colsecd", "key_ejectcd", "key_ejectclosecd", ! "key_nextsong", "key_playpause", "key_previoussong", "key_stopcd", "key_record", ! "key_rewind", "key_phone", "key_iso", "key_config", "key_homepage", "key_refresh", "key_exit", ! "key_move", "key_edit", "key_scrollup", "key_scrolldown", "key_kpleftparen", "key_kprightparen", ! ! "key_intl1", "key_intl2", "key_intl3", "key_intl4", "key_intl5", "key_intl6", "key_intl7", ! "key_intl8", "key_intl9", "key_lang1", "key_lang2", "key_lang3", "key_lang4", "key_lang5", ! "key_lang6", "key_lang7", "key_lang8", "key_lang9", "key_playcd", "key_pausecd", "key_prog3", ! "key_prog4", "key_suspend", "key_close", "key_play", "key_fastforward", "key_bassboost", ! "key_print", "key_hp", "key_camera", "key_sound", "key_question", "key_email", "key_chat", ! "key_search", "key_connect", "key_finance", "key_sport", "key_shop", "key_alterase", ! "key_cancel", "key_brightnessdown", "key_brightnessup", "key_media" }; ! return gensym(key_names[linux_code]); }
void hid_print_element_list(t_hid *x) { debug_print(LOG_DEBUG,"hid_print_element_list"); ! unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)]; // char event_type_string[256]; // char event_code_string[256]; --- 84,144 ---- static char key_names[227][20] = { ! "key_reserved", "key_esc", "key_1", "key_2", "key_3", "key_4", ! "key_5", "key_6", "key_7", "key_8", "key_9", "key_0", "key_minus", ! "key_equal", "key_backspace", "key_tab", "key_q", "key_w", ! "key_e", "key_r", "key_t", "key_y", "key_u", "key_i", "key_o", ! "key_p","key_leftbrace", "key_rightbrace", "key_enter", ! "key_leftctrl", "key_a","key_s", "key_d", "key_f", "key_g", ! "key_h", "key_j", "key_k", "key_l", "key_semicolon", ! "key_apostrophe", "key_grave", "key_leftshift", "key_backslash", ! "key_z","key_x", "key_c", "key_v", "key_b", "key_n", "key_m", ! "key_comma", "key_dot", "key_slash","key_rightshift", ! "key_kpasterisk", "key_leftalt", "key_space", "key_capslock", ! "key_f1", "key_f2", "key_f3", "key_f4", "key_f5", "key_f6", ! "key_f7", "key_f8", "key_f9", "key_f10","key_numlock", ! "key_scrolllock", "key_kp7", "key_kp8", "key_kp9", "key_kpminus", ! "key_kp4", "key_kp5", "key_kp6", "key_kpplus", "key_kp1", "key_kp2", ! "key_kp3", "key_kp3", "key_kpdot","key_103rd", "key_f13", ! "key_102nd", "key_f11", "key_f12", "key_f14", "key_f15", "key_f16", ! "key_f17", "key_f18", "key_f19", "key_f20", "key_kpenter", ! "key_rightctrl", "key_kpslash","key_sysrq", "key_rightalt", ! "key_linefeed", "key_home", "key_up", "key_pageup", "key_left", ! "key_right", "key_end", "key_down", "key_pagedown", "key_insert", ! "key_delete", "key_macro","key_mute", "key_volumedown", ! "key_volumeup", "key_power", "key_kpequal", "key_kpplusminus", ! "key_pause", "key_f21", "key_f22", "key_f23", "key_f24", ! "key_kpcomma", "key_leftmeta","key_rightmeta", "key_compose", ! "key_stop", "key_again", "key_props", "key_undo", "key_front", ! "key_copy", "key_open","key_paste", "key_find","key_cut","key_help", ! "key_menu", "key_calc", "key_setup", "key_sleep", "key_wakeup", ! "key_file", "key_sendfile", "key_deletefile","key_xfer","key_prog1", ! "key_prog2", "key_www","key_msdos", "key_coffee", "key_direction", ! "key_cyclewindows", "key_mail", "key_bookmarks","key_computer", ! "key_back", "key_forward", "key_colsecd", "key_ejectcd", ! "key_ejectclosecd","key_nextsong","key_playpause","key_previoussong", ! "key_stopcd", "key_record","key_rewind", "key_phone", "key_iso", ! "key_config", "key_homepage", "key_refresh", "key_exit","key_move", ! "key_edit", "key_scrollup", "key_scrolldown", "key_kpleftparen", ! "key_kprightparen","key_intl1", "key_intl2", "key_intl3","key_intl4", ! "key_intl5", "key_intl6", "key_intl7","key_intl8", "key_intl9", ! "key_lang1", "key_lang2", "key_lang3", "key_lang4", "key_lang5", ! "key_lang6", "key_lang7", "key_lang8", "key_lang9", "key_playcd", ! "key_pausecd", "key_prog3","key_prog4", "key_suspend", "key_close", ! "key_play", "key_fastforward", "key_bassboost","key_print", "key_hp", ! "key_camera", "key_sound", "key_question", "key_email", "key_chat", ! "key_search", "key_connect", "key_finance", "key_sport", "key_shop", ! "key_alterase","key_cancel", "key_brightnessdown", "key_brightnessup", ! "key_media" }; ! return gensym(key_names[linux_code]); // TODO: this should just return the char * }
+ + + void hid_print_element_list(t_hid *x) { debug_print(LOG_DEBUG,"hid_print_element_list"); ! unsigned long element_bitmask[EV_MAX][NBITS(KEY_MAX)]; // char event_type_string[256]; // char event_code_string[256]; *************** *** 140,148 **** t_int i, j; /* counts for various event types */ ! t_int syn_count,key_count,rel_count,abs_count,msc_count,led_count,snd_count,rep_count,ff_count,pwr_count,ff_status_count;
! /* get bitmask representing supported events (axes, keys, etc.) */ ! memset(bitmask, 0, sizeof(bitmask)); ! ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), bitmask[0]); post("\nSupported events:");
--- 146,155 ---- t_int i, j; /* counts for various event types */ ! t_int syn_count,key_count,rel_count,abs_count,msc_count,led_count, ! snd_count,rep_count,ff_count,pwr_count,ff_status_count;
! /* get bitmask representing supported element (axes, keys, etc.) */ ! memset(element_bitmask, 0, sizeof(element_bitmask)); ! ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), element_bitmask[0]); post("\nSupported events:");
*************** *** 154,160 **** * i = i j = j */ ! for (i = 1; i < EV_MAX; i++) { ! if (test_bit(i, bitmask[0])) { /* make pretty names for event types */ --- 161,167 ---- * i = i j = j */ ! for(i = 1; i < EV_MAX; i++) { ! if(test_bit(i, element_bitmask[0])) { /* make pretty names for event types */ *************** *** 176,180 **** /* get bitmask representing supported button types */ ! ioctl(x->x_fd, EVIOCGBIT(i, KEY_MAX), bitmask[i]); post(""); --- 183,187 ---- /* get bitmask representing supported button types */ ! ioctl(x->x_fd, EVIOCGBIT(i, KEY_MAX), element_bitmask[i]); post(""); *************** *** 186,204 **** * i = i j = j */ ! for (j = 0; j < KEY_MAX; j++) { ! if (test_bit(j, bitmask[i])) { ! if ((i == EV_KEY) && (j >= BTN_MISC) && (j < KEY_OK) ) { ! t_symbol*hid_codesym=hid_convert_linux_buttons_to_numbers(j); ! if(hid_codesym){ ! post(" %s\t%s\t%s", ! ev[i] ? ev[i] : "?", ! hid_codesym->s_name, ! event_names[i] ? (event_names[i][j] ? event_names[i][j] : "?") : "?"); } } ! else if (i != EV_SYN) { post(" %s\t%s\t%s", --- 193,213 ---- * i = i j = j */ ! for(j = 0; j < KEY_MAX; j++) { ! if(test_bit(j, element_bitmask[i])) { ! if((i == EV_KEY) && (j >= BTN_MISC) && (j < KEY_OK) ) { ! t_symbol * hid_codesym = hid_convert_linux_buttons_to_numbers(j); ! if(hid_codesym) ! { ! post(" %s\t%s\t%s (%s)", ! ev[i] ? ev[i] : "?", ! hid_codesym->s_name, ! event_type_name, ! event_names[i] ? (event_names[i][j] ? event_names[i][j] : "?") : "?"); } } ! else if(i != EV_SYN) { post(" %s\t%s\t%s", *************** *** 237,251 ****
post("\nDetected:"); ! // if (syn_count > 0) post (" %d Synchronization types",syn_count); ! if (key_count > 0) post (" %d Key/Button types",key_count); ! if (rel_count > 0) post (" %d Relative Axis types",rel_count); ! if (abs_count > 0) post (" %d Absolute Axis types",abs_count); ! if (msc_count > 0) post (" %d Misc types",msc_count); ! if (led_count > 0) post (" %d LED types",led_count); ! if (snd_count > 0) post (" %d System Sound types",snd_count); ! if (rep_count > 0) post (" %d Key Repeat types",rep_count); ! if (ff_count > 0) post (" %d Force Feedback types",ff_count); ! if (pwr_count > 0) post (" %d Power types",pwr_count); ! if (ff_status_count > 0) post (" %d Force Feedback types",ff_status_count); }
--- 246,260 ----
post("\nDetected:"); ! // if(syn_count > 0) post (" %d Synchronization types",syn_count); ! if(key_count > 0) post (" %d Key/Button types",key_count); ! if(rel_count > 0) post (" %d Relative Axis types",rel_count); ! if(abs_count > 0) post (" %d Absolute Axis types",abs_count); ! if(msc_count > 0) post (" %d Misc types",msc_count); ! if(led_count > 0) post (" %d LED types",led_count); ! if(snd_count > 0) post (" %d System Sound types",snd_count); ! if(rep_count > 0) post (" %d Key Repeat types",rep_count); ! if(ff_count > 0) post (" %d Force Feedback types",ff_count); ! if(pwr_count > 0) post (" %d Power types",pwr_count); ! if(ff_status_count > 0) post (" %d Force Feedback types",ff_status_count); }
*************** *** 259,271 ****
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 ) { fd = -1; --- 268,280 ----
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 ) { fd = -1; *************** *** 285,349 ****
/* ------------------------------------------------------------------------------ */ - /* FORCE FEEDBACK FUNCTIONS */ - /* ------------------------------------------------------------------------------ */ - - /* cross-platform force feedback functions */ - t_int hid_ff_autocenter( t_hid *x, t_float value ) - { - return ( 0 ); - } - - - t_int hid_ff_gain( t_hid *x, t_float value ) - { - return ( 0 ); - } - - - t_int hid_ff_motors( t_hid *x, t_float value ) - { - return ( 0 ); - } - - - t_int hid_ff_continue( t_hid *x ) - { - return ( 0 ); - } - - - t_int hid_ff_pause( t_hid *x ) - { - return ( 0 ); - } - - - t_int hid_ff_reset( t_hid *x ) - { - return ( 0 ); - } - - - t_int hid_ff_stopall( t_hid *x ) - { - return ( 0 ); - } - - - - // these are just for testing... - t_int hid_ff_fftest ( t_hid *x, t_float value) - { - return ( 0 ); - } - - - void hid_ff_print( t_hid *x ) - { - } - - - - /* ------------------------------------------------------------------------------ */ /* Pd [hid] FUNCTIONS */ /* ------------------------------------------------------------------------------ */ --- 294,297 ---- *************** *** 363,367 **** struct input_event hid_input_event;
! if (x->x_fd < 0) return;
while( read (x->x_fd, &(hid_input_event), sizeof(struct input_event)) > -1 ) --- 311,315 ---- struct input_event hid_input_event;
! if(x->x_fd < 0) return;
while( read (x->x_fd, &(hid_input_event), sizeof(struct input_event)) > -1 ) *************** *** 383,399 **** else if( event_names[hid_input_event.type][hid_input_event.code] != NULL ) { ! hid_code=gensym(event_names[hid_input_event.type][hid_input_event.code]); } else { ! hid_code=gensym("unknown"); } if( hid_code && hid_input_event.type != EV_SYN ) hid_output_event(x, gensym(ev[hid_input_event.type]), hid_code, ! (t_float)hid_input_event.value); DEBUG(++event_counter;); } DEBUG( ! //if (event_counter > 0) //post("output %d events",event_counter); ); --- 331,348 ---- else if( event_names[hid_input_event.type][hid_input_event.code] != NULL ) { ! hid_code = gensym(event_names[hid_input_event.type][hid_input_event.code]); } else { ! hid_code = gensym("unknown"); } + /* TODO: needs porting if( hid_code && hid_input_event.type != EV_SYN ) hid_output_event(x, gensym(ev[hid_input_event.type]), hid_code, ! (t_float)hid_input_event.value);*/ DEBUG(++event_counter;); } DEBUG( ! //if(event_counter > 0) //post("output %d events",event_counter); ); *************** *** 410,419 ****
! t_int hid_open_device(t_hid *x, t_int device_number) { debug_print(LOG_DEBUG,"hid_open_device");
char device_name[256] = "Unknown"; ! char dev_handle_name[20] = "/dev/input/event0"; struct input_event hid_input_event;
--- 359,368 ----
! t_int hid_open_device(t_hid *x, short device_number) { debug_print(LOG_DEBUG,"hid_open_device");
char device_name[256] = "Unknown"; ! char block_device[20] = "/dev/input/event0"; struct input_event hid_input_event;
*************** *** 421,434 ****
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; --- 370,383 ----
x->x_device_number = device_number; ! sprintf(block_device,"/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; *************** *** 444,448 **** 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); --- 393,399 ---- ioctl(x->x_fd, EVIOCGNAME(sizeof(device_name)), device_name); post ("[hid] opened device %d (%s): %s", ! x->x_device_number,block_device,device_name); ! ! hid_build_element_list(x);
return (0); *************** *** 455,459 **** { debug_print(LOG_DEBUG,"hid_close_device"); ! if (x->x_fd <0) return 0; else --- 406,410 ---- { debug_print(LOG_DEBUG,"hid_close_device"); ! if(x->x_fd <0) return 0; else *************** *** 461,468 **** }
void hid_build_device_list(void) { - debug_print(LOG_DEBUG,"hid_build_device_list"); - /* the device list should be refreshed here */ /* * since in GNU/Linux the device list is the input event devices --- 412,418 ---- }
+ void hid_build_device_list(void) { /* * since in GNU/Linux the device list is the input event devices *************** *** 471,476 **** --- 421,550 ---- * the current t_float, then this will probably need to be changed. */ + int fd; + unsigned int i; + unsigned int last_active_device = 0; + char device_name[256] = "Unknown"; + char block_device[20] = "/dev/input/event0"; + struct input_event x_input_event; + + debug_print(LOG_DEBUG,"hid_build_device_list"); + + debug_print(LOG_WARNING,"[hid] Building device list..."); + + for(i=0; i<MAX_DEVICES; ++i) + { + sprintf(&block_device,"%s%d",LINUX_BLOCK_DEVICE,i); + /* open the device read-only, non-exclusive */ + fd = open (&block_device, O_RDONLY | O_NONBLOCK); + /* test if device open */ + if(fd < 0 ) { + /* 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 */ + ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name); + post("Found '%s' on '%s'",device_name, &block_device); + + close (fd); + } + last_active_device = i; + + } + device_count = last_active_device ; // set the global variable + debug_print(LOG_WARNING,"[hid] completed device list."); + } + + + + + + static void hid_build_element_list(t_hid *x) + { + unsigned long element_bitmask[EV_MAX][NBITS(KEY_MAX)]; + uint8_t abs_bitmask[ABS_MAX/8 + 1]; + struct input_absinfo abs_features; + char type_name[256]; + char code_name[256]; + t_hid_element *new_element = NULL; + t_int i, j; + + element_count[x->x_device_number] = 0; + if( x->x_fd ) + { + new_element = getbytes(sizeof(t_hid_element)); + /* get bitmask representing supported elements (axes, keys, etc.) */ + memset(element_bitmask, 0, sizeof(element_bitmask)); + if( ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), element_bitmask[0]) < 0 ) + perror("[hid] error: evdev ioctl: element_bitmask"); + memset(abs_bitmask, 0, sizeof(abs_bitmask)); + if( ioctl(x->x_fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) < 0 ) + perror("[hid] error: evdev ioctl: abs_bitmask"); + for( i = 1; i < EV_MAX; i++ ) + { + if(test_bit(i, element_bitmask[0])) + { + new_element->linux_type = i; + new_element->type = gensym(ev[i] ? ev[i] : "?"); + /* get bitmask representing supported button types */ + ioctl(x->x_fd, EVIOCGBIT(i, KEY_MAX), element_bitmask[i]); + /* cycle through all possible event codes (axes, keys, etc.) + * testing to see which are supported. + * i = i j = j + */ + for(j = 0; j < KEY_MAX; j++) + { + if(test_bit(j, abs_bitmask)) + { + /* this means that the bit is set in the axes list */ + if(ioctl(x->x_fd, EVIOCGABS(j), &abs_features)) + perror("evdev EVIOCGABS ioctl"); + new_element->min = abs_features.minimum; + new_element->max = abs_features.maximum; + } + else + { + new_element->min = 0; + new_element->max = 0; + } + if(test_bit(j, element_bitmask[i])) + { + new_element->linux_code = j; + if((i == EV_KEY) && (j >= BTN_MISC) && (j < KEY_OK) ) + { + new_element->name = hid_convert_linux_buttons_to_numbers(j); + } + else + { + new_element->name = gensym(event_names[i][j] ? event_names[i][j] : "?"); + } + if( i == EV_REL ) + 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]; + } + } + } + } + } }
+ void hid_platform_specific_free(t_hid *x) { *************** *** 505,509 ****
! t_int get_device_number_by_id(unsigned short vendor_id, unsigned short product_id) {
--- 579,583 ----
! short get_device_number_by_id(unsigned short vendor_id, unsigned short product_id) {
*************** *** 511,515 **** }
! t_int get_device_number_from_usage(t_int device_number, unsigned short usage_page, unsigned short usage) --- 585,589 ---- }
! short get_device_number_from_usage(short device_number, unsigned short usage_page, unsigned short usage) *************** *** 521,524 **** --- 595,658 ----
+ /* ------------------------------------------------------------------------------ */ + /* FORCE FEEDBACK FUNCTIONS */ + /* ------------------------------------------------------------------------------ */ + + /* cross-platform force feedback functions */ + t_int hid_ff_autocenter( t_hid *x, t_float value ) + { + return ( 0 ); + } + + + t_int hid_ff_gain( t_hid *x, t_float value ) + { + return ( 0 ); + } + + + t_int hid_ff_motors( t_hid *x, t_float value ) + { + return ( 0 ); + } + + + t_int hid_ff_continue( t_hid *x ) + { + return ( 0 ); + } + + + t_int hid_ff_pause( t_hid *x ) + { + return ( 0 ); + } + + + t_int hid_ff_reset( t_hid *x ) + { + return ( 0 ); + } + + + t_int hid_ff_stopall( t_hid *x ) + { + return ( 0 ); + } + + + + // these are just for testing... + t_int hid_ff_fftest ( t_hid *x, t_float value) + { + return ( 0 ); + } + + + void hid_ff_print( t_hid *x ) + { + } + + #endif /* #ifdef __linux__ */
Index: hid.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** hid.c 15 Aug 2006 01:50:17 -0000 1.28 --- hid.c 22 Aug 2006 04:13:14 -0000 1.29 *************** *** 1,8 **** /* --------------------------------------------------------------------------*/ /* */ ! /* MacOS X object to use HIDs (Human Interface Devices) */ /* Written by Hans-Christoph Steiner hans@at.or.at */ /* */ ! /* Copyright (c) 2004 Hans-Christoph Steiner */ /* */ /* This program is free software; you can redistribute it and/or */ --- 1,8 ---- /* --------------------------------------------------------------------------*/ /* */ ! /* interface to native HID (Human Interface Devices) API */ /* Written by Hans-Christoph Steiner hans@at.or.at */ /* */ ! /* Copyright (c) 2004-2006 Hans-Christoph Steiner */ /* */ /* This program is free software; you can redistribute it and/or */