aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2003-11-17 06:18:23 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2003-11-17 06:18:23 +0000
commitb1533897bfb19b182e50325e6b3c5c6b1c7470a4 (patch)
tree0c9442ada58869c34bc58d4dd0de2ca56d815b6f
parente96ac50ac3609e5b9f82eaae4ee766946b3c91b4 (diff)
fixed [linuxevent] and added help files
svn path=/trunk/externals/hcs/; revision=1188
-rw-r--r--linuxevent-help.pd204
-rw-r--r--linuxevent-joystick.pd29
-rw-r--r--linuxevent.c111
3 files changed, 277 insertions, 67 deletions
diff --git a/linuxevent-help.pd b/linuxevent-help.pd
index 5093c6b..1580638 100644
--- a/linuxevent-help.pd
+++ b/linuxevent-help.pd
@@ -1,21 +1,187 @@
-#N canvas 454 205 450 300 10;
-#X floatatom 254 231 5 0 0 3 code - -;
-#X floatatom 318 231 5 0 0 3 value - -;
-#X floatatom 190 231 4 0 0 3 type - -;
-#X floatatom 117 231 9 0 0 3 time - -;
-#X msg 177 104 start;
-#X msg 178 126 stop;
-#X obj 127 208 linuxevent /dev/input/event0;
-#X obj 127 63 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+#N canvas 547 51 569 453 10;
+#X floatatom 241 326 5 0 0 3 code - -;
+#X floatatom 305 326 5 0 0 3 value - -;
+#X floatatom 177 326 4 0 0 3 type - -;
+#X floatatom 104 326 9 0 0 3 time - -;
+#X msg 164 199 start;
+#X msg 165 221 stop;
+#X obj 114 303 linuxevent /dev/input/event0;
+#X obj 114 158 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
-#X text 147 63 bang to get an update;
-#X text 225 116 start/stop polling;
-#X obj 52 67 metro 20;
-#X msg 182 165 delay 20;
-#X text 249 165 time between polls (ms);
-#X obj 51 35 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+#X text 134 158 bang to get an update;
+#X text 212 211 start/stop polling;
+#X obj 25 158 metro 20;
+#X text 236 260 time between polls (ms);
+#X obj 25 136 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
-#X msg 75 39 stop;
+#X msg 45 136 stop;
+#X msg 169 260 delay 20;
+#X obj 114 109 key;
+#X obj 114 129 select 98;
+#X text 187 129 <- type 'b' for a bang;
+#N canvas 278 328 611 524 Event_Codes 0;
+#X text 28 48 (For a complete listing of Linux Input Events \, see
+/usr/include/linux/input.h.);
+#X obj 11 9 cnv 15 580 30 empty empty Event_Codes 20 12 1 14 -225271
+-66577 0;
+#X text 32 118 EVENT CODE;
+#X text 162 118 #define;
+#X text 232 118 number;
+#X text 32 133 -----------------------------------;
+#X text 32 148 X Axis;
+#X text 32 163 Y Axis;
+#X text 32 178 Z Axis;
+#X text 32 193 Horizontal Wheel;
+#X text 32 208 Dial;
+#X text 32 223 Wheel;
+#X text 32 238 Misc;
+#X text 162 148 REL_X;
+#X text 162 163 REL_Y;
+#X text 162 178 REL_Z;
+#X text 162 193 REL_HWHEEL;
+#X text 162 208 REL_DIAL;
+#X text 162 223 REL_WHEEL;
+#X text 162 238 REL_MISC;
+#X text 232 148 0;
+#X text 232 163 1;
+#X text 232 178 2;
+#X text 232 193 6;
+#X text 232 208 7;
+#X text 232 223 8;
+#X text 232 238 9;
+#X text 307 118 EVENT CODE;
+#X text 457 118 #define;
+#X text 547 118 number;
+#X text 307 148 Absolute X;
+#X text 307 163 Absolute Y;
+#X text 307 178 Absolute Z;
+#X text 307 193 RX;
+#X text 307 208 RY;
+#X text 307 223 RZ;
+#X text 307 238 Throttle;
+#X text 307 253 Rudder;
+#X text 307 268 Wheel;
+#X text 307 283 Gas Pedal;
+#X text 307 298 Brake Pedal;
+#X text 307 313 Hat Switch 0 X-axis;
+#X text 307 328 Hat Switch 0 Y-axis;
+#X text 307 343 Hat Switch 1 X-axis;
+#X text 307 358 Hat Switch 1 Y-axis;
+#X text 307 373 Hat Switch 2 X-axis;
+#X text 307 388 Hat Switch 2 Y-axis;
+#X text 307 403 Hat Switch 3 X-axis;
+#X text 307 418 Hat Switch 3 Y-axis;
+#X text 307 433 Pressure;
+#X text 307 448 Distance;
+#X text 307 463 Tilt X-Axis;
+#X text 307 478 Tilt Y-Axis;
+#X text 307 493 Misc;
+#X text 457 148 ABS_X;
+#X text 457 163 ABS_Y;
+#X text 457 178 ABS_Z;
+#X text 457 193 ABS_RX;
+#X text 457 208 ABS_RY;
+#X text 457 223 ABS_RZ;
+#X text 457 238 ABS_THROTTLE;
+#X text 457 253 ABS_RUDDER;
+#X text 457 268 ABS_WHEEL;
+#X text 457 283 ABS_GAS;
+#X text 457 298 ABS_BRAKE;
+#X text 457 313 ABS_HAT0X;
+#X text 457 328 ABS_HAT0Y;
+#X text 457 343 ABS_HAT1X;
+#X text 457 358 ABS_HAT1Y;
+#X text 457 373 ABS_HAT2X;
+#X text 457 388 ABS_HAT2Y;
+#X text 457 403 ABS_HAT3X;
+#X text 457 418 ABS_HAT3Y;
+#X text 457 433 ABS_PRESSURE;
+#X text 457 448 ABS_DISTANCE;
+#X text 457 463 ABS_TILT_X;
+#X text 457 478 ABS_TILT_Y;
+#X text 457 493 ABS_MISC;
+#X text 547 148 0;
+#X text 547 163 1;
+#X text 547 178 2;
+#X text 547 193 3;
+#X text 547 208 4;
+#X text 547 223 5;
+#X text 547 238 6;
+#X text 547 253 7;
+#X text 547 268 8;
+#X text 547 283 9;
+#X text 547 298 10;
+#X text 547 313 16;
+#X text 547 328 17;
+#X text 547 343 18;
+#X text 547 358 19;
+#X text 547 373 20;
+#X text 547 388 21;
+#X text 547 403 22;
+#X text 547 418 23;
+#X text 547 433 24;
+#X text 547 448 25;
+#X text 547 463 26;
+#X text 547 478 27;
+#X text 547 493 28;
+#X obj 30 89 cnv 15 250 25 empty empty Relative_Axes 20 12 1 12 -241660
+-66577 0;
+#X obj 308 89 cnv 15 280 25 empty empty Absolute_Axes 20 12 1 12 -241660
+-66577 0;
+#X text 307 133 ----------------------------------------;
+#X restore 439 368 pd Event_Codes;
+#N canvas 546 568 420 271 Event_Types 0;
+#X text 28 48 (For a complete listing of Linux Input Events \, see
+/usr/include/linux/input.h.);
+#X text 84 94 EVENT TYPE;
+#X text 84 109 -----------------------------------;
+#X text 84 124 RST;
+#X text 84 139 Keys and Buttons;
+#X text 84 154 Relative Axes;
+#X text 84 169 Absolute Axes;
+#X text 84 184 Misc Events;
+#X text 84 199 LED Event;
+#X text 84 214 Sounds;
+#X text 84 229 Autorepeat Values;
+#X text 84 244 Force Feedback;
+#X text 214 94 #define;
+#X text 214 124 EV_RST;
+#X text 214 139 EV_KEY;
+#X text 214 154 EV_REL;
+#X text 214 169 EV_ABS;
+#X text 214 184 EV_MSC;
+#X text 214 199 EV_LED;
+#X text 214 214 EV_SND;
+#X text 214 229 EV_REP;
+#X text 214 244 EV_FF;
+#X text 284 94 number;
+#X text 284 124 0;
+#X text 284 139 1;
+#X text 284 154 2;
+#X text 284 169 3;
+#X text 284 184 4;
+#X text 284 199 17;
+#X text 284 214 18;
+#X text 284 229 20;
+#X text 284 244 21;
+#X obj 11 9 cnv 15 400 30 empty empty Event_Types 20 12 1 14 -262131
+-66577 0;
+#X restore 439 348 pd Event_Types;
+#N canvas 0 0 450 300 Event_Values 0;
+#X text 28 48 (For a complete listing of Linux Input Events \, see
+/usr/include/linux/input.h.);
+#X obj 11 9 cnv 15 400 30 empty empty Event_Values 20 12 1 14 -261681
+-66577 0;
+#X restore 439 388 pd Event_Values;
+#X text 8 373 Check the Pd console for supported event types and codes.
+This object will report them when it opens a device.;
+#X obj 9 8 cnv 15 550 30 empty empty linuxevent 20 12 1 16 -228992
+-66577 0;
+#X text 17 50 [linuxevent] outputs raw events from the Linux Event
+system. It is used for access the output of various Human Interface
+Devices \, like mice \, joysticks \, tablets \, etc.;
+#X text 62 424 Here's an example for using a joystick:;
+#X obj 366 423 linuxevent-joystick;
#X connect 4 0 6 0;
#X connect 5 0 6 0;
#X connect 6 0 3 0;
@@ -24,6 +190,8 @@
#X connect 6 3 1 0;
#X connect 7 0 6 0;
#X connect 10 0 6 0;
-#X connect 11 0 6 0;
+#X connect 12 0 10 0;
#X connect 13 0 10 0;
-#X connect 14 0 10 0;
+#X connect 14 0 6 0;
+#X connect 15 0 16 0;
+#X connect 16 0 7 0;
diff --git a/linuxevent-joystick.pd b/linuxevent-joystick.pd
new file mode 100644
index 0000000..d3d5eda
--- /dev/null
+++ b/linuxevent-joystick.pd
@@ -0,0 +1,29 @@
+#N canvas 270 365 499 362 10;
+#X obj 16 86 linuxevent /dev/input/event1;
+#X msg 35 43 start;
+#X msg 44 62 stop;
+#X obj 16 9 inlet;
+#X obj 79 116 pack f f f;
+#X obj 79 139 route 1 3;
+#X obj 137 159 print UNKNOWN_JOYSTICK_EVENT_TYPE;
+#X text 148 139 types (1=buttons 3=abs axes);
+#X obj 108 187 route 0 1 6 7;
+#X obj 194 209 print UNKNOWN_JOYSTICK_EVENT_CODE;
+#X obj 151 249 print THROTTLE;
+#X text 204 190 codes (0=X 1=Y 6=throttle 7=rudder);
+#X obj 172 229 print RUDDER;
+#X obj 129 269 print Y-AXIS;
+#X obj 108 290 print X-AXIS;
+#X connect 0 1 4 0;
+#X connect 0 2 4 1;
+#X connect 0 3 4 2;
+#X connect 1 0 0 0;
+#X connect 2 0 0 0;
+#X connect 3 0 0 0;
+#X connect 4 0 5 0;
+#X connect 5 1 8 0;
+#X connect 5 2 6 0;
+#X connect 8 0 14 0;
+#X connect 8 1 13 0;
+#X connect 8 2 10 0;
+#X connect 8 3 12 0;
diff --git a/linuxevent.c b/linuxevent.c
index c562243..c9901c9 100644
--- a/linuxevent.c
+++ b/linuxevent.c
@@ -3,7 +3,7 @@
#define LINUXEVENT_DEVICE "/dev/input/event0"
#define LINUXEVENT_OUTLETS 4
-static char *version = "$Revision: 1.2 $";
+static char *version = "$Revision: 1.3 $";
/*------------------------------------------------------------------------------
* CLASS DEF
@@ -14,6 +14,7 @@ typedef struct _linuxevent {
t_object x_obj;
t_int x_fd;
t_symbol* x_devname;
+ t_clock *x_clock;
int read_ok;
int started;
struct input_event x_input_event;
@@ -21,6 +22,7 @@ typedef struct _linuxevent {
t_outlet *x_input_event_type_outlet;
t_outlet *x_input_event_code_outlet;
t_outlet *x_input_event_value_outlet;
+ int x_delaytime;
}t_linuxevent;
/*------------------------------------------------------------------------------
@@ -30,13 +32,14 @@ typedef struct _linuxevent {
//DONE
static int linuxevent_close(t_linuxevent *x)
{
- DEBUG(post("linuxevent_close");)
-
- if (x->x_fd <0) return 0;
-
- close (x->x_fd);
-
- return 1;
+ DEBUG(post("linuxevent_close");)
+
+ if (x->x_fd <0) {
+ return 0;
+ } else {
+ close (x->x_fd);
+ return 1;
+ }
}
//DONE
@@ -157,66 +160,70 @@ static int linuxevent_open(t_linuxevent *x,t_symbol* s)
static int linuxevent_read(t_linuxevent *x,int fd)
{
- int readBytes;
- int axis_num = 0;
- t_float button_num = 0;
+// int readBytes;
if (x->x_fd < 0) return 0;
- if (x->read_ok) {
- readBytes = read(x->x_fd, &(x->x_input_event), sizeof(struct input_event));
- DEBUG(post("reading %d",readBytes);)
- if ( readBytes < 0 ) {
- post("linuxevent: read failed");
- x->read_ok = 0;
- return 0;
- }
+
+ 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); */
}
- /* input_event.time is a timeval struct from <sys/time.h> */
- /* outlet_float (x->x_input_event_time_outlet, x->x_input_event.time); */
- outlet_float (x->x_input_event_type_outlet, x->x_input_event.type);
- outlet_float (x->x_input_event_code_outlet, x->x_input_event.code);
- outlet_float (x->x_input_event_value_outlet, (int)x->x_input_event.value);
+ if (x->started) {
+ clock_delay(x->x_clock, x->x_delaytime);
+ }
+
return 1;
}
/* Actions */
-static void linuxevent_bang(t_linuxevent* x)
-{
- DEBUG(post("linuxevent_bang");)
-
-}
-
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_delaytime = (int)f;
+ } else {
+ x->x_delaytime = 5;
+ }
+}
+
// DONE
void linuxevent_start(t_linuxevent* x)
{
- DEBUG(post("linuxevent_start");)
-
- if (x->x_fd >= 0 && !x->started) {
- sys_addpollfn(x->x_fd, (t_fdpollfn)linuxevent_read, x);
- post("linuxevent: start");
- x->started = 1;
- }
+ DEBUG(post("linuxevent_start"););
+ post("clock delay: %d",x->x_delaytime);
+
+ if (x->x_fd >= 0 && !x->started) {
+ clock_delay(x->x_clock, 2);
+ post("linuxevent: start");
+ x->started = 1;
+ }
}
// DONE
void linuxevent_stop(t_linuxevent* x)
{
- DEBUG(post("linuxevent_stop");)
-
- if (x->x_fd >= 0 && x->started) {
- sys_rmpollfn(x->x_fd);
- post("linuxevent: stop");
- x->started = 0;
- }
+ DEBUG(post("linuxevent_stop"););
+
+ post("clock delay: %d",x->x_delaytime);
+
+ if (x->x_fd >= 0 && x->started) {
+ clock_unset(x->x_clock);
+ post("linuxevent: stop");
+ x->started = 0;
+ }
}
/* Misc setup functions */
@@ -226,10 +233,10 @@ static void linuxevent_free(t_linuxevent* x)
{
DEBUG(post("linuxevent_free");)
- if (x->x_fd < 0) return;
-
+ if (x->x_fd < 0) return;
+
linuxevent_stop(x);
-
+ clock_free(x->x_clock);
close (x->x_fd);
}
@@ -239,11 +246,16 @@ static void *linuxevent_new(t_symbol *s)
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);
+
/* init vars */
x->x_fd = -1;
x->read_ok = 1;
x->started = 0;
+ x->x_delaytime = 5;
+
+ 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);
@@ -272,13 +284,14 @@ void linuxevent_setup(void)
/* add inlet datatype methods */
class_addfloat(linuxevent_class,(t_method) linuxevent_float);
- class_addbang(linuxevent_class,(t_method) linuxevent_bang);
+ class_addbang(linuxevent_class,(t_method) linuxevent_read);
/* add inlet message methods */
class_addmethod(linuxevent_class, (t_method) linuxevent_open,gensym("open"),A_DEFSYM);
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_stop,gensym("stop"),0);
+ class_addmethod(linuxevent_class,(t_method) linuxevent_delay,gensym("delay"),A_FLOAT,0);
}