Update of /cvsroot/pure-data/externals/hcs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30099
Modified Files: ifeel-help.pd ifeel.c Log Message: added [command( msg and cleaned up code
Index: ifeel-help.pd =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/ifeel-help.pd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ifeel-help.pd 17 Nov 2003 06:25:03 -0000 1.1 --- ifeel-help.pd 28 May 2004 01:01:36 -0000 1.2 *************** *** 1,26 **** ! #N canvas 736 320 450 300 10; ! #X obj 105 228 ifeel /dev/input/ifeel0; ! #X obj 160 82 hsl 128 20 0 255 0 0 empty empty interval_(0-255) 6 8 ! 32 8 -225271 -1 -1 12700 0; ! #X obj 212 130 hsl 128 20 0 255 0 0 empty empty count_(0-255) 6 8 32 ! 8 -261681 -1 -1 0 0; ! #X obj 264 178 hsl 128 20 0 1 0 0 empty empty level_(0-1) 6 8 32 8 ! -261689 -1 -1 12700 0; ! #X obj 61 157 bng 25 250 50 0 empty empty empty 0 -6 32 8 -24198 -1 -1; ! #X obj 105 157 bng 25 250 50 0 empty empty empty 0 -6 32 8 -258699 ! -1 -1; ! #X msg 105 187 stop; ! #X msg 61 187 start; ! #X obj 261 201 nbx 5 14 -1e+37 1e+37 0 0 pack_bang_env empty empty ! 0 -6 33 10 -233017 -1 -1 1 256; ! #X obj 209 153 nbx 3 14 -1e+37 1e+37 0 0 pack_bang_env empty empty ! 0 -6 33 10 -233017 -1 -1 0 256; ! #X obj 157 105 nbx 3 14 -1e+37 1e+37 0 0 pack_bang_env empty empty ! 0 -6 33 10 -233017 -1 -1 255 256; ! #X obj 120 9 cnv 15 20 20 empty empty ifeel 4 12 33 14 -228992 -66577 0; ! #X text 190 15 control the pulse in an iFeel mouse; ! #X obj 4 13 force-feedback; #X connect 1 0 10 0; #X connect 2 0 9 0; --- 1,39 ---- ! #N canvas 208 93 480 482 10; ! #X obj 187 324 ifeel /dev/input/ifeel0; ! #X obj 242 224 hsl 128 20 0 255 0 0 empty empty interval_(0-255) 6 ! 10 1 10 -225271 -1 -1 0 0; ! #X obj 294 253 hsl 128 20 0 255 0 0 empty empty count_(0-255) 6 10 ! 1 10 -261681 -1 -1 0 0; ! #X obj 346 282 hsl 128 20 0 1 0 0 empty empty strength_(0-1) 6 10 1 ! 10 -261689 -1 -1 0 0; ! #X obj 182 46 bng 25 250 50 0 empty empty empty 0 -6 0 8 -24198 -1 -1; ! #X obj 226 46 bng 25 250 50 0 empty empty empty 0 -6 0 8 -258699 -1 ! -1; ! #X msg 226 76 stop; ! #X msg 182 76 start; ! #X obj 343 305 nbx 5 14 -1e+37 1e+37 0 0 pack_bang_env empty empty ! 0 -6 0 10 -233017 -1 -1 0 256; ! #X obj 291 276 nbx 3 14 -1e+37 1e+37 0 0 pack_bang_env empty empty ! 0 -6 0 10 -233017 -1 -1 0 256; ! #X obj 239 247 nbx 3 14 -1e+37 1e+37 0 0 pack_bang_env empty empty ! 0 -6 0 10 -233017 -1 -1 0 256; ! #X obj 3 4 cnv 15 470 30 empty empty [ifeel] 4 12 1 16 -228992 -66577 0; ! #X text 73 10 control the pulse in an iFeel mouse; ! #X text 37 359 If you feed data to the ifeel mouse too quickly , it ! has a tendency to crash the whole machine. I suspect a bug in the kernel ! module ifeel.o.; ! #X text 13 449 by Hans-Christoph Steiner hans@at.or.at; ! #X obj 324 416 all_about_haptics; ! #X text 201 417 For more info:; ! #X msg 251 168 strength 0.56; ! #X msg 234 124 interval 73; ! #X msg 243 147 count 14; ! #X msg 26 271 command 50 10 1; ! #X text 19 223 interval count strength; ! #X text 1 205 Or give a single command:; ! #X msg 26 249 command 25 255 1; ! #X msg 26 293 command 0 0 0; #X connect 1 0 10 0; #X connect 2 0 9 0; *************** *** 33,34 **** --- 46,53 ---- #X connect 9 0 0 2; #X connect 10 0 0 1; + #X connect 17 0 0 0; + #X connect 18 0 0 0; + #X connect 19 0 0 0; + #X connect 20 0 0 0; + #X connect 23 0 0 0; + #X connect 24 0 0 0;
Index: ifeel.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/ifeel.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ifeel.c 14 Apr 2004 23:50:44 -0000 1.3 --- ifeel.c 28 May 2004 01:01:36 -0000 1.4 *************** *** 21,27 **** * there is a difference in the naming schemes of the ifeel driver and this * object. The ifeel driver uses strength, delay, and count. This object ! * uses level, interval, and count. * ! * strength/level - the strength of the pulse (I am searching for a better word) * delay/interval - the interval in between each pulse * count - the total number of pulses to do --- 21,27 ---- * there is a difference in the naming schemes of the ifeel driver and this * object. The ifeel driver uses strength, delay, and count. This object ! * uses strength, interval, and count. * ! * strength - the strength of the pulse (I am searching for a better word) * delay/interval - the interval in between each pulse * count - the total number of pulses to do *************** *** 51,55 **** static t_class *ifeel_class;
! typedef struct _ifeel { t_object x_obj; int x_fd; --- 51,56 ---- static t_class *ifeel_class;
! typedef struct _ifeel ! { t_object x_obj; int x_fd; *************** *** 63,82 **** ******************************************************************************/
! void ifeel_playcommand(t_ifeel *x) { /* const struct timespec *requested_time; */ /* struct timespec *remaining; */ ! #ifdef __linux__ ! if (ioctl(x->x_fd, USB_IFEEL_BUZZ_IOCTL, &x->x_ifeel_command) < 0) { ! post("x->x_fd: %d",x->x_fd); ! post("level: %d interval: %d count: %d",x->x_ifeel_command.strength,x->x_ifeel_command.delay,x->x_ifeel_command.count); ! post("ERROR %s", strerror(errno)); ! close(x->x_fd); ! } ! #endif ! ! DEBUG( ! post("level: %d interval: %d count: %d",x->x_ifeel_command.strength,x->x_ifeel_command.delay,x->x_ifeel_command.count); ! post("");) }
--- 64,87 ---- ******************************************************************************/
! void ifeel_playcommand(t_ifeel *x) ! { /* const struct timespec *requested_time; */ /* struct timespec *remaining; */ ! #ifdef __linux__ ! if (ioctl(x->x_fd, USB_IFEEL_BUZZ_IOCTL, &x->x_ifeel_command) < 0) ! { ! post("x->x_fd: %d",x->x_fd); ! post("strength: %d interval: %d count: %d", ! x->x_ifeel_command.strength,x->x_ifeel_command.delay,x->x_ifeel_command.count); ! post("ERROR %s", strerror(errno)); ! close(x->x_fd); ! } ! #endif /* __linux__ */ ! ! DEBUG( ! post("strength: %d interval: %d count: %d", ! x->x_ifeel_command.strength,x->x_ifeel_command.delay,x->x_ifeel_command.count); ! post("");); }
*************** *** 96,146 **** }
! void ifeel_stop(t_ifeel *x) { ! DEBUG(post("ifeel_stop");) ! ! /* ! * there is no 'stop' ioctl, so set everything to zero ! * to achieve the same effect ! */ ! x->x_ifeel_command.strength = 0; ! x->x_ifeel_command.delay = 0; ! x->x_ifeel_command.count = 0;
! ifeel_playcommand(x); }
! void ifeel_level(t_ifeel *x, t_floatarg level) { ! DEBUG(post("ifeel_level");) ! ! /* ! * make sure its in the proper range ! * this object takes floats 0-1 ! * the ifeel driver takes ints 0-255 ! */ ! level = level * 255; ! level = (level > 255 ? 255 : level); ! level = (level < 0 ? 0 : level);
! x->x_ifeel_command.strength = (unsigned int)level; }
! void ifeel_interval(t_ifeel *x, t_floatarg interval) { ! DEBUG(post("ifeel_interval");) ! ! interval = (interval < 0 ? 0 : interval); ! ! x->x_ifeel_command.delay = (unsigned int)interval; }
! void ifeel_count(t_ifeel *x, t_floatarg count ) { ! DEBUG(post("ifeel_count");) ! ! count = (count < 0 ? 0 : count);
! x->x_ifeel_command.count = (unsigned int)count; }
! static int ifeel_open(t_ifeel *x) { ! return 1; }
--- 101,178 ---- }
! void ifeel_stop(t_ifeel *x) ! { ! DEBUG(post("ifeel_stop");); ! struct ifeel_command temp_ifeel_command;
! /* store previous command for restoring after stop */ ! temp_ifeel_command.strength = x->x_ifeel_command.strength; ! temp_ifeel_command.delay = x->x_ifeel_command.delay; ! temp_ifeel_command.count = x->x_ifeel_command.count; ! ! /* ! * there is no 'stop' ioctl, so set everything to zero ! * to achieve the same effect ! */ ! x->x_ifeel_command.strength = 0; ! x->x_ifeel_command.delay = 0; ! x->x_ifeel_command.count = 0; ! ! ifeel_playcommand(x); ! ! /* restore previous command so the start msg will work */ ! x->x_ifeel_command.strength = temp_ifeel_command.strength; ! x->x_ifeel_command.delay = temp_ifeel_command.delay; ! x->x_ifeel_command.count = temp_ifeel_command.count; }
! void ifeel_strength(t_ifeel *x, t_floatarg strength) ! { ! DEBUG(post("ifeel_strength");); ! ! /* ! * make sure its in the proper range ! * this object takes floats 0-1 ! * the ifeel driver takes ints 0-255 ! */ ! strength = strength * 255; ! strength = (strength > 255 ? 255 : strength); ! strength = (strength < 0 ? 0 : strength);
! x->x_ifeel_command.strength = (unsigned int)strength; }
! void ifeel_interval(t_ifeel *x, t_floatarg interval) ! { ! DEBUG(post("ifeel_interval");); ! ! interval = (interval < 0 ? 0 : interval); ! ! x->x_ifeel_command.delay = (unsigned int)interval; }
! void ifeel_count(t_ifeel *x, t_floatarg count ) ! { ! DEBUG(post("ifeel_count");); ! ! count = (count < 0 ? 0 : count); ! ! x->x_ifeel_command.count = (unsigned int)count; ! }
! void ifeel_command(t_ifeel *x, t_floatarg interval, t_floatarg count, t_floatarg strength) ! { ! DEBUG(post("ifeel_command");); ! ! ifeel_strength(x,strength); ! ifeel_interval(x,interval); ! ifeel_count(x,count); ! ! ifeel_playcommand(x); }
! static int ifeel_open(t_ifeel *x) ! { ! return 1; }
*************** *** 151,175 **** void ifeel_free(t_ifeel *x) { ! DEBUG(post("ifeel_free");) ! ! /* stop effect */ ! ifeel_stop(x); ! ! /* close device */ ! close(x->x_fd); }
! void *ifeel_new(t_symbol *device, t_floatarg level, t_floatarg interval, t_floatarg count) { ! DEBUG(post("ifeel_new");) ! ! t_ifeel *x = (t_ifeel *)pd_new(ifeel_class);
! post("iFeel mouse, by Hans-Christoph Steiner hans@eds.org"); ! post(""); ! post ("WARNING * 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"); ! post(""); #ifndef __linux__ post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); --- 183,207 ---- void ifeel_free(t_ifeel *x) { ! DEBUG(post("ifeel_free");); ! ! /* stop effect */ ! ifeel_stop(x); ! ! /* close device */ ! close(x->x_fd); }
! void *ifeel_new(t_symbol *device, t_floatarg strength, t_floatarg interval, t_floatarg count) { ! DEBUG(post("ifeel_new");); ! ! t_ifeel *x = (t_ifeel *)pd_new(ifeel_class);
! post("iFeel mouse, by Hans-Christoph Steiner hans@eds.org"); ! post(""); ! post ("WARNING * 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"); ! post(""); #ifndef __linux__ post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); *************** *** 182,220 **** * struct with the argument values */ ! x->x_ifeel_command.strength = 0; ! x->x_ifeel_command.delay = 0; ! x->x_ifeel_command.count = 0; ! ! inlet_new(&x->x_obj, ! &x->x_obj.ob_pd, ! gensym("float"), ! gensym("interval")); ! inlet_new(&x->x_obj, ! &x->x_obj.ob_pd, ! gensym("float"), ! gensym("count")); ! inlet_new(&x->x_obj, ! &x->x_obj.ob_pd, ! gensym("float"), ! gensym("level")); ! ! if (device != &s_) { ! post("Using %s",device->s_name); ! ! /* x->x_fd = open(IFEEL_DEVICE, O_RDWR); */ ! if ((x->x_fd = open((char *) device->s_name, O_RDWR | O_NONBLOCK, 0)) <= 0) { ! printf("ERROR %s\n", strerror(errno)); ! return 0; ! } ! ! /* ifeel_level(x,level); */ /* ifeel_interval(x,interval); */ /* ifeel_count(x,count); */ ! } ! ! else { ! post("ifeel: You need to set an ifeel device (i.e /dev/input/ifeel0)"); ! } ! return (void*)x; } --- 214,255 ---- * struct with the argument values */ ! x->x_ifeel_command.strength = 0; ! x->x_ifeel_command.delay = 0; ! x->x_ifeel_command.count = 0; ! ! inlet_new(&x->x_obj, ! &x->x_obj.ob_pd, ! gensym("float"), ! gensym("interval")); ! inlet_new(&x->x_obj, ! &x->x_obj.ob_pd, ! gensym("float"), ! gensym("count")); ! inlet_new(&x->x_obj, ! &x->x_obj.ob_pd, ! gensym("float"), ! gensym("strength")); ! ! if (device != &s_) ! { ! post("Using %s",device->s_name); ! ! /* x->x_fd = open(IFEEL_DEVICE, O_RDWR); */ ! if ((x->x_fd = open((char *) device->s_name, O_RDWR | O_NONBLOCK, 0)) <= 0) ! { ! printf("ERROR %s\n", strerror(errno)); ! return 0; ! } ! ! /* ifeel_strength(x,strength); */ /* ifeel_interval(x,interval); */ /* ifeel_count(x,count); */ ! } ! ! else ! { ! post("ifeel: You need to set an ifeel device (i.e /dev/input/ifeel0)"); ! } ! return (void*)x; } *************** *** 222,248 **** void ifeel_setup(void) { ! DEBUG(post("ifeel_setup");) ! ! ifeel_class = class_new(gensym("ifeel"), ! (t_newmethod)ifeel_new, ! (t_method)ifeel_free, ! sizeof(t_ifeel), ! CLASS_DEFAULT, ! A_DEFSYMBOL, ! A_DEFFLOAT, ! A_DEFFLOAT, ! A_DEFFLOAT, ! 0); ! ! class_addbang(ifeel_class,ifeel_start); ! ! class_addmethod(ifeel_class, (t_method)ifeel_start,gensym("start"),0); ! class_addmethod(ifeel_class, (t_method)ifeel_stop,gensym("stop"),0); ! ! class_addmethod(ifeel_class, (t_method)ifeel_level, gensym("level"), A_DEFFLOAT,0); ! class_addmethod(ifeel_class, (t_method)ifeel_interval,gensym("interval"),A_DEFFLOAT,0); ! class_addmethod(ifeel_class, (t_method)ifeel_count,gensym("count"),A_DEFFLOAT,0); ! ! }
--- 257,285 ---- void ifeel_setup(void) { ! DEBUG(post("ifeel_setup");); ! ! ifeel_class = class_new(gensym("ifeel"), ! (t_newmethod)ifeel_new, ! (t_method)ifeel_free, ! sizeof(t_ifeel), ! CLASS_DEFAULT, ! A_DEFSYMBOL, ! A_DEFFLOAT, ! A_DEFFLOAT, ! A_DEFFLOAT, ! 0); ! ! class_addbang(ifeel_class,ifeel_start); ! ! class_addmethod(ifeel_class, (t_method)ifeel_start,gensym("start"),0); ! class_addmethod(ifeel_class, (t_method)ifeel_stop,gensym("stop"),0); ! ! class_addmethod(ifeel_class, (t_method)ifeel_command,gensym("command"), ! A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0); ! ! class_addmethod(ifeel_class, (t_method)ifeel_strength,gensym("strength"),A_DEFFLOAT,0); ! class_addmethod(ifeel_class, (t_method)ifeel_interval,gensym("interval"),A_DEFFLOAT,0); ! class_addmethod(ifeel_class, (t_method)ifeel_count,gensym("count"),A_DEFFLOAT,0); ! }