Update of /cvsroot/pure-data/externals/hcs/rawhid In directory sc8-pr-cvs1:/tmp/cvs-serv5904
Modified Files: rawjoystick.c rawjoystick-help.pd Log Message: X, Y, hatX, hatY, buttons all work twist and throttle are still silent. help patch uses toggles to represent buttons
Index: rawjoystick.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/rawhid/rawjoystick.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** rawjoystick.c 20 Aug 2003 16:20:43 -0000 1.2 --- rawjoystick.c 12 Oct 2003 16:26:39 -0000 1.3 *************** *** 18,33 **** /* * $Id$ */ static char *version = "$Revision$";
! #include "SDL.h" #include "m_imp.h"
! //#define DEBUG(x) ! #define DEBUG(x) x
#define RAWJOYSTICK_AXES 6 #define RAWJOYSTICK_BUTTONS 9
/*------------------------------------------------------------------------------ --- 18,45 ---- /* * $Id$ + * + * TODO + * -make work with multiple joysticks (using SDL_JoyHatEvent.which) + * -figure out why it takes so long for [rawjoystick] to start + * -get throttle and twist working */ static char *version = "$Revision$";
! #include <SDL/SDL.h> ! #include <m_pd.h> #include "m_imp.h"
! #define DEBUG(x) ! /* #define DEBUG(x) x */
+ /* total number of axes and buttons supported by this object */ + /* each axis gets a fixed outlet */ #define RAWJOYSTICK_AXES 6 #define RAWJOYSTICK_BUTTONS 9
+ /* this is the outlet number for the hat switch */ + #define RAWJOYSTICK_HATX 3 + #define RAWJOYSTICK_HATY 4 +
/*------------------------------------------------------------------------------ *************** *** 91,96 **** post (" device has %i axes, %i hats, and %i buttons.\n",x->x_axes,x->x_hats,x->x_buttons); 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");
--- 103,108 ---- post (" device has %i axes, %i hats, and %i buttons.\n",x->x_axes,x->x_hats,x->x_buttons); post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING"); ! post ("This object is under development! The interface will change!"); ! post ("This means inlets, outlets, messages, etc. are not fixed!"); post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING");
*************** *** 98,135 **** }
! static int rawjoystick_read(t_rawjoystick *x,int fd) { ! SDL_Event event; ! ! DEBUG(post("rawjoystick_READ"));
! if ( ! SDL_JoystickOpened(x->x_devnum) ) { ! return 0; }
! post("Joystick read: %s",SDL_JoystickName(x->x_devnum));
! if ( SDL_PollEvent(&event) ) { ! post("SDL_Event.type: %i",event.type); ! post("SDL_JoyAxisEvent.value: %i",event.jaxis.value); ! post("SDL_JoyButtonEvent.value: %i",event.jbutton.state); ! switch (event.type) { ! case SDL_JOYAXISMOTION: ! outlet_float (x->x_axis_out[event.jaxis.axis], event.jaxis.value); ! break; ! case SDL_JOYHATMOTION: ! break; ! case SDL_JOYBUTTONDOWN: ! outlet_float (x->x_button_val_out, 1); ! outlet_float (x->x_button_num_out, event.jaxis.axis); ! break; ! case SDL_JOYBUTTONUP: ! outlet_float (x->x_button_val_out, 0); ! outlet_float (x->x_button_num_out, event.jaxis.axis); ! break; ! default: ! DEBUG(post("Unhandled event.")); ! } ! } ! return 1; }
--- 110,176 ---- }
! /* read the joystick, called through clock */ ! static void *rawjoystick_read(t_rawjoystick *x) { ! SDL_Event event; ! ! /* DEBUG(post("rawjoystick_READ")); */ ! ! if ( ! SDL_JoystickOpened(x->x_devnum) ) { ! post ("Joystick not open, you need to open it first."); ! return 0; ! } ! ! /* DEBUG(post("Joystick read: %s",SDL_JoystickName(x->x_devnum));) */
! if ( SDL_PollEvent(&event) ) { ! DEBUG(post("SDL_Event.type: %i",event.type);) ! DEBUG(post("SDL_JoyAxisEvent.value: %i",event.jaxis.value);) ! DEBUG(post("SDL_JoyButtonEvent.value: %i",event.jbutton.state);) ! switch (event.type) { ! case SDL_JOYAXISMOTION: ! /* ! * It might be a good idea to make a for{;;} loop to output the values of ! * all of the axes everytime in right-to-left order. ! */ ! outlet_float (x->x_axis_out[event.jaxis.axis], event.jaxis.value); ! break; ! case SDL_JOYHATMOTION: ! /* this object only supports the first hat switch */ ! if (event.jhat.hat == 0) { ! /* X axis */ ! if (event.jhat.value & SDL_HAT_LEFT) { ! outlet_float (x->x_axis_out[RAWJOYSTICK_HATX], -1); ! } else if (event.jhat.value & SDL_HAT_RIGHT) { ! outlet_float (x->x_axis_out[RAWJOYSTICK_HATX], 1); ! } else { ! outlet_float (x->x_axis_out[RAWJOYSTICK_HATX], 0); ! } ! /* Y axis */ ! if (event.jhat.value & SDL_HAT_UP) { ! outlet_float (x->x_axis_out[RAWJOYSTICK_HATY], -1); ! } else if (event.jhat.value & SDL_HAT_DOWN) { ! outlet_float (x->x_axis_out[RAWJOYSTICK_HATY], 1); ! } else { ! outlet_float (x->x_axis_out[RAWJOYSTICK_HATY], 0); ! } ! } ! break; ! case SDL_JOYBUTTONDOWN: ! outlet_float (x->x_button_val_out, 1); ! outlet_float (x->x_button_num_out, (float)event.jbutton.button); ! break; ! case SDL_JOYBUTTONUP: ! outlet_float (x->x_button_val_out, 0); ! outlet_float (x->x_button_num_out, (float)event.jbutton.button); ! break; ! default: ! DEBUG(post("Unhandled event.")); ! } }
! if (x->started) ! clock_delay(x->x_clock, x->x_delaytime);
! return NULL; }
*************** *** 137,148 ****
static void rawjoystick_bang(t_rawjoystick* x) { ! DEBUG(post("rawjoystick_bang")); }
static void rawjoystick_float(t_rawjoystick* x) { ! DEBUG(post("rawjoystick_float")); }
- // DONE void rawjoystick_start(t_rawjoystick* x) { --- 178,188 ----
static void rawjoystick_bang(t_rawjoystick* x) { ! DEBUG(post("rawjoystick_bang")); }
static void rawjoystick_float(t_rawjoystick* x) { ! DEBUG(post("rawjoystick_float")); }
void rawjoystick_start(t_rawjoystick* x) { *************** *** 150,169 ****
if ( ( SDL_JoystickOpened(x->x_devnum) ) && ( ! x->started ) ) { - sys_addpollfn(x->x_devnum, (t_fdpollfn)rawjoystick_read, x); x->started = 1; } }
- // DONE void rawjoystick_stop(t_rawjoystick* x) { DEBUG(post("rawjoystick_STOP");) ! if ( ( SDL_JoystickOpened(x->x_devnum) ) && ( x->started ) ) { ! sys_rmpollfn(x->x_devnum); ! x->started = 0; } }
/* Misc setup functions */
--- 190,215 ----
if ( ( SDL_JoystickOpened(x->x_devnum) ) && ( ! x->started ) ) { x->started = 1; + clock_delay(x->x_clock, 0); } }
void rawjoystick_stop(t_rawjoystick* x) { DEBUG(post("rawjoystick_STOP");) ! if ( ( SDL_JoystickOpened(x->x_devnum) ) && ( x->started ) ) { ! x->started = 0; ! clock_unset(x->x_clock); } }
+ void rawjoystick_delay(t_rawjoystick* x, t_float f) { + DEBUG(post("rawjoystick_DELAY %f",f);) + + x->x_delaytime = f; + } + + /* Misc setup functions */
*************** *** 178,181 **** --- 224,228 ----
SDL_Quit(); + clock_free(x->x_clock); }
*************** *** 192,195 **** --- 239,245 ---- x->read_ok = 1; x->started = 0; + x->x_delaytime = 5; + + x->x_clock = clock_new(x, (t_method)rawjoystick_read);
/* INIT SDL using joystick layer */ *************** *** 223,227 ****
/* Open the device and save settings */ - if ( ! rawjoystick_open(x) ) return x;
--- 273,276 ---- *************** *** 245,252 **** class_addmethod(rawjoystick_class,(t_method) rawjoystick_open,gensym("open"),0); class_addmethod(rawjoystick_class,(t_method) rawjoystick_close,gensym("close"),0); class_addmethod(rawjoystick_class,(t_method) rawjoystick_start,gensym("start"),0); class_addmethod(rawjoystick_class,(t_method) rawjoystick_stop,gensym("stop"),0); class_addmethod(rawjoystick_class,(t_method) rawjoystick_read,gensym("read"),0); ! }
--- 294,304 ---- class_addmethod(rawjoystick_class,(t_method) rawjoystick_open,gensym("open"),0); class_addmethod(rawjoystick_class,(t_method) rawjoystick_close,gensym("close"),0); + class_addmethod(rawjoystick_class,(t_method) rawjoystick_start,gensym("start"),0); class_addmethod(rawjoystick_class,(t_method) rawjoystick_stop,gensym("stop"),0); + class_addmethod(rawjoystick_class,(t_method) rawjoystick_read,gensym("read"),0); ! ! class_addmethod(rawjoystick_class,(t_method) rawjoystick_delay,gensym("delay"),A_FLOAT,0); }
Index: rawjoystick-help.pd =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/rawhid/rawjoystick-help.pd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** rawjoystick-help.pd 11 Oct 2003 04:28:43 -0000 1.1 --- rawjoystick-help.pd 12 Oct 2003 16:26:39 -0000 1.2 *************** *** 1,60 **** ! #N canvas 26 222 886 505 10; #X msg 192 64 start; #X msg 207 95 stop; #X floatatom 397 180 2 0 0 3 button# - -; #X floatatom 454 179 2 0 0 3 button_value - -; ! #X floatatom 143 180 5 0 0 3 y-axis - -; ! #X floatatom 95 180 5 0 0 3 x-axis - -; #X floatatom 242 181 3 0 0 3 hat-X - -; #X floatatom 288 181 3 0 0 3 hat-Y - -; ! #X floatatom 192 181 5 0 0 3 twist - -; ! #X floatatom 331 180 5 0 0 3 throttle - -; ! #X obj 299 309 select 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ! 19 20 21; ! #X obj 297 354 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 ! -1; ! #X obj 313 355 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 333 354 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 351 354 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 370 353 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 389 354 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 409 353 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 734 354 bng 30 250 50 0 empty empty not_recognized 0 -6 0 8 ! -261689 -1 -1; ! #X obj 689 352 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 667 350 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 647 351 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 631 354 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 613 352 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 596 350 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 579 352 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 561 351 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 541 349 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 523 351 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 503 350 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 485 351 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 466 351 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 447 353 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; ! #X obj 428 353 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X obj 439 220 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 --- 1,56 ---- ! #N canvas 26 222 906 525 10; #X msg 192 64 start; #X msg 207 95 stop; #X floatatom 397 180 2 0 0 3 button# - -; #X floatatom 454 179 2 0 0 3 button_value - -; ! #X floatatom 143 180 6 0 0 3 y-axis - -; ! #X floatatom 95 180 6 0 0 3 x-axis - -; #X floatatom 242 181 3 0 0 3 hat-X - -; #X floatatom 288 181 3 0 0 3 hat-Y - -; ! #X floatatom 192 181 6 0 0 3 twist - -; ! #X floatatom 331 180 6 0 0 3 throttle - -; ! #X obj 299 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 ! 1; ! #X obj 317 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 335 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 353 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 371 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 390 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 408 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 681 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 663 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 645 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 627 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 608 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 590 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 572 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 554 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 535 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 517 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 499 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 481 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 463 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 444 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; ! #X obj 426 355 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; #X obj 439 220 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 *************** *** 62,100 **** #X obj 192 123 rawjoystick; #X msg 282 57 read; ! #X connect 0 0 35 0; ! #X connect 1 0 35 0; ! #X connect 2 0 10 0; ! #X connect 3 0 34 0; ! #X connect 10 0 11 0; ! #X connect 10 1 12 0; ! #X connect 10 2 13 0; ! #X connect 10 3 14 0; ! #X connect 10 4 15 0; ! #X connect 10 5 16 0; ! #X connect 10 6 17 0; ! #X connect 10 7 33 0; ! #X connect 10 8 32 0; ! #X connect 10 9 31 0; ! #X connect 10 10 30 0; ! #X connect 10 11 29 0; ! #X connect 10 12 28 0; ! #X connect 10 13 27 0; ! #X connect 10 14 26 0; ! #X connect 10 15 25 0; ! #X connect 10 16 24 0; ! #X connect 10 17 23 0; ! #X connect 10 18 22 0; ! #X connect 10 19 21 0; ! #X connect 10 20 20 0; ! #X connect 10 21 19 0; ! #X connect 10 22 18 0; ! #X connect 34 0 2 0; ! #X connect 35 0 5 0; ! #X connect 35 1 4 0; ! #X connect 35 2 8 0; ! #X connect 35 3 6 0; ! #X connect 35 4 7 0; ! #X connect 35 5 9 0; ! #X connect 35 6 2 0; ! #X connect 35 7 3 0; ! #X connect 36 0 35 0; --- 58,113 ---- #X obj 192 123 rawjoystick; #X msg 282 57 read; ! #X msg 380 91 close; ! #X msg 381 64 open; ! #X text 470 20 [rawjoystick]'s timer defaults to 5 ms. You can change ! it with the [delay( message:; ! #X msg 529 76 delay 20; ! #X msg 527 105 delay 1000; ! #X obj 303 270 pack f f; ! #X obj 299 309 route 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ! 19 20 21; ! #X obj 721 356 bng 35 250 50 0 empty empty empty 0 -6 0 8 -162590 -1 ! -1; ! #X connect 0 0 33 0; ! #X connect 1 0 33 0; ! #X connect 2 0 40 0; ! #X connect 3 0 32 0; ! #X connect 3 0 40 1; ! #X connect 32 0 2 0; ! #X connect 33 0 5 0; ! #X connect 33 1 4 0; ! #X connect 33 2 8 0; ! #X connect 33 3 6 0; ! #X connect 33 4 7 0; ! #X connect 33 5 9 0; ! #X connect 33 6 2 0; ! #X connect 33 7 3 0; ! #X connect 34 0 33 0; ! #X connect 35 0 33 0; ! #X connect 36 0 33 0; ! #X connect 38 0 33 0; ! #X connect 39 0 33 0; ! #X connect 40 0 41 0; ! #X connect 41 0 10 0; ! #X connect 41 1 11 0; ! #X connect 41 2 12 0; ! #X connect 41 3 13 0; ! #X connect 41 4 14 0; ! #X connect 41 5 15 0; ! #X connect 41 6 16 0; ! #X connect 41 7 31 0; ! #X connect 41 8 30 0; ! #X connect 41 9 29 0; ! #X connect 41 10 28 0; ! #X connect 41 11 27 0; ! #X connect 41 12 26 0; ! #X connect 41 13 25 0; ! #X connect 41 14 24 0; ! #X connect 41 15 23 0; ! #X connect 41 16 22 0; ! #X connect 41 17 21 0; ! #X connect 41 18 20 0; ! #X connect 41 19 19 0; ! #X connect 41 20 18 0; ! #X connect 41 21 17 0; ! #X connect 41 22 42 0;