Update of /cvsroot/pure-data/externals/hcs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11996
Modified Files: Makefile linuxevent.c linuxhid.h linuxjoystick.c linuxmouse.c Log Message: cleaned up includes
Index: linuxhid.h =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/linuxhid.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** linuxhid.h 23 Aug 2004 03:48:57 -0000 1.8 --- linuxhid.h 22 Oct 2004 02:34:32 -0000 1.9 *************** *** 1,9 **** - #include <m_pd.h> - - #ifdef PD_MAJOR_VERSION - #include "s_stuff.h" - #else - #include "m_imp.h" - #endif
#ifdef __gnu_linux__ --- 1,2 ----
Index: linuxevent.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/linuxevent.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** linuxevent.c 30 May 2004 02:05:15 -0000 1.8 --- linuxevent.c 22 Oct 2004 02:34:32 -0000 1.9 *************** *** 1,280 **** ! #include "linuxhid.h" ! ! #define LINUXEVENT_DEVICE "/dev/input/event0" ! ! static char *version = "$Revision$"; ! ! /*------------------------------------------------------------------------------ ! * CLASS DEF ! */ ! static t_class *linuxevent_class; ! ! typedef struct _linuxevent { ! t_object x_obj; ! t_int x_fd; ! t_symbol *x_devname; ! t_clock *x_clock; ! int x_read_ok; ! int x_started; ! int x_delay; ! #ifdef __gnu_linux__ ! struct input_event x_input_event; ! #endif ! t_outlet *x_input_event_time_outlet; ! t_outlet *x_input_event_type_outlet; ! t_outlet *x_input_event_code_outlet; ! t_outlet *x_input_event_value_outlet; ! }t_linuxevent; ! ! /*------------------------------------------------------------------------------ ! * IMPLEMENTATION ! */ ! ! void linuxevent_stop(t_linuxevent* x) { ! DEBUG(post("linuxevent_stop");); ! ! if (x->x_fd >= 0 && x->x_started) { ! clock_unset(x->x_clock); ! post("linuxevent: polling stopped"); ! x->x_started = 0; ! } ! } ! ! static int linuxevent_close(t_linuxevent *x) { ! DEBUG(post("linuxevent_close");); ! ! /* just to be safe, stop it first */ ! linuxevent_stop(x); ! ! if (x->x_fd <0) return 0; ! close (x->x_fd); ! post ("[linuxevent] closed %s",x->x_devname->s_name); ! ! return 1; ! } ! ! static int linuxevent_open(t_linuxevent *x, t_symbol *s) { ! int eventType, eventCode, buttons, rel_axes, abs_axes, ff; ! #ifdef __gnu_linux__ ! unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)]; ! #endif ! char devicename[256] = "Unknown"; ! DEBUG(post("linuxevent_open");) ! ! linuxevent_close(x); ! ! /* set obj device name to parameter ! * otherwise set to default ! */ ! if (s != &s_) ! x->x_devname = s; ! ! #ifdef __gnu_linux__ ! /* open device */ ! if (x->x_devname) { ! /* open the device read-only, non-exclusive */ ! x->x_fd = open (x->x_devname->s_name, O_RDONLY | O_NONBLOCK); ! /* test if device open */ ! if (x->x_fd < 0 ) { ! post("[linuxevent] open %s failed",x->x_devname->s_name); ! x->x_fd = -1; ! return 0; ! } ! } else return 1; ! ! /* read input_events from the LINUXEVENT_DEVICE stream ! * It seems that is just there to flush the event input buffer? ! */ ! while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1); ! ! /* get name of device */ ! ioctl(x->x_fd, EVIOCGNAME(sizeof(devicename)), devicename); ! post ("Configuring %s on %s",devicename,x->x_devname->s_name); ! ! /* get bitmask representing supported events (axes, buttons, etc.) */ ! memset(bitmask, 0, sizeof(bitmask)); ! ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), bitmask[0]); ! post("\nSupported events:"); ! ! rel_axes = 0; ! abs_axes = 0; ! buttons = 0; ! ff = 0; ! ! /* cycle through all possible event types */ ! for (eventType = 0; eventType < EV_MAX; eventType++) { ! if (test_bit(eventType, bitmask[0])) { ! post(" %s (type %d) ", events[eventType] ? events[eventType] : "?", eventType); ! // post("Event type %d",eventType); ! ! /* get bitmask representing supported button types */ ! ioctl(x->x_fd, EVIOCGBIT(eventType, KEY_MAX), bitmask[eventType]); ! ! /* cycle through all possible event codes (axes, keys, etc.) ! * testing to see which are supported ! */ ! for (eventCode = 0; eventCode < KEY_MAX; eventCode++) ! if (test_bit(eventCode, bitmask[eventType])) { ! post(" Event code %d (%s)", eventCode, names[eventType] ? (names[eventType][eventCode] ? names[eventType][eventCode] : "?") : "?"); ! ! switch(eventType) { ! #ifdef EV_RST ! case EV_RST: ! break; ! #endif ! case EV_KEY: ! buttons++; ! break; ! case EV_REL: ! rel_axes++; ! break; ! case EV_ABS: ! abs_axes++; ! break; ! case EV_MSC: ! break; ! case EV_LED: ! break; ! case EV_SND: ! break; ! case EV_REP: ! break; ! case EV_FF: ! ff++; ! break; ! } ! } ! } ! } ! ! post ("\nUsing %d relative axes, %d absolute axes, and %d buttons.", rel_axes, abs_axes, buttons); ! if (ff > 0) post ("Detected %d force feedback types",ff); ! post ("\nWARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING"); ! post ("This object is under development! The interface could change at anytime!"); ! post ("As I write cross-platform versions, the interface might have to change."); ! post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING\n"); ! #endif ! ! return 1; ! } ! ! static int linuxevent_read(t_linuxevent *x,int fd) { ! if (x->x_fd < 0) return 0; ! ! #ifdef __gnu_linux__ ! while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1) { ! outlet_float (x->x_input_event_value_outlet, (int)x->x_input_event.value); ! outlet_float (x->x_input_event_code_outlet, x->x_input_event.code); ! outlet_float (x->x_input_event_type_outlet, x->x_input_event.type); ! /* input_event.time is a timeval struct from <sys/time.h> */ ! /* outlet_float (x->x_input_event_time_outlet, x->x_input_event.time); */ ! } ! #endif ! ! if (x->x_started) { ! clock_delay(x->x_clock, x->x_delay); ! } ! ! return 1; ! } ! ! /* Actions */ ! static void linuxevent_float(t_linuxevent* x) { ! DEBUG(post("linuxevent_float");) ! ! } ! ! void linuxevent_delay(t_linuxevent* x, t_float f) { ! DEBUG(post("linuxevent_DELAY %f",f);) ! ! /* if the user sets the delay less than zero, reset to default */ ! if ( f > 0 ) { ! x->x_delay = (int)f; ! } else { ! x->x_delay = DEFAULT_DELAY; ! } ! } ! ! void linuxevent_start(t_linuxevent* x) { ! DEBUG(post("linuxevent_start");); ! ! if (x->x_fd >= 0 && !x->x_started) { ! clock_delay(x->x_clock, DEFAULT_DELAY); ! post("linuxevent: polling started"); ! x->x_started = 1; ! } else { ! post("You need to set a input device (i.e /dev/input/event0)"); ! } ! } ! ! /* setup functions */ ! static void linuxevent_free(t_linuxevent* x) { ! DEBUG(post("linuxevent_free");) ! ! if (x->x_fd < 0) return; ! ! linuxevent_stop(x); ! clock_free(x->x_clock); ! close (x->x_fd); ! } ! ! static void *linuxevent_new(t_symbol *s) { ! int i; ! t_linuxevent *x = (t_linuxevent *)pd_new(linuxevent_class); ! ! DEBUG(post("linuxevent_new");) ! ! post("[linuxevent] %s, written by Hans-Christoph Steiner hans@eds.org",version); ! #ifndef __linux__ ! post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); ! post(" This is a dummy, since this object only works with a Linux kernel!"); ! post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); ! #endif ! ! /* init vars */ ! x->x_fd = -1; ! x->x_read_ok = 1; ! x->x_started = 0; ! x->x_delay = DEFAULT_DELAY; ! x->x_devname = gensym(LINUXEVENT_DEVICE); ! ! x->x_clock = clock_new(x, (t_method)linuxevent_read); ! ! /* create outlets for each axis */ ! x->x_input_event_time_outlet = outlet_new(&x->x_obj, &s_float); ! x->x_input_event_type_outlet = outlet_new(&x->x_obj, &s_float); ! x->x_input_event_code_outlet = outlet_new(&x->x_obj, &s_float); ! x->x_input_event_value_outlet = outlet_new(&x->x_obj, &s_float); ! ! /* set to the value from the object argument, if that exists */ ! if (s != &s_) ! x->x_devname = s; ! ! /* Open the device and save settings */ ! ! if (!linuxevent_open(x,s)) return x; ! ! return (x); ! } ! ! void linuxevent_setup(void) { ! DEBUG(post("linuxevent_setup");) ! linuxevent_class = class_new(gensym("linuxevent"), ! (t_newmethod)linuxevent_new, ! (t_method)linuxevent_free, ! sizeof(t_linuxevent),0,A_DEFSYM,0); ! ! /* add inlet datatype methods */ ! class_addfloat(linuxevent_class,(t_method) linuxevent_float); ! class_addbang(linuxevent_class,(t_method) linuxevent_read); ! ! /* add inlet message methods */ ! class_addmethod(linuxevent_class,(t_method) linuxevent_delay,gensym("delay"),A_DEFFLOAT,0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_open,gensym("open"),A_DEFSYM,0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_close,gensym("close"),0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_start,gensym("start"),0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_start,gensym("poll"),0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_stop,gensym("stop"),0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_stop,gensym("nopoll"),0); ! } ! --- 1,285 ---- ! #include <m_pd.h> ! ! #include "linuxhid.h" ! ! #define LINUXEVENT_DEVICE "/dev/input/event0" ! ! static char *version = "$Revision$"; ! ! /*------------------------------------------------------------------------------ ! * CLASS DEF ! */ ! static t_class *linuxevent_class; ! ! typedef struct _linuxevent { ! t_object x_obj; ! t_int x_fd; ! t_symbol *x_devname; ! t_clock *x_clock; ! int x_read_ok; ! int x_started; ! int x_delay; ! #ifdef __gnu_linux__ ! struct input_event x_input_event; ! #endif ! t_outlet *x_input_event_time_outlet; ! t_outlet *x_input_event_type_outlet; ! t_outlet *x_input_event_code_outlet; ! t_outlet *x_input_event_value_outlet; ! }t_linuxevent; ! ! /*------------------------------------------------------------------------------ ! * IMPLEMENTATION ! */ ! ! void linuxevent_stop(t_linuxevent* x) { ! DEBUG(post("linuxevent_stop");); ! ! if (x->x_fd >= 0 && x->x_started) { ! clock_unset(x->x_clock); ! post("linuxevent: polling stopped"); ! x->x_started = 0; ! } ! } ! ! static int linuxevent_close(t_linuxevent *x) { ! DEBUG(post("linuxevent_close");); ! ! /* just to be safe, stop it first */ ! linuxevent_stop(x); ! ! if (x->x_fd <0) return 0; ! close (x->x_fd); ! post ("[linuxevent] closed %s",x->x_devname->s_name); ! ! return 1; ! } ! ! static int linuxevent_open(t_linuxevent *x, t_symbol *s) { ! int eventType, eventCode, buttons, rel_axes, abs_axes, ff; ! #ifdef __gnu_linux__ ! unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)]; ! #endif ! char devicename[256] = "Unknown"; ! DEBUG(post("linuxevent_open");) ! ! linuxevent_close(x); ! ! /* set obj device name to parameter ! * otherwise set to default ! */ ! if (s != &s_) ! x->x_devname = s; ! ! #ifdef __gnu_linux__ ! /* open device */ ! if (x->x_devname) { ! /* open the device read-only, non-exclusive */ ! x->x_fd = open (x->x_devname->s_name, O_RDONLY | O_NONBLOCK); ! /* test if device open */ ! if (x->x_fd < 0 ) { ! post("[linuxevent] open %s failed",x->x_devname->s_name); ! x->x_fd = -1; ! return 0; ! } ! } else return 1; ! ! /* read input_events from the LINUXEVENT_DEVICE stream ! * It seems that is just there to flush the event input buffer? ! */ ! while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1); ! ! /* get name of device */ ! ioctl(x->x_fd, EVIOCGNAME(sizeof(devicename)), devicename); ! post ("Configuring %s on %s",devicename,x->x_devname->s_name); ! ! /* get bitmask representing supported events (axes, buttons, etc.) */ ! memset(bitmask, 0, sizeof(bitmask)); ! ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), bitmask[0]); ! post("\nSupported events:"); ! ! rel_axes = 0; ! abs_axes = 0; ! buttons = 0; ! ff = 0; ! ! /* cycle through all possible event types */ ! for (eventType = 0; eventType < EV_MAX; eventType++) { ! if (test_bit(eventType, bitmask[0])) { ! post(" %s (type %d) ", events[eventType] ? events[eventType] : "?", eventType); ! // post("Event type %d",eventType); ! ! /* get bitmask representing supported button types */ ! ioctl(x->x_fd, EVIOCGBIT(eventType, KEY_MAX), bitmask[eventType]); ! ! /* cycle through all possible event codes (axes, keys, etc.) ! * testing to see which are supported ! */ ! for (eventCode = 0; eventCode < KEY_MAX; eventCode++) ! if (test_bit(eventCode, bitmask[eventType])) { ! post(" Event code %d (%s)", eventCode, names[eventType] ? (names[eventType][eventCode] ? names[eventType][eventCode] : "?") : "?"); ! ! switch(eventType) { ! // the API changed at some point... ! #ifdef EV_RST ! case EV_RST: ! #else ! case EV_SYN: ! #endif ! break; ! case EV_KEY: ! buttons++; ! break; ! case EV_REL: ! rel_axes++; ! break; ! case EV_ABS: ! abs_axes++; ! break; ! case EV_MSC: ! break; ! case EV_LED: ! break; ! case EV_SND: ! break; ! case EV_REP: ! break; ! case EV_FF: ! ff++; ! break; ! } ! } ! } ! } ! ! post ("\nUsing %d relative axes, %d absolute axes, and %d buttons.", rel_axes, abs_axes, buttons); ! if (ff > 0) post ("Detected %d force feedback types",ff); ! post ("\nWARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING"); ! post ("This object is under development! The interface could change at anytime!"); ! post ("As I write cross-platform versions, the interface might have to change."); ! post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING\n"); ! #endif ! ! return 1; ! } ! ! static int linuxevent_read(t_linuxevent *x,int fd) { ! if (x->x_fd < 0) return 0; ! ! #ifdef __gnu_linux__ ! while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1) { ! outlet_float (x->x_input_event_value_outlet, (int)x->x_input_event.value); ! outlet_float (x->x_input_event_code_outlet, x->x_input_event.code); ! outlet_float (x->x_input_event_type_outlet, x->x_input_event.type); ! /* input_event.time is a timeval struct from <sys/time.h> */ ! /* outlet_float (x->x_input_event_time_outlet, x->x_input_event.time); */ ! } ! #endif ! ! if (x->x_started) { ! clock_delay(x->x_clock, x->x_delay); ! } ! ! return 1; ! } ! ! /* Actions */ ! static void linuxevent_float(t_linuxevent* x) { ! DEBUG(post("linuxevent_float");) ! ! } ! ! void linuxevent_delay(t_linuxevent* x, t_float f) { ! DEBUG(post("linuxevent_DELAY %f",f);) ! ! /* if the user sets the delay less than zero, reset to default */ ! if ( f > 0 ) { ! x->x_delay = (int)f; ! } else { ! x->x_delay = DEFAULT_DELAY; ! } ! } ! ! void linuxevent_start(t_linuxevent* x) { ! DEBUG(post("linuxevent_start");); ! ! if (x->x_fd >= 0 && !x->x_started) { ! clock_delay(x->x_clock, DEFAULT_DELAY); ! post("linuxevent: polling started"); ! x->x_started = 1; ! } else { ! post("You need to set a input device (i.e /dev/input/event0)"); ! } ! } ! ! /* setup functions */ ! static void linuxevent_free(t_linuxevent* x) { ! DEBUG(post("linuxevent_free");) ! ! if (x->x_fd < 0) return; ! ! linuxevent_stop(x); ! clock_free(x->x_clock); ! close (x->x_fd); ! } ! ! static void *linuxevent_new(t_symbol *s) { ! int i; ! t_linuxevent *x = (t_linuxevent *)pd_new(linuxevent_class); ! ! DEBUG(post("linuxevent_new");) ! ! post("[linuxevent] %s, written by Hans-Christoph Steiner hans@eds.org",version); ! #ifndef __linux__ ! post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); ! post(" This is a dummy, since this object only works with a Linux kernel!"); ! post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); ! #endif ! ! /* init vars */ ! x->x_fd = -1; ! x->x_read_ok = 1; ! x->x_started = 0; ! x->x_delay = DEFAULT_DELAY; ! x->x_devname = gensym(LINUXEVENT_DEVICE); ! ! x->x_clock = clock_new(x, (t_method)linuxevent_read); ! ! /* create outlets for each axis */ ! x->x_input_event_time_outlet = outlet_new(&x->x_obj, &s_float); ! x->x_input_event_type_outlet = outlet_new(&x->x_obj, &s_float); ! x->x_input_event_code_outlet = outlet_new(&x->x_obj, &s_float); ! x->x_input_event_value_outlet = outlet_new(&x->x_obj, &s_float); ! ! /* set to the value from the object argument, if that exists */ ! if (s != &s_) ! x->x_devname = s; ! ! /* Open the device and save settings */ ! ! if (!linuxevent_open(x,s)) return x; ! ! return (x); ! } ! ! void linuxevent_setup(void) { ! DEBUG(post("linuxevent_setup");) ! linuxevent_class = class_new(gensym("linuxevent"), ! (t_newmethod)linuxevent_new, ! (t_method)linuxevent_free, ! sizeof(t_linuxevent),0,A_DEFSYM,0); ! ! /* add inlet datatype methods */ ! class_addfloat(linuxevent_class,(t_method) linuxevent_float); ! class_addbang(linuxevent_class,(t_method) linuxevent_read); ! ! /* add inlet message methods */ ! class_addmethod(linuxevent_class,(t_method) linuxevent_delay,gensym("delay"),A_DEFFLOAT,0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_open,gensym("open"),A_DEFSYM,0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_close,gensym("close"),0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_start,gensym("start"),0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_start,gensym("poll"),0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_stop,gensym("stop"),0); ! class_addmethod(linuxevent_class,(t_method) linuxevent_stop,gensym("nopoll"),0); ! } !
Index: Makefile =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/Makefile,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Makefile 17 Nov 2003 21:09:44 -0000 1.10 --- Makefile 22 Oct 2004 02:34:32 -0000 1.11 *************** *** 1,3 **** ! CC=gcc-3.2
pd_linux: pan_gogins~.pd_linux range.pd_linux linuxmouse.pd_linux linuxevent.pd_linux linuxjoystick.pd_linux ifeel.pd_linux platformdummy.pd_linux --- 1,3 ---- ! CC=gcc
pd_linux: pan_gogins~.pd_linux range.pd_linux linuxmouse.pd_linux linuxevent.pd_linux linuxjoystick.pd_linux ifeel.pd_linux platformdummy.pd_linux
Index: linuxjoystick.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/linuxjoystick.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** linuxjoystick.c 28 May 2004 01:03:21 -0000 1.6 --- linuxjoystick.c 22 Oct 2004 02:34:32 -0000 1.7 *************** *** 1,2 **** --- 1,4 ---- + #include <m_pd.h> + #include "linuxhid.h"
Index: linuxmouse.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/linuxmouse.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** linuxmouse.c 30 May 2004 01:59:05 -0000 1.6 --- linuxmouse.c 22 Oct 2004 02:34:32 -0000 1.7 *************** *** 1,276 **** ! #include "linuxhid.h" ! ! #define LINUXMOUSE_DEVICE "/dev/input/event0" ! #define LINUXMOUSE_AXES 3 ! ! static char *version = "$Revision$"; ! ! /*------------------------------------------------------------------------------ ! * CLASS DEF ! */ ! static t_class *linuxmouse_class; ! ! typedef struct _linuxmouse { ! t_object x_obj; ! t_int x_fd; ! t_symbol *x_devname; ! int x_read_ok; ! int x_started; ! #ifdef __gnu_linux__ ! struct input_event x_input_event; ! #endif ! t_outlet *x_axis_out[LINUXMOUSE_AXES]; ! t_outlet *x_button_num_out; ! t_outlet *x_button_val_out; ! unsigned char x_buttons; ! unsigned char x_axes; ! } t_linuxmouse; ! ! /*------------------------------------------------------------------------------ ! * IMPLEMENTATION ! */ ! ! /* Actions */ ! void linuxmouse_stop(t_linuxmouse* x) { ! DEBUG(post("linuxmouse_stop");); ! ! #ifdef __gnu_linux__ ! if (x->x_fd >= 0 && x->x_started) { ! sys_rmpollfn(x->x_fd); ! post("[linuxmouse] stopped"); ! x->x_started = 0; ! } ! #endif ! } ! ! static int linuxmouse_close(t_linuxmouse *x) { ! DEBUG(post("linuxmouse_close");); ! ! /* just to be safe, stop it first */ ! linuxmouse_stop(x); ! ! if (x->x_fd < 0) { ! return 0; ! } ! else { ! close (x->x_fd); ! post ("[linuxmouse] closed %s",x->x_devname->s_name); ! return 1; ! } ! } ! ! static int linuxmouse_open(t_linuxmouse *x, t_symbol *s) { ! int eventType, eventCode; ! char devicename[256] = "Unknown"; ! #ifdef __gnu_linux__ ! unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)]; ! #endif ! ! DEBUG(post("linuxmouse_open");); ! ! linuxmouse_close(x); ! ! /* set obj device name to parameter otherwise set to default */ ! if ( s != &s_ ) ! x->x_devname = s; ! ! #ifdef __gnu_linux__ ! /* open device */ ! if (x->x_devname) { ! /* open the device read-only, non-exclusive */ ! x->x_fd = open (x->x_devname->s_name, O_RDONLY | O_NONBLOCK); ! /* test if device open */ ! if (x->x_fd < 0 ) { ! post("[linuxmouse] open %s failed",x->x_devname->s_name); ! x->x_fd = -1; ! return 0; ! } ! } else { ! post("[linuxmouse] no device set: %s",x->x_devname->s_name); ! return 1; ! } ! ! /* read input_events from the LINUXMOUSE_DEVICE stream ! * It seems that is just there to flush the event input buffer? ! */ ! while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1); ! ! /* get name of device */ ! ioctl(x->x_fd, EVIOCGNAME(sizeof(devicename)), devicename); ! post ("Configuring %s on %s.",devicename,x->x_devname->s_name); ! post("\nSupported events:"); ! ! /* get bitmask representing supported events (axes, buttons, etc.) */ ! memset(bitmask, 0, sizeof(bitmask)); ! ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), bitmask[0]); ! ! x->x_axes = 0; ! x->x_buttons = 0; ! ! /* cycle through all possible event types */ ! for (eventType = 0; eventType < EV_MAX; eventType++) { ! if (test_bit(eventType, bitmask[0])) { ! post(" %s (type %d) ", events[eventType] ? events[eventType] : "?", eventType); ! // post("Event type %d",eventType); ! ! /* get bitmask representing supported button types */ ! ioctl(x->x_fd, EVIOCGBIT(eventType, KEY_MAX), bitmask[eventType]); ! ! /* cycle through all possible event codes (axes, keys, etc.) ! * testing to see which are supported ! */ ! for (eventCode = 0; eventCode < KEY_MAX; eventCode++) { ! if (test_bit(eventCode, bitmask[eventType])) { ! post(" Event code %d (%s)", eventCode, names[eventType] ? (names[eventType][eventCode] ? names[eventType][eventCode] : "?") : "?"); ! ! if ( eventType == EV_KEY ) ! x->x_buttons++; ! else if ( eventType == EV_REL ) ! x->x_axes++; ! } ! } ! } ! } ! ! post ("\nUsing %d axes and %d buttons.", x->x_axes, x->x_buttons); ! post ("\nWARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING"); ! post ("This object is under development! The interface could change at anytime!"); ! post ("As I write cross-platform versions, the interface might have to change."); ! post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING\n"); ! #endif ! ! return 1; ! } ! ! static int linuxmouse_read(t_linuxmouse *x,int fd) { ! int axis_num = 0; ! t_float button_num = 0; ! ! if (x->x_fd < 0) return 0; ! ! #ifdef __gnu_linux__ ! while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1) { ! if ( x->x_input_event.type == EV_REL ) { ! /* Relative Axes Event Type */ ! switch ( x->x_input_event.code ) { ! case REL_X: ! axis_num = 0; ! break; ! case REL_Y: ! axis_num = 1; ! break; ! case REL_WHEEL: ! axis_num = 2; ! break; ! } ! outlet_float (x->x_axis_out[axis_num], (int)x->x_input_event.value); ! } ! else if ( x->x_input_event.type == EV_KEY ) { ! /* key/button event type */ ! switch ( x->x_input_event.code ) { ! case BTN_LEFT: ! button_num = 0; ! break; ! case BTN_RIGHT: ! button_num = 1; ! break; ! case BTN_MIDDLE: ! button_num = 2; ! break; ! case BTN_SIDE: ! button_num = 3; ! break; ! case BTN_EXTRA: ! button_num = 4; ! break; ! case BTN_FORWARD: ! button_num = 5; ! break; ! case BTN_BACK: ! button_num = 6; ! break; ! } ! outlet_float (x->x_button_val_out, x->x_input_event.value); ! outlet_float (x->x_button_num_out, button_num); ! } ! } ! #endif ! ! return 1; ! } ! ! void linuxmouse_start(t_linuxmouse* x) { ! DEBUG(post("linuxmouse_start");); ! ! /* if the device isn't open already, open it */ ! /* (I'll test this later -HCS) */ ! /* if (x->x_fd < 0) linuxmouse_open(x,&s_); */ ! ! #ifdef __gnu_linux__ ! if (x->x_fd >= 0 && !x->x_started) { ! sys_addpollfn(x->x_fd, (t_fdpollfn)linuxmouse_read, x); ! post("[linuxmouse] started"); ! x->x_started = 1; ! } else { ! post("You need to set a input device (i.e /dev/input/event0)"); ! } ! #endif ! } ! ! /* setup functions */ ! static void linuxmouse_free(t_linuxmouse* x) { ! DEBUG(post("linuxmouse_free");); ! ! if (x->x_fd < 0) return; ! linuxmouse_stop(x); ! close (x->x_fd); ! } ! ! static void *linuxmouse_new(t_symbol *s) { ! int i; ! t_linuxmouse *x = (t_linuxmouse *)pd_new(linuxmouse_class); ! ! DEBUG(post("linuxmouse_new");); ! ! post("[linuxmouse] %s, written by Hans-Christoph Steiner hans@eds.org",version); ! #ifndef __gnu_linux__ ! post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); ! post(" This is a dummy, since this object only works with a Linux kernel!"); ! post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); ! #endif ! ! /* init vars */ ! x->x_fd = -1; ! x->x_read_ok = 1; ! x->x_started = 0; ! x->x_devname = gensym("/dev/input/event0"); ! ! /* create outlets for each axis */ ! for (i = 0; i < LINUXMOUSE_AXES; i++) ! x->x_axis_out[i] = outlet_new(&x->x_obj, &s_float); ! ! /* create outlets for buttons */ ! x->x_button_num_out = outlet_new(&x->x_obj, &s_float); ! x->x_button_val_out = outlet_new(&x->x_obj, &s_float); ! ! if (!linuxmouse_open(x,s)) return x; ! ! return (x); ! } ! ! void linuxmouse_setup(void) { ! DEBUG(post("linuxmouse_setup");); ! linuxmouse_class = class_new(gensym("linuxmouse"), ! (t_newmethod)linuxmouse_new, ! (t_method)linuxmouse_free, ! sizeof(t_linuxmouse), 0, A_DEFSYM, 0); ! ! /* add inlet message methods */ ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_open,gensym("open"),A_DEFSYM,0); ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_close,gensym("close"),0); ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_start,gensym("start"),0); ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_stop,gensym("stop"),0); ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_start,gensym("poll"),0); ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_stop,gensym("nopoll"),0); ! } ! --- 1,284 ---- ! #include <m_pd.h> ! ! #ifdef PD_MAJOR_VERSION ! #include "s_stuff.h" ! #else ! #include "m_imp.h" ! #endif ! ! #include "linuxhid.h" ! ! #define LINUXMOUSE_DEVICE "/dev/input/event0" ! #define LINUXMOUSE_AXES 3 ! ! static char *version = "$Revision$"; ! ! /*------------------------------------------------------------------------------ ! * CLASS DEF ! */ ! static t_class *linuxmouse_class; ! ! typedef struct _linuxmouse { ! t_object x_obj; ! t_int x_fd; ! t_symbol *x_devname; ! int x_read_ok; ! int x_started; ! #ifdef __gnu_linux__ ! struct input_event x_input_event; ! #endif ! t_outlet *x_axis_out[LINUXMOUSE_AXES]; ! t_outlet *x_button_num_out; ! t_outlet *x_button_val_out; ! unsigned char x_buttons; ! unsigned char x_axes; ! } t_linuxmouse; ! ! /*------------------------------------------------------------------------------ ! * IMPLEMENTATION ! */ ! ! /* Actions */ ! void linuxmouse_stop(t_linuxmouse* x) { ! DEBUG(post("linuxmouse_stop");); ! ! #ifdef __gnu_linux__ ! if (x->x_fd >= 0 && x->x_started) { ! sys_rmpollfn(x->x_fd); ! post("[linuxmouse] stopped"); ! x->x_started = 0; ! } ! #endif ! } ! ! static int linuxmouse_close(t_linuxmouse *x) { ! DEBUG(post("linuxmouse_close");); ! ! /* just to be safe, stop it first */ ! linuxmouse_stop(x); ! ! if (x->x_fd < 0) { ! return 0; ! } ! else { ! close (x->x_fd); ! post ("[linuxmouse] closed %s",x->x_devname->s_name); ! return 1; ! } ! } ! ! static int linuxmouse_open(t_linuxmouse *x, t_symbol *s) { ! int eventType, eventCode; ! char devicename[256] = "Unknown"; ! #ifdef __gnu_linux__ ! unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)]; ! #endif ! ! DEBUG(post("linuxmouse_open");); ! ! linuxmouse_close(x); ! ! /* set obj device name to parameter otherwise set to default */ ! if ( s != &s_ ) ! x->x_devname = s; ! ! #ifdef __gnu_linux__ ! /* open device */ ! if (x->x_devname) { ! /* open the device read-only, non-exclusive */ ! x->x_fd = open (x->x_devname->s_name, O_RDONLY | O_NONBLOCK); ! /* test if device open */ ! if (x->x_fd < 0 ) { ! post("[linuxmouse] open %s failed",x->x_devname->s_name); ! x->x_fd = -1; ! return 0; ! } ! } else { ! post("[linuxmouse] no device set: %s",x->x_devname->s_name); ! return 1; ! } ! ! /* read input_events from the LINUXMOUSE_DEVICE stream ! * It seems that is just there to flush the event input buffer? ! */ ! while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1); ! ! /* get name of device */ ! ioctl(x->x_fd, EVIOCGNAME(sizeof(devicename)), devicename); ! post ("Configuring %s on %s.",devicename,x->x_devname->s_name); ! post("\nSupported events:"); ! ! /* get bitmask representing supported events (axes, buttons, etc.) */ ! memset(bitmask, 0, sizeof(bitmask)); ! ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), bitmask[0]); ! ! x->x_axes = 0; ! x->x_buttons = 0; ! ! /* cycle through all possible event types */ ! for (eventType = 0; eventType < EV_MAX; eventType++) { ! if (test_bit(eventType, bitmask[0])) { ! post(" %s (type %d) ", events[eventType] ? events[eventType] : "?", eventType); ! // post("Event type %d",eventType); ! ! /* get bitmask representing supported button types */ ! ioctl(x->x_fd, EVIOCGBIT(eventType, KEY_MAX), bitmask[eventType]); ! ! /* cycle through all possible event codes (axes, keys, etc.) ! * testing to see which are supported ! */ ! for (eventCode = 0; eventCode < KEY_MAX; eventCode++) { ! if (test_bit(eventCode, bitmask[eventType])) { ! post(" Event code %d (%s)", eventCode, names[eventType] ? (names[eventType][eventCode] ? names[eventType][eventCode] : "?") : "?"); ! ! if ( eventType == EV_KEY ) ! x->x_buttons++; ! else if ( eventType == EV_REL ) ! x->x_axes++; ! } ! } ! } ! } ! ! post ("\nUsing %d axes and %d buttons.", x->x_axes, x->x_buttons); ! post ("\nWARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING"); ! post ("This object is under development! The interface could change at anytime!"); ! post ("As I write cross-platform versions, the interface might have to change."); ! post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING\n"); ! #endif ! ! return 1; ! } ! ! static int linuxmouse_read(t_linuxmouse *x,int fd) { ! int axis_num = 0; ! t_float button_num = 0; ! ! if (x->x_fd < 0) return 0; ! ! #ifdef __gnu_linux__ ! while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1) { ! if ( x->x_input_event.type == EV_REL ) { ! /* Relative Axes Event Type */ ! switch ( x->x_input_event.code ) { ! case REL_X: ! axis_num = 0; ! break; ! case REL_Y: ! axis_num = 1; ! break; ! case REL_WHEEL: ! axis_num = 2; ! break; ! } ! outlet_float (x->x_axis_out[axis_num], (int)x->x_input_event.value); ! } ! else if ( x->x_input_event.type == EV_KEY ) { ! /* key/button event type */ ! switch ( x->x_input_event.code ) { ! case BTN_LEFT: ! button_num = 0; ! break; ! case BTN_RIGHT: ! button_num = 1; ! break; ! case BTN_MIDDLE: ! button_num = 2; ! break; ! case BTN_SIDE: ! button_num = 3; ! break; ! case BTN_EXTRA: ! button_num = 4; ! break; ! case BTN_FORWARD: ! button_num = 5; ! break; ! case BTN_BACK: ! button_num = 6; ! break; ! } ! outlet_float (x->x_button_val_out, x->x_input_event.value); ! outlet_float (x->x_button_num_out, button_num); ! } ! } ! #endif ! ! return 1; ! } ! ! void linuxmouse_start(t_linuxmouse* x) { ! DEBUG(post("linuxmouse_start");); ! ! /* if the device isn't open already, open it */ ! /* (I'll test this later -HCS) */ ! /* if (x->x_fd < 0) linuxmouse_open(x,&s_); */ ! ! #ifdef __gnu_linux__ ! if (x->x_fd >= 0 && !x->x_started) { ! sys_addpollfn(x->x_fd, (t_fdpollfn)linuxmouse_read, x); ! post("[linuxmouse] started"); ! x->x_started = 1; ! } else { ! post("You need to set a input device (i.e /dev/input/event0)"); ! } ! #endif ! } ! ! /* setup functions */ ! static void linuxmouse_free(t_linuxmouse* x) { ! DEBUG(post("linuxmouse_free");); ! ! if (x->x_fd < 0) return; ! linuxmouse_stop(x); ! close (x->x_fd); ! } ! ! static void *linuxmouse_new(t_symbol *s) { ! int i; ! t_linuxmouse *x = (t_linuxmouse *)pd_new(linuxmouse_class); ! ! DEBUG(post("linuxmouse_new");); ! ! post("[linuxmouse] %s, written by Hans-Christoph Steiner hans@eds.org",version); ! #ifndef __gnu_linux__ ! post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); ! post(" This is a dummy, since this object only works with a Linux kernel!"); ! post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); ! #endif ! ! /* init vars */ ! x->x_fd = -1; ! x->x_read_ok = 1; ! x->x_started = 0; ! x->x_devname = gensym("/dev/input/event0"); ! ! /* create outlets for each axis */ ! for (i = 0; i < LINUXMOUSE_AXES; i++) ! x->x_axis_out[i] = outlet_new(&x->x_obj, &s_float); ! ! /* create outlets for buttons */ ! x->x_button_num_out = outlet_new(&x->x_obj, &s_float); ! x->x_button_val_out = outlet_new(&x->x_obj, &s_float); ! ! if (!linuxmouse_open(x,s)) return x; ! ! return (x); ! } ! ! void linuxmouse_setup(void) { ! DEBUG(post("linuxmouse_setup");); ! linuxmouse_class = class_new(gensym("linuxmouse"), ! (t_newmethod)linuxmouse_new, ! (t_method)linuxmouse_free, ! sizeof(t_linuxmouse), 0, A_DEFSYM, 0); ! ! /* add inlet message methods */ ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_open,gensym("open"),A_DEFSYM,0); ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_close,gensym("close"),0); ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_start,gensym("start"),0); ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_stop,gensym("stop"),0); ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_start,gensym("poll"),0); ! class_addmethod(linuxmouse_class,(t_method) linuxmouse_stop,gensym("nopoll"),0); ! } !