From c095709343b24661506a5a850bac5cf142748a01 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 28 Jun 2008 16:08:02 +0000 Subject: first somewhat 'working' version of the objectclass to get data from the Sony SIXAXIS accelerometer svn path=/trunk/externals/io/; revision=10115 --- sixaxis/sixaxis-help.pd | 156 ++++++++++++++++++++++ sixaxis/sixaxis.c | 345 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 501 insertions(+) create mode 100644 sixaxis/sixaxis-help.pd create mode 100644 sixaxis/sixaxis.c (limited to 'sixaxis') diff --git a/sixaxis/sixaxis-help.pd b/sixaxis/sixaxis-help.pd new file mode 100644 index 0000000..7b36070 --- /dev/null +++ b/sixaxis/sixaxis-help.pd @@ -0,0 +1,156 @@ +#N canvas 292 101 633 730 10; +#X obj 129 267 sixaxis /dev/hidraw0; +#X obj 107 178 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 18 178 metro 20; +#X obj 18 156 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 38 156 stop; +#X obj 107 129 key; +#X obj 2 2 cnv 15 550 25 empty empty sixaxis 20 12 1 16 -228992 -66577 +0; +#X text 10 44 [sixaxis] 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 26 105 bang to get an update when polling is stopped.; +#X obj 107 149 sel 98; +#X text 153 149 <- (type 'b' for a bang); +#X obj 182 372 pddp/print; +#N canvas 743 25 411 235 see 0; +#N canvas 108 318 543 264 route 0; +#X obj 27 14 inlet; +#X obj 72 226 outlet; +#X obj 19 226 outlet; +#X obj 172 226 outlet; +#X obj 222 204 symbol; +#X obj 222 226 outlet; +#X obj 272 204 symbol; +#X obj 272 226 outlet; +#X obj 322 204 symbol; +#X obj 322 226 outlet; +#X obj 372 204 symbol; +#X obj 372 226 outlet; +#X obj 122 225 outlet; +#X obj 422 204 symbol; +#X obj 422 226 outlet; +#X obj 472 204 symbol; +#X obj 472 226 outlet; +#X obj 26 63 route open device poll total product manufacturer transport +type vendorID productID; +#X connect 0 0 17 0; +#X connect 4 0 5 0; +#X connect 6 0 7 0; +#X connect 8 0 9 0; +#X connect 10 0 11 0; +#X connect 13 0 14 0; +#X connect 15 0 16 0; +#X connect 17 0 2 0; +#X connect 17 1 1 0; +#X connect 17 2 12 0; +#X connect 17 3 3 0; +#X connect 17 4 4 0; +#X connect 17 5 6 0; +#X connect 17 6 8 0; +#X connect 17 7 10 0; +#X connect 17 8 13 0; +#X connect 17 9 15 0; +#X restore 117 70 pd route info; +#X obj 81 96 tgl 15 0 empty empty open 0 -6 0 8 -262144 -1 -1 1 1; +#X obj 110 22 inlet; +#X obj 123 43 print info; +#X symbolatom 304 93 0 0 0 0 productID - -; +#X symbolatom 304 112 0 0 0 0 vendorID - -; +#X symbolatom 304 151 0 0 0 0 transport - -; +#X symbolatom 304 171 0 0 0 0 manufacturer - -; +#X symbolatom 186 192 0 0 0 0 product - -; +#X floatatom 97 140 5 0 0 0 device - -; +#X floatatom 97 162 5 0 0 0 poll - -; +#X symbolatom 304 131 0 0 0 0 type - -; +#X floatatom 97 182 5 0 0 0 total - -; +#X connect 0 0 1 0; +#X connect 0 1 9 0; +#X connect 0 2 10 0; +#X connect 0 3 12 0; +#X connect 0 4 8 0; +#X connect 0 5 7 0; +#X connect 0 6 6 0; +#X connect 0 7 11 0; +#X connect 0 8 5 0; +#X connect 0 9 4 0; +#X connect 2 0 0 0; +#X connect 2 0 3 0; +#X restore 246 297 pd see device info; +#X obj 130 210 tgl 30 0 empty empty empty 17 7 0 10 -4034 -1 -1 0 1 +; +#X msg 179 222 info; +#X obj 181 348 spigot; +#X obj 216 328 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 +1; +#X obj 249 334 spigot; +#X obj 282 327 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 +1; +#X obj 250 354 print RAW; +#X obj 61 416 route position speed acceleration accelerometer; +#X obj 341 445 print WARNING_UNSUPPORTED_MESSAGES; +#X obj 43 528 unpack 0 0 0; +#X floatatom 31 549 7 0 0 0 - - -; +#X floatatom 77 549 7 0 0 0 - - -; +#X floatatom 123 549 7 0 0 0 - - -; +#X obj 77 484 unpack 0 0 0; +#X floatatom 65 505 7 0 0 0 - - -; +#X floatatom 111 505 7 0 0 0 - - -; +#X floatatom 157 505 7 0 0 0 - - -; +#X obj 197 461 unpack 0 0 0; +#X floatatom 185 482 7 0 0 0 - - -; +#X floatatom 231 482 7 0 0 0 - - -; +#X floatatom 277 482 7 0 0 0 - - -; +#X obj 252 513 track_min; +#X obj 325 517 track_max; +#X floatatom 324 539 9 0 0 0 - - -; +#X floatatom 252 539 9 0 0 0 - - -; +#X obj 22 573 track_min; +#X obj 95 577 track_max; +#X floatatom 94 599 9 0 0 0 - - -; +#X floatatom 22 599 9 0 0 0 - - -; +#X msg 176 551 bang; +#X msg 232 217 close; +#X connect 0 0 15 0; +#X connect 0 0 17 0; +#X connect 0 0 20 0; +#X connect 0 1 12 0; +#X connect 1 0 0 0; +#X connect 2 0 0 0; +#X connect 3 0 2 0; +#X connect 4 0 2 0; +#X connect 5 0 9 0; +#X connect 9 0 1 0; +#X connect 13 0 0 0; +#X connect 14 0 0 0; +#X connect 15 0 11 0; +#X connect 16 0 15 1; +#X connect 17 0 19 0; +#X connect 18 0 17 1; +#X connect 20 0 22 0; +#X connect 20 1 26 0; +#X connect 20 2 30 0; +#X connect 20 4 21 0; +#X connect 22 0 23 0; +#X connect 22 1 24 0; +#X connect 22 1 39 0; +#X connect 22 1 38 0; +#X connect 22 2 25 0; +#X connect 26 0 27 0; +#X connect 26 1 28 0; +#X connect 26 2 29 0; +#X connect 30 0 31 0; +#X connect 30 1 32 0; +#X connect 30 1 35 0; +#X connect 30 1 34 0; +#X connect 30 2 33 0; +#X connect 34 0 37 0; +#X connect 35 0 36 0; +#X connect 38 0 41 0; +#X connect 39 0 40 0; +#X connect 42 0 39 2; +#X connect 42 0 38 2; +#X connect 43 0 0 0; diff --git a/sixaxis/sixaxis.c b/sixaxis/sixaxis.c new file mode 100644 index 0000000..b9c2232 --- /dev/null +++ b/sixaxis/sixaxis.c @@ -0,0 +1,345 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "m_pd.h" + +#define DEBUG(x) +//#define DEBUG(x) x + +#define DEFAULT_DELAY 10 +#define SIXAXIS_DEVICE "/dev/hidraw0" + +static char *version = "$Revision: 1.1 $"; + +/*------------------------------------------------------------------------------ + * GLOBAL DECLARATIONS + */ + +/* hidraw data format */ +struct sixaxis_state { + double time; + int ax, ay, az; // Raw accelerometer data + double ddx, ddy, ddz; // Acceleration + double dx, dy, dz; // Speed + double x, y, z; // Position +}; + +/* pre-generated symbols */ +static t_symbol *ps_open, *ps_device, *ps_poll, *ps_total, *ps_range; +static t_symbol *ps_accelerometer, *ps_acceleration, *ps_speed, *ps_position; + +/* mostly for status querying */ +static unsigned short device_count; + +/* previous state for calculating position, speed, acceleration */ +static struct sixaxis_state prev; + +/*------------------------------------------------------------------------------ + * CLASS DEF + */ +static t_class *sixaxis_class; + +typedef struct _sixaxis { + t_object x_obj; + t_int x_fd; + t_symbol *x_devname; + t_clock *x_clock; + short x_device_number; + short x_instance; + t_int x_device_open; + int x_read_ok; + int x_started; + int x_delay; + unsigned char buf[128]; + struct sixaxis_state x_sixaxis_state; + t_atom x_output_atoms[3]; + t_outlet *x_data_outlet; + t_outlet *x_status_outlet; +} t_sixaxis; + + + +/*------------------------------------------------------------------------------ + * SUPPORT FUNCTIONS + */ + +static void output_status(t_sixaxis *x, t_symbol *selector, t_float output_value) +{ + t_atom *output_atom = (t_atom *)getbytes(sizeof(t_atom)); + SETFLOAT(output_atom, output_value); + outlet_anything( x->x_status_outlet, selector, 1, output_atom); + freebytes(output_atom,sizeof(t_atom)); +} + +static void output_open_status(t_sixaxis *x) +{ + output_status(x, ps_open, x->x_device_open); +} + +static void output_device_number(t_sixaxis *x) +{ + output_status(x, ps_device, x->x_device_number); +} + +static void output_poll_time(t_sixaxis *x) +{ + output_status(x, ps_poll, x->x_delay); +} + +static void output_device_count(t_sixaxis *x) +{ + output_status(x, ps_total, device_count); +} + +/*------------------------------------------------------------------------------ + * CLASS METHODS + */ + +void sixaxis_stop(t_sixaxis* x) +{ + DEBUG(post("sixaxis_stop");); + + if (x->x_fd >= 0 && x->x_started) { + clock_unset(x->x_clock); + post("sixaxis: polling stopped"); + x->x_started = 0; + } +} + +static void sixaxis_close(t_sixaxis *x) +{ + DEBUG(post("sixaxis_close");); + +/* just to be safe, stop it first */ + sixaxis_stop(x); + + if(x->x_fd < 0) + return; + close(x->x_fd); + post("[sixaxis] closed %s",x->x_devname->s_name); + x->x_device_open = 0; + output_open_status(x); +} + +static int sixaxis_open(t_sixaxis *x, t_symbol *s) +{ + DEBUG(post("sixaxis_open");); + + sixaxis_close(x); + + /* set obj device name to parameter + * otherwise set to default + */ + if (s != &s_) + x->x_devname = s; + + /* 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 > -1 ) { + x->x_device_open = 1; + output_open_status(x); + return 1; + } else { + pd_error(x, "[sixaxis] open %s failed", x->x_devname->s_name); + x->x_fd = -1; + x->x_device_open = 0; + output_open_status(x); + } + } + return 0; +} + +static void sixaxis_read(t_sixaxis *x) +{ + if(x->x_fd < 0) + return; + if(read(x->x_fd, &(x->buf), sizeof(x->buf)) > -1) { +// if ( nr < 0 ) { perror("read(stdin)"); exit(1); } +// if ( nr != 48 ) { fprintf(stderr, "Unsupported report\n"); exit(1); } + + struct timeval tv; + if ( gettimeofday(&tv, NULL) ) { + perror("gettimeofday"); + return; + } + x->x_sixaxis_state.time = tv.tv_sec + tv.tv_usec*1e-6; + x->x_sixaxis_state.ax = x->buf[40]<<8 | x->buf[41]; + x->x_sixaxis_state.ay = x->buf[42]<<8 | x->buf[43]; + x->x_sixaxis_state.az = x->buf[44]<<8 | x->buf[45]; + if ( ! prev.time ) { + prev.time = x->x_sixaxis_state.time; + prev.ax = x->x_sixaxis_state.ax; + prev.ay = x->x_sixaxis_state.ay; + prev.az = x->x_sixaxis_state.az; + } + double dt = x->x_sixaxis_state.time - prev.time; + double rc_dd = 2.0; // Time constant for highpass filter on acceleration + double alpha_dd = rc_dd / (rc_dd+dt); + x->x_sixaxis_state.ddx = alpha_dd*(prev.ddx + (x->x_sixaxis_state.ax-prev.ax)*0.01); + x->x_sixaxis_state.ddy = alpha_dd*(prev.ddy + (x->x_sixaxis_state.ay-prev.ay)*0.01); + x->x_sixaxis_state.ddz = alpha_dd*(prev.ddz - (x->x_sixaxis_state.az-prev.az)*0.01); + double rc_d = 2.0; // Time constant for highpass filter on speed + double alpha_d = rc_d / (rc_d+dt); + x->x_sixaxis_state.dx = alpha_d*(prev.dx + x->x_sixaxis_state.ddx*dt); + x->x_sixaxis_state.dy = alpha_d*(prev.dy + x->x_sixaxis_state.ddy*dt); + x->x_sixaxis_state.dz = alpha_d*(prev.dz + x->x_sixaxis_state.ddz*dt); + double rc = 1.0; // Time constant for highpass filter on position + double alpha = rc / (rc+dt); + x->x_sixaxis_state.x = alpha*(prev.x + x->x_sixaxis_state.dx*dt); + x->x_sixaxis_state.y = alpha*(prev.y + x->x_sixaxis_state.dy*dt); + x->x_sixaxis_state.z = alpha*(prev.z + x->x_sixaxis_state.dz*dt); + /* raw accelerometer data */ + SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.ax); + SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.ay); + SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.az); + outlet_anything(x->x_data_outlet, ps_accelerometer, 3, x->x_output_atoms); + /* acceleration data */ + SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.ddx); + SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.ddy); + SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.ddz); + outlet_anything(x->x_data_outlet, ps_acceleration, 3, x->x_output_atoms); + /* speed data */ + SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.dx); + SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.dy); + SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.dz); + outlet_anything(x->x_data_outlet, ps_speed, 3, x->x_output_atoms); + /* position data */ + SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.x); + SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.y); + SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.z); + outlet_anything(x->x_data_outlet, ps_position, 3, x->x_output_atoms); + } + if(x->x_started) { + clock_delay(x->x_clock, x->x_delay); + } +} +// double ddx, ddy, ddz; // Acceleration +// double dx, dy, dz; // Speed +// double x, y, z; // Position + +/* Actions */ + +static void sixaxis_info(t_sixaxis *x) +{ + output_open_status(x); + output_device_number(x); + output_device_count(x); + output_poll_time(x); +// TODO output ranges for sixaxis +// output_element_ranges(x); +} + +void sixaxis_start(t_sixaxis* x) +{ + DEBUG(post("sixaxis_start");); + + if (x->x_fd > -1 && !x->x_started) { + clock_delay(x->x_clock, DEFAULT_DELAY); + post("sixaxis: polling started"); + x->x_started = 1; + } else { + post("You need to set a input device (i.e /dev/input/event0)"); + } + + if(x->x_device_number > -1) + { + if(!x->x_device_open) + { + sixaxis_open(x,x->x_devname); + } + if(!x->x_started) + { + clock_delay(x->x_clock, x->x_delay); + x->x_started = 1; + } + } + +} + +static void sixaxis_float(t_sixaxis* x, t_floatarg f) +{ + DEBUG(post("sixaxis_float");); + + if (f > 0) + sixaxis_start(x); + else + sixaxis_stop(x); +} + +/* setup functions */ +static void sixaxis_free(t_sixaxis* x) +{ + DEBUG(post("sixaxis_free");); + + if (x->x_fd < 0) return; + + sixaxis_stop(x); + clock_free(x->x_clock); + close(x->x_fd); +} + +static void *sixaxis_new(t_symbol *s) +{ + t_sixaxis *x = (t_sixaxis *)pd_new(sixaxis_class); + + DEBUG(post("sixaxis_new");); + + post("[sixaxis] %s, written by Hans-Christoph Steiner ",version); + + /* init vars */ + x->x_fd = -1; + x->x_read_ok = 1; + x->x_started = 0; + x->x_delay = DEFAULT_DELAY; + x->x_devname = gensym(SIXAXIS_DEVICE); + + x->x_clock = clock_new(x, (t_method)sixaxis_read); + + /* create standard hidio-style outlets */ + x->x_data_outlet = outlet_new(&x->x_obj, 0); + x->x_status_outlet = outlet_new(&x->x_obj, 0); + + /* set to the value from the object argument, if that exists */ + if (s != &s_) + x->x_devname = s; + + return (x); +} + +void sixaxis_setup(void) +{ + DEBUG(post("sixaxis_setup");); + sixaxis_class = class_new(gensym("sixaxis"), + (t_newmethod)sixaxis_new, + (t_method)sixaxis_free, + sizeof(t_sixaxis), 0, A_DEFSYM, 0); + + /* add inlet datatype methods */ + class_addfloat(sixaxis_class,(t_method) sixaxis_float); + class_addbang(sixaxis_class,(t_method) sixaxis_read); + + /* add inlet message methods */ + class_addmethod(sixaxis_class,(t_method) sixaxis_open,gensym("open"),A_DEFFLOAT,0); + class_addmethod(sixaxis_class,(t_method) sixaxis_close,gensym("close"),0); + class_addmethod(sixaxis_class,(t_method) sixaxis_info,gensym("info"),0); + + /* pre-generate often used symbols */ + ps_open = gensym("open"); + ps_device = gensym("device"); + ps_poll = gensym("poll"); + ps_total = gensym("total"); + ps_range = gensym("range"); + ps_accelerometer = gensym("accelerometer"); + ps_acceleration = gensym("acceleration"); + ps_speed = gensym("speed"); + ps_position = gensym("position"); +} + -- cgit v1.2.1 From 8d8c3b56bd45eb78a3d70b61d00d0e14290e6178 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 28 Jun 2008 21:32:30 +0000 Subject: - the sixaxis external now builds with Pd-extended, and outputs the raw accelerometer data - for the rest of the data, use [hid] or [hidio] they happily coexist svn path=/trunk/externals/io/; revision=10116 --- sixaxis/Makefile | 17 +++ sixaxis/sixaxis-help.pd | 193 ++++++++++++++------------------- sixaxis/sixaxis.c | 279 ++++++++++++++++++++++++++++++------------------ 3 files changed, 272 insertions(+), 217 deletions(-) create mode 100644 sixaxis/Makefile (limited to 'sixaxis') diff --git a/sixaxis/Makefile b/sixaxis/Makefile new file mode 100644 index 0000000..2b8688b --- /dev/null +++ b/sixaxis/Makefile @@ -0,0 +1,17 @@ +TARGET := $(shell pwd | sed 's|.*/\(.*\)$$|\1|') +EXTERNALS_ROOT := $(shell pwd | sed 's|^\(/.*externals\).*|\1|') + +default: + make -C $(EXTERNALS_ROOT) $(TARGET) + +install: + make -C $(EXTERNALS_ROOT) $(TARGET)_install + +clean: + make -C $(EXTERNALS_ROOT) $(TARGET)_clean + +test_locations: + make -C $(EXTERNALS_ROOT) test_locations + +etags: + etags *.[ch] ~/code/pure-data/trunk/pd/src/*.[ch] /usr/include/*.h /usr/include/sys/*.h diff --git a/sixaxis/sixaxis-help.pd b/sixaxis/sixaxis-help.pd index 7b36070..b5fae4f 100644 --- a/sixaxis/sixaxis-help.pd +++ b/sixaxis/sixaxis-help.pd @@ -1,22 +1,7 @@ -#N canvas 292 101 633 730 10; -#X obj 129 267 sixaxis /dev/hidraw0; -#X obj 107 178 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 --1; -#X obj 18 178 metro 20; -#X obj 18 156 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 --1; -#X msg 38 156 stop; -#X obj 107 129 key; -#X obj 2 2 cnv 15 550 25 empty empty sixaxis 20 12 1 16 -228992 -66577 +#N canvas 197 95 565 482 10; +#X obj -71 5 cnv 15 550 25 empty empty sixaxis 20 12 1 16 -228992 -66577 0; -#X text 10 44 [sixaxis] 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 26 105 bang to get an update when polling is stopped.; -#X obj 107 149 sel 98; -#X text 153 149 <- (type 'b' for a bang); -#X obj 182 372 pddp/print; -#N canvas 743 25 411 235 see 0; +#N canvas 746 51 411 235 see 0; #N canvas 108 318 543 264 route 0; #X obj 27 14 inlet; #X obj 72 226 outlet; @@ -55,102 +40,88 @@ type vendorID productID; #X connect 17 8 13 0; #X connect 17 9 15 0; #X restore 117 70 pd route info; -#X obj 81 96 tgl 15 0 empty empty open 0 -6 0 8 -262144 -1 -1 1 1; +#X obj 221 96 tgl 15 0 empty empty open 0 -6 0 8 -262144 -1 -1 1 1 +; #X obj 110 22 inlet; #X obj 123 43 print info; -#X symbolatom 304 93 0 0 0 0 productID - -; -#X symbolatom 304 112 0 0 0 0 vendorID - -; -#X symbolatom 304 151 0 0 0 0 transport - -; -#X symbolatom 304 171 0 0 0 0 manufacturer - -; -#X symbolatom 186 192 0 0 0 0 product - -; -#X floatatom 97 140 5 0 0 0 device - -; -#X floatatom 97 162 5 0 0 0 poll - -; -#X symbolatom 304 131 0 0 0 0 type - -; -#X floatatom 97 182 5 0 0 0 total - -; +#X floatatom 156 140 5 0 0 0 device - -; +#X floatatom 156 162 5 0 0 0 poll - -; +#X floatatom 156 182 5 0 0 0 total - -; #X connect 0 0 1 0; -#X connect 0 1 9 0; -#X connect 0 2 10 0; -#X connect 0 3 12 0; -#X connect 0 4 8 0; -#X connect 0 5 7 0; -#X connect 0 6 6 0; -#X connect 0 7 11 0; -#X connect 0 8 5 0; -#X connect 0 9 4 0; +#X connect 0 1 4 0; +#X connect 0 2 5 0; +#X connect 0 3 6 0; #X connect 2 0 0 0; #X connect 2 0 3 0; -#X restore 246 297 pd see device info; -#X obj 130 210 tgl 30 0 empty empty empty 17 7 0 10 -4034 -1 -1 0 1 +#X restore 82 239 pd see device info; +#X obj -7 181 tgl 30 0 empty empty empty 17 7 0 10 -4034 -1 -1 0 1 ; -#X msg 179 222 info; -#X obj 181 348 spigot; -#X obj 216 328 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 -1; -#X obj 249 334 spigot; -#X obj 282 327 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 -1; -#X obj 250 354 print RAW; -#X obj 61 416 route position speed acceleration accelerometer; -#X obj 341 445 print WARNING_UNSUPPORTED_MESSAGES; -#X obj 43 528 unpack 0 0 0; -#X floatatom 31 549 7 0 0 0 - - -; -#X floatatom 77 549 7 0 0 0 - - -; -#X floatatom 123 549 7 0 0 0 - - -; -#X obj 77 484 unpack 0 0 0; -#X floatatom 65 505 7 0 0 0 - - -; -#X floatatom 111 505 7 0 0 0 - - -; -#X floatatom 157 505 7 0 0 0 - - -; -#X obj 197 461 unpack 0 0 0; -#X floatatom 185 482 7 0 0 0 - - -; -#X floatatom 231 482 7 0 0 0 - - -; -#X floatatom 277 482 7 0 0 0 - - -; -#X obj 252 513 track_min; -#X obj 325 517 track_max; -#X floatatom 324 539 9 0 0 0 - - -; -#X floatatom 252 539 9 0 0 0 - - -; -#X obj 22 573 track_min; -#X obj 95 577 track_max; -#X floatatom 94 599 9 0 0 0 - - -; -#X floatatom 22 599 9 0 0 0 - - -; -#X msg 176 551 bang; -#X msg 232 217 close; -#X connect 0 0 15 0; -#X connect 0 0 17 0; -#X connect 0 0 20 0; -#X connect 0 1 12 0; -#X connect 1 0 0 0; -#X connect 2 0 0 0; -#X connect 3 0 2 0; -#X connect 4 0 2 0; -#X connect 5 0 9 0; -#X connect 9 0 1 0; -#X connect 13 0 0 0; -#X connect 14 0 0 0; -#X connect 15 0 11 0; -#X connect 16 0 15 1; -#X connect 17 0 19 0; -#X connect 18 0 17 1; -#X connect 20 0 22 0; -#X connect 20 1 26 0; -#X connect 20 2 30 0; -#X connect 20 4 21 0; -#X connect 22 0 23 0; -#X connect 22 1 24 0; -#X connect 22 1 39 0; -#X connect 22 1 38 0; -#X connect 22 2 25 0; -#X connect 26 0 27 0; -#X connect 26 1 28 0; -#X connect 26 2 29 0; -#X connect 30 0 31 0; -#X connect 30 1 32 0; -#X connect 30 1 35 0; -#X connect 30 1 34 0; -#X connect 30 2 33 0; -#X connect 34 0 37 0; -#X connect 35 0 36 0; -#X connect 38 0 41 0; -#X connect 39 0 40 0; -#X connect 42 0 39 2; -#X connect 42 0 38 2; -#X connect 43 0 0 0; +#X msg 89 188 info; +#X msg 48 171 close; +#X obj -20 406 hsl 128 15 0 1 0 0 empty empty empty -2 -8 0 10 -262144 +-1 -1 5904 1; +#X obj 120 406 hsl 128 15 0 1 0 0 empty empty empty -2 -8 0 10 -262144 +-1 -1 8699 1; +#X obj 260 406 hsl 128 15 0 1 0 0 empty empty empty -2 -8 0 10 -262144 +-1 -1 5152 1; +#X obj 43 276 route accelerometer; +#X obj 43 308 route x y z; +#X msg 43 151 open 4; +#N canvas 162 133 570 420 serin 0; +#X obj 286 61 cnv 15 30 15 empty \$0-open-canvas 4 4 8 0 14 -233017 +-1 0; +#X obj 60 61 hradio 15 1 1 15 empty empty empty 0 -6 0 8 -225271 -1 +-1 4; +#X obj 60 13 inlet; +#X msg 200 202 label \$1; +#X obj 200 180 makefilename %d; +#X obj 59 108 int; +#X obj 59 337 outlet; +#X msg 201 306 set \$1 \$2; +#X obj 59 266 trigger bang anything; +#X obj 201 286 list; +#X msg 60 210 open \$1; +#X obj 200 225 send \$0-open-canvas; +#X connect 1 0 5 0; +#X connect 2 0 1 0; +#X connect 3 0 11 0; +#X connect 4 0 3 0; +#X connect 5 0 4 0; +#X connect 5 0 10 0; +#X connect 7 0 6 0; +#X connect 8 0 6 0; +#X connect 8 1 9 0; +#X connect 9 0 7 0; +#X connect 10 0 8 0; +#X coords 0 -1 1 1 257 17 1 60 60; +#X restore 43 129 pd serin; +#X obj 257 375 mapping/autoscale; +#X obj 117 375 mapping/autoscale; +#X obj -23 375 mapping/autoscale; +#X obj 43 216 sixaxis; +#N canvas 6 77 450 300 more 0; +#X text -17 56 By default \, [sixaxis] uses /dev/hidraw? for the device +name to get data from. You can override it using the [devname( message +\, like this:; +#X msg 30 154 devname /dev/my/strange/custom/hidraw; +#X restore -15 444 pd more on device names; +#X text -63 44 This objectclass supports getting accelerometer data +from the Sony SIXAXIS controller. Use this in conjuction with [hid] +to get all of the data from the SIXAXIS; +#X obj -59 83 pddp/pddplink http://www.pabr.org/sixlinux/sixlinux.en.html +-text Using the PlayStation 3 controller in Bluetooth mode with Linux +; +#X connect 2 0 15 0; +#X connect 3 0 15 0; +#X connect 4 0 15 0; +#X connect 8 0 9 0; +#X connect 9 0 14 0; +#X connect 9 1 13 0; +#X connect 9 2 12 0; +#X connect 10 0 15 0; +#X connect 11 0 10 0; +#X connect 12 0 7 0; +#X connect 13 0 6 0; +#X connect 14 0 5 0; +#X connect 15 0 8 0; +#X connect 15 1 1 0; diff --git a/sixaxis/sixaxis.c b/sixaxis/sixaxis.c index b9c2232..d110c71 100644 --- a/sixaxis/sixaxis.c +++ b/sixaxis/sixaxis.c @@ -4,15 +4,16 @@ #include #include #include +#include #include #include "m_pd.h" -#define DEBUG(x) -//#define DEBUG(x) x +//#define DEBUG(x) +#define DEBUG(x) x #define DEFAULT_DELAY 10 -#define SIXAXIS_DEVICE "/dev/hidraw0" +#define SIXAXIS_DEVNAME "/dev/hidraw" static char *version = "$Revision: 1.1 $"; @@ -30,14 +31,15 @@ struct sixaxis_state { }; /* pre-generated symbols */ -static t_symbol *ps_open, *ps_device, *ps_poll, *ps_total, *ps_range; +static t_symbol *ps_open, *ps_device, *ps_poll, *ps_total, *ps_range, *ps_devname; +static t_symbol *ps_x, *ps_y, *ps_z; static t_symbol *ps_accelerometer, *ps_acceleration, *ps_speed, *ps_position; /* mostly for status querying */ static unsigned short device_count; /* previous state for calculating position, speed, acceleration */ -static struct sixaxis_state prev; +//static struct sixaxis_state prev; /*------------------------------------------------------------------------------ * CLASS DEF @@ -47,7 +49,6 @@ static t_class *sixaxis_class; typedef struct _sixaxis { t_object x_obj; t_int x_fd; - t_symbol *x_devname; t_clock *x_clock; short x_device_number; short x_instance; @@ -96,6 +97,21 @@ static void output_device_count(t_sixaxis *x) output_status(x, ps_total, device_count); } +static short get_device_number_from_arguments(int argc, t_atom *argv) +{ + short device_number = -1; + t_symbol *first_argument; + + if(argc == 1) + { + first_argument = atom_getsymbolarg(0,argc,argv); + if(first_argument == &s_) + { // single float arg means device # + device_number = (short) atom_getfloatarg(0,argc,argv); + } + } + return device_number; +} /*------------------------------------------------------------------------------ * CLASS METHODS */ @@ -121,40 +137,90 @@ static void sixaxis_close(t_sixaxis *x) if(x->x_fd < 0) return; close(x->x_fd); - post("[sixaxis] closed %s",x->x_devname->s_name); + post("[sixaxis] closed %s%d", SIXAXIS_DEVNAME, x->x_device_number); x->x_device_open = 0; output_open_status(x); } -static int sixaxis_open(t_sixaxis *x, t_symbol *s) +static t_int sixaxis_open_device(t_sixaxis *x, short device_number) { - DEBUG(post("sixaxis_open");); + DEBUG(post("sixaxis_open_device");); - sixaxis_close(x); + char block_device[FILENAME_MAX]; - /* set obj device name to parameter - * otherwise set to default - */ - if (s != &s_) - x->x_devname = s; - - /* 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 > -1 ) { + x->x_fd = -1; + + if(device_number < 0) + { + pd_error(x,"[sixaxis] invalid device number: %d (must be 0 or greater)" + , device_number); + return EXIT_FAILURE; + } + + x->x_device_number = device_number; + snprintf(block_device, FILENAME_MAX, "%s%d", SIXAXIS_DEVNAME, x->x_device_number); + + /* 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 ) + { + pd_error(x,"[sixaxis] open %s failed",block_device); + x->x_fd = -1; + return EXIT_FAILURE; + } + post ("[sixaxis] opened device %d (%s)", x->x_device_number, block_device); + + return EXIT_SUCCESS; +} + +/* sixaxis_open behavoir + * current state action + * --------------------------------------- + * closed / same device open + * open / same device no action + * closed / different device open + * open / different device close, open + */ +static void sixaxis_open(t_sixaxis *x, t_symbol *s, int argc, t_atom *argv) +{ + DEBUG(post("sixaxis_open");); + short new_device_number = get_device_number_from_arguments(argc, argv); +// t_int started = x->x_started; // store state to restore after device is opened + + if (new_device_number < 0) + { + pd_error(x,"[sixaxis] invalid device number: %d (must be 0 or greater)", + new_device_number); + return; + } + /* check whether we have to close previous device */ + if (x->x_device_open && new_device_number != x->x_device_number) + { + sixaxis_close(x); + } + /* no device open, so open one now */ + if (!x->x_device_open) + { + if(sixaxis_open_device(x, new_device_number) == EXIT_SUCCESS) + { x->x_device_open = 1; - output_open_status(x); - return 1; - } else { - pd_error(x, "[sixaxis] open %s failed", x->x_devname->s_name); - x->x_fd = -1; - x->x_device_open = 0; - output_open_status(x); + x->x_device_number = new_device_number; + /* restore the polling state so that when I [tgl] is used to + * start/stop [sixaxis], the [tgl]'s state will continue to + * accurately reflect [sixaxis]'s state */ + post("[sixaxis] set device# to %d",new_device_number); + output_device_number(x); + } + else + { + x->x_device_number = -1; + pd_error(x, "[sixaxis] can not open device %d",new_device_number); } } - return 0; + + /* always output open result so you can test for success in Pd space */ + output_open_status(x); } static void sixaxis_read(t_sixaxis *x) @@ -165,57 +231,66 @@ static void sixaxis_read(t_sixaxis *x) // if ( nr < 0 ) { perror("read(stdin)"); exit(1); } // if ( nr != 48 ) { fprintf(stderr, "Unsupported report\n"); exit(1); } - struct timeval tv; - if ( gettimeofday(&tv, NULL) ) { - perror("gettimeofday"); - return; - } - x->x_sixaxis_state.time = tv.tv_sec + tv.tv_usec*1e-6; - x->x_sixaxis_state.ax = x->buf[40]<<8 | x->buf[41]; - x->x_sixaxis_state.ay = x->buf[42]<<8 | x->buf[43]; - x->x_sixaxis_state.az = x->buf[44]<<8 | x->buf[45]; - if ( ! prev.time ) { - prev.time = x->x_sixaxis_state.time; - prev.ax = x->x_sixaxis_state.ax; - prev.ay = x->x_sixaxis_state.ay; - prev.az = x->x_sixaxis_state.az; - } - double dt = x->x_sixaxis_state.time - prev.time; - double rc_dd = 2.0; // Time constant for highpass filter on acceleration - double alpha_dd = rc_dd / (rc_dd+dt); - x->x_sixaxis_state.ddx = alpha_dd*(prev.ddx + (x->x_sixaxis_state.ax-prev.ax)*0.01); - x->x_sixaxis_state.ddy = alpha_dd*(prev.ddy + (x->x_sixaxis_state.ay-prev.ay)*0.01); - x->x_sixaxis_state.ddz = alpha_dd*(prev.ddz - (x->x_sixaxis_state.az-prev.az)*0.01); - double rc_d = 2.0; // Time constant for highpass filter on speed - double alpha_d = rc_d / (rc_d+dt); - x->x_sixaxis_state.dx = alpha_d*(prev.dx + x->x_sixaxis_state.ddx*dt); - x->x_sixaxis_state.dy = alpha_d*(prev.dy + x->x_sixaxis_state.ddy*dt); - x->x_sixaxis_state.dz = alpha_d*(prev.dz + x->x_sixaxis_state.ddz*dt); - double rc = 1.0; // Time constant for highpass filter on position - double alpha = rc / (rc+dt); - x->x_sixaxis_state.x = alpha*(prev.x + x->x_sixaxis_state.dx*dt); - x->x_sixaxis_state.y = alpha*(prev.y + x->x_sixaxis_state.dy*dt); - x->x_sixaxis_state.z = alpha*(prev.z + x->x_sixaxis_state.dz*dt); +/* struct timeval tv; */ +/* if ( gettimeofday(&tv, NULL) ) { */ +/* perror("gettimeofday"); */ +/* return; */ +/* } */ +/* x->x_sixaxis_state.time = tv.tv_sec + tv.tv_usec*1e-6; */ +/* x->x_sixaxis_state.ax = x->buf[40]<<8 | x->buf[41]; */ +/* x->x_sixaxis_state.ay = x->buf[42]<<8 | x->buf[43]; */ +/* x->x_sixaxis_state.az = x->buf[44]<<8 | x->buf[45]; */ +/* if ( ! prev.time ) { */ +/* prev.time = x->x_sixaxis_state.time; */ +/* prev.ax = x->x_sixaxis_state.ax; */ +/* prev.ay = x->x_sixaxis_state.ay; */ +/* prev.az = x->x_sixaxis_state.az; */ +/* } */ +/* double dt = x->x_sixaxis_state.time - prev.time; */ +/* double rc_dd = 2.0; // Time constant for highpass filter on acceleration */ +/* double alpha_dd = rc_dd / (rc_dd+dt); */ +/* x->x_sixaxis_state.ddx = alpha_dd*(prev.ddx + (x->x_sixaxis_state.ax-prev.ax)*0.01); */ +/* x->x_sixaxis_state.ddy = alpha_dd*(prev.ddy + (x->x_sixaxis_state.ay-prev.ay)*0.01); */ +/* x->x_sixaxis_state.ddz = alpha_dd*(prev.ddz - (x->x_sixaxis_state.az-prev.az)*0.01); */ +/* double rc_d = 2.0; // Time constant for highpass filter on speed */ +/* double alpha_d = rc_d / (rc_d+dt); */ +/* x->x_sixaxis_state.dx = alpha_d*(prev.dx + x->x_sixaxis_state.ddx*dt); */ +/* x->x_sixaxis_state.dy = alpha_d*(prev.dy + x->x_sixaxis_state.ddy*dt); */ +/* x->x_sixaxis_state.dz = alpha_d*(prev.dz + x->x_sixaxis_state.ddz*dt); */ +/* double rc = 1.0; // Time constant for highpass filter on position */ +/* double alpha = rc / (rc+dt); */ +/* x->x_sixaxis_state.x = alpha*(prev.x + x->x_sixaxis_state.dx*dt); */ +/* x->x_sixaxis_state.y = alpha*(prev.y + x->x_sixaxis_state.dy*dt); */ +/* x->x_sixaxis_state.z = alpha*(prev.z + x->x_sixaxis_state.dz*dt); */ /* raw accelerometer data */ - SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.ax); - SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.ay); - SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.az); - outlet_anything(x->x_data_outlet, ps_accelerometer, 3, x->x_output_atoms); - /* acceleration data */ - SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.ddx); - SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.ddy); - SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.ddz); - outlet_anything(x->x_data_outlet, ps_acceleration, 3, x->x_output_atoms); - /* speed data */ - SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.dx); - SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.dy); - SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.dz); - outlet_anything(x->x_data_outlet, ps_speed, 3, x->x_output_atoms); - /* position data */ - SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.x); - SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.y); - SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.z); - outlet_anything(x->x_data_outlet, ps_position, 3, x->x_output_atoms); + SETSYMBOL(x->x_output_atoms, ps_x); + SETFLOAT(x->x_output_atoms + 1, x->buf[40]<<8 | x->buf[41]); + outlet_anything(x->x_data_outlet, ps_accelerometer, 2, x->x_output_atoms); + SETSYMBOL(x->x_output_atoms, ps_y); + SETFLOAT(x->x_output_atoms + 1, x->buf[42]<<8 | x->buf[43]); + outlet_anything(x->x_data_outlet, ps_accelerometer, 2, x->x_output_atoms); + SETSYMBOL(x->x_output_atoms, ps_z); + SETFLOAT(x->x_output_atoms + 1, x->buf[44]<<8 | x->buf[45]); + outlet_anything(x->x_data_outlet, ps_accelerometer, 2, x->x_output_atoms); +/* SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.ax); */ +/* SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.ay); */ +/* SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.az); */ +/* outlet_anything(x->x_data_outlet, ps_accelerometer, 3, x->x_output_atoms); */ +/* /\* acceleration data *\/ */ +/* SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.ddx); */ +/* SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.ddy); */ +/* SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.ddz); */ +/* outlet_anything(x->x_data_outlet, ps_acceleration, 3, x->x_output_atoms); */ +/* /\* speed data *\/ */ +/* SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.dx); */ +/* SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.dy); */ +/* SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.dz); */ +/* outlet_anything(x->x_data_outlet, ps_speed, 3, x->x_output_atoms); */ +/* /\* position data *\/ */ +/* SETFLOAT(x->x_output_atoms, x->x_sixaxis_state.x); */ +/* SETFLOAT(x->x_output_atoms + 1, x->x_sixaxis_state.y); */ +/* SETFLOAT(x->x_output_atoms + 2, x->x_sixaxis_state.z); */ +/* outlet_anything(x->x_data_outlet, ps_position, 3, x->x_output_atoms); */ } if(x->x_started) { clock_delay(x->x_clock, x->x_delay); @@ -240,28 +315,15 @@ static void sixaxis_info(t_sixaxis *x) void sixaxis_start(t_sixaxis* x) { DEBUG(post("sixaxis_start");); - + + if(!x->x_device_open) { + sixaxis_open_device(x, x->x_device_number); + } if (x->x_fd > -1 && !x->x_started) { clock_delay(x->x_clock, DEFAULT_DELAY); post("sixaxis: polling started"); x->x_started = 1; - } else { - post("You need to set a input device (i.e /dev/input/event0)"); } - - if(x->x_device_number > -1) - { - if(!x->x_device_open) - { - sixaxis_open(x,x->x_devname); - } - if(!x->x_started) - { - clock_delay(x->x_clock, x->x_delay); - x->x_started = 1; - } - } - } static void sixaxis_float(t_sixaxis* x, t_floatarg f) @@ -286,7 +348,7 @@ static void sixaxis_free(t_sixaxis* x) close(x->x_fd); } -static void *sixaxis_new(t_symbol *s) +static void *sixaxis_new(t_symbol *s, int argc, t_atom *argv) { t_sixaxis *x = (t_sixaxis *)pd_new(sixaxis_class); @@ -299,17 +361,16 @@ static void *sixaxis_new(t_symbol *s) x->x_read_ok = 1; x->x_started = 0; x->x_delay = DEFAULT_DELAY; - x->x_devname = gensym(SIXAXIS_DEVICE); + if(argc > 0) + x->x_device_number = get_device_number_from_arguments(argc, argv); + else + x->x_device_number = 0; x->x_clock = clock_new(x, (t_method)sixaxis_read); - /* create standard hidio-style outlets */ + /* create standard "io"-style outlets */ x->x_data_outlet = outlet_new(&x->x_obj, 0); x->x_status_outlet = outlet_new(&x->x_obj, 0); - - /* set to the value from the object argument, if that exists */ - if (s != &s_) - x->x_devname = s; return (x); } @@ -320,14 +381,14 @@ void sixaxis_setup(void) sixaxis_class = class_new(gensym("sixaxis"), (t_newmethod)sixaxis_new, (t_method)sixaxis_free, - sizeof(t_sixaxis), 0, A_DEFSYM, 0); + sizeof(t_sixaxis), 0, A_GIMME, 0); /* add inlet datatype methods */ class_addfloat(sixaxis_class,(t_method) sixaxis_float); class_addbang(sixaxis_class,(t_method) sixaxis_read); /* add inlet message methods */ - class_addmethod(sixaxis_class,(t_method) sixaxis_open,gensym("open"),A_DEFFLOAT,0); + class_addmethod(sixaxis_class,(t_method) sixaxis_open,gensym("open"),A_GIMME,0); class_addmethod(sixaxis_class,(t_method) sixaxis_close,gensym("close"),0); class_addmethod(sixaxis_class,(t_method) sixaxis_info,gensym("info"),0); @@ -337,7 +398,13 @@ void sixaxis_setup(void) ps_poll = gensym("poll"); ps_total = gensym("total"); ps_range = gensym("range"); + ps_devname = gensym("devname"); + ps_accelerometer = gensym("accelerometer"); + ps_x = gensym("x"); + ps_y = gensym("y"); + ps_z = gensym("z"); + ps_acceleration = gensym("acceleration"); ps_speed = gensym("speed"); ps_position = gensym("position"); -- cgit v1.2.1 From 92bf1f78a169ec5e4ac07ff631c112840b03d5dd Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 1 Apr 2010 13:52:32 +0000 Subject: setup with template Makefile svn path=/trunk/externals/io/; revision=13356 --- sixaxis/Makefile | 245 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 235 insertions(+), 10 deletions(-) (limited to 'sixaxis') diff --git a/sixaxis/Makefile b/sixaxis/Makefile index 2b8688b..5e8fe8a 100644 --- a/sixaxis/Makefile +++ b/sixaxis/Makefile @@ -1,17 +1,242 @@ -TARGET := $(shell pwd | sed 's|.*/\(.*\)$$|\1|') -EXTERNALS_ROOT := $(shell pwd | sed 's|^\(/.*externals\).*|\1|') +# To use this Makefile for your project, first put the name of your library in +# LIBRARY_NAME variable. The folder for your project should have the same name +# as your library. +LIBRARY_NAME = sixaxis +LIBRARY_VERSION = 0.1 -default: - make -C $(EXTERNALS_ROOT) $(TARGET) +# Next, add your .c source files to the SOURCES variable. The help files will +# be included automatically +SOURCES = + +# For objects that only build on certain platforms, add those to the SOURCES +# line for the right platforms. +SOURCES_android = +SOURCES_cygwin = +SOURCES_macosx = +SOURCES_iphoneos = +SOURCES_linux = sixaxis.c +SOURCES_windows = + +# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will +# be included automatically +PDOBJECTS = + +# if you want to include any other files in the source and binary tarballs, +# list them here. This can be anything from header files, READMEs, example +# patches, documentation, etc. +EXTRA_DIST = + + +#------------------------------------------------------------------------------# +# +# you shouldn't need to edit anything below here, if we did it right :) +# +#------------------------------------------------------------------------------# + +# where Pd lives +PD_PATH = ../../../pd +# where to install the library +prefix = /usr/local +libdir = $(prefix)/lib +pkglibdir = $(libdir)/pd-externals +objectsdir = $(pkglibdir) + + +INSTALL = install +INSTALL_FILE = $(INSTALL) -p -m 644 +INSTALL_DIR = $(INSTALL) -p -m 755 -d + +CFLAGS = -DPD -I$(PD_PATH)/src -Wall -W -g +LDFLAGS = +LIBS = +ALLSOURCES := $(SOURCES) $(SOURCES_android) $(SOURCES_cygwin) $(SOURCES_macosx) \ + $(SOURCES_iphoneos) $(SOURCES_linux) $(SOURCES_windows) + +UNAME := $(shell uname -s) +ifeq ($(UNAME),Darwin) + CPU := $(shell uname -p) + ifeq ($(CPU),arm) # iPhone/iPod Touch + SOURCES += $(SOURCES_macosx) + EXTENSION = pd_darwin + OS = iphoneos + IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin + CC=$(IPHONE_BASE)/gcc + CPP=$(IPHONE_BASE)/cpp + CXX=$(IPHONE_BASE)/g++ + ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk + IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6 + OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer + CFLAGS := $(IPHONE_CFLAGS) $(OPT_CFLAGS) $(CFLAGS) \ + -I/Applications/Pd-extended.app/Contents/Resources/include + LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT) + LIBS += -lc + STRIP = strip -x + DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) + DISTBINDIR=$(DISTDIR)-$(OS) + else # Mac OS X + SOURCES += $(SOURCES_macosx) + EXTENSION = pd_darwin + OS = macosx + OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast + FAT_FLAGS = -arch i386 -arch ppc -mmacosx-version-min=10.4 + CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include \ + -I/Applications/Pd-extended.app/Contents/Resources/include + LDFLAGS += $(FAT_FLAGS) -bundle -undefined dynamic_lookup -L/sw/lib + # if the 'pd' binary exists, check the linking against it to aid with stripping + LDFLAGS += $(shell test -e $(PD_PATH)/bin/pd && echo -bundle_loader $(PD_PATH)/bin/pd) + LIBS += -lc + STRIP = strip -x + DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) + DISTBINDIR=$(DISTDIR)-$(OS) + endif +endif +ifeq ($(UNAME),Linux) + SOURCES += $(SOURCES_linux) + EXTENSION = pd_linux + OS = linux + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + CFLAGS += -fPIC + LDFLAGS += -Wl,--export-dynamic -shared -fPIC + LIBS += -lc + STRIP = strip --strip-unneeded -R .note -R .comment + DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) + DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) +endif +ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME))) + SOURCES += $(SOURCES_cygwin) + EXTENSION = dll + OS = cygwin + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + CFLAGS += + LDFLAGS += -Wl,--export-dynamic -shared -L$(PD_PATH)/src + LIBS += -lc -lpd + STRIP = strip --strip-unneeded -R .note -R .comment + DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) + DISTBINDIR=$(DISTDIR)-$(OS) +endif +ifeq (MINGW,$(findstring MINGW,$(UNAME))) + SOURCES += $(SOURCES_windows) + EXTENSION = dll + OS = windows + OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer -march=i686 -mtune=pentium4 + WINDOWS_HACKS = -D'O_NONBLOCK=1' + CFLAGS += -mms-bitfields $(WINDOWS_HACKS) + LDFLAGS += -s -shared -Wl,--enable-auto-import + LIBS += -L$(PD_PATH)/src -L$(PD_PATH)/bin -L$(PD_PATH)/obj -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 + STRIP = strip --strip-unneeded -R .note -R .comment + DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) + DISTBINDIR=$(DISTDIR)-$(OS) +endif + +CFLAGS += $(OPT_CFLAGS) + + +.PHONY = install libdir_install single_install install-doc install-exec install-examples clean dist etags + +all: $(SOURCES:.c=.$(EXTENSION)) + +%.o: %.c + $(CC) $(CFLAGS) -o "$*.o" -c "$*.c" + +%.$(EXTENSION): %.o + $(CC) $(LDFLAGS) -o "$*.$(EXTENSION)" "$*.o" $(LIBS) + chmod a-x "$*.$(EXTENSION)" + +# this links everything into a single binary file +$(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o + $(CC) $(LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(LIBS) + chmod a-x $(LIBRARY_NAME).$(EXTENSION) + + +install: libdir_install + +# The meta and help files are explicitly installed to make sure they are +# actually there. Those files are not optional, then need to be there. +libdir_install: $(SOURCES:.c=.$(EXTENSION)) install-doc install-examples + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(INSTALL_FILE) $(LIBRARY_NAME)-meta.pd \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(SOURCES))" || (\ + $(INSTALL_FILE) $(SOURCES:.c=.$(EXTENSION)) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) && \ + $(STRIP) $(addprefix $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/,$(SOURCES:.c=.$(EXTENSION)))) + test -z "$(strip $(PDOBJECTS))" || \ + $(INSTALL_FILE) $(PDOBJECTS) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + +# install library linked as single binary +single_install: $(LIBRARY_NAME) install-doc install-exec + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(INSTALL_FILE) $(LIBRARY_NAME).$(EXTENSION) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(STRIP) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/$(LIBRARY_NAME).$(EXTENSION) + +install-doc: + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(SOURCES))" || \ + $(INSTALL_FILE) $(SOURCES:.c=-help.pd) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(PDOBJECTS))" || \ + $(INSTALL_FILE) $(PDOBJECTS:.pd=-help.pd) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) +# this is the only bit not really handled well... + $(INSTALL_FILE) README.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/ + +install-examples: + test ! -d examples || (\ + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples && \ + $(INSTALL_FILE) examples/*.* $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples) -install: - make -C $(EXTERNALS_ROOT) $(TARGET)_install clean: - make -C $(EXTERNALS_ROOT) $(TARGET)_clean + -rm -f -- $(SOURCES:.c=.o) + -rm -f -- $(SOURCES:.c=.$(EXTENSION)) + -rm -f -- $(LIBRARY_NAME).$(EXTENSION) + +distclean: clean + -rm -f -- $(DISTBINDIR).tar.gz + -rm -rf -- $(DISTBINDIR) + -rm -f -- $(DISTDIR).tar.gz + -rm -rf -- $(DISTDIR) + + +$(DISTBINDIR): + $(INSTALL_DIR) $(DISTBINDIR) + +libdir: all $(DISTBINDIR) + $(INSTALL_FILE) $(LIBRARY_NAME)-meta.pd $(DISTBINDIR) + $(INSTALL_FILE) $(SOURCES) $(DISTBINDIR) + $(INSTALL_FILE) $(SOURCES:.c=-help.pd) $(DISTBINDIR) + test -z "$(strip $(EXTRA_DIST))" || \ + $(INSTALL_FILE) $(EXTRA_DIST) $(DISTBINDIR) +# tar --exclude-vcs -czpf $(DISTBINDIR).tar.gz $(DISTBINDIR) + +$(DISTDIR): + $(INSTALL_DIR) $(DISTDIR) + +dist: $(DISTDIR) + $(INSTALL_FILE) Makefile $(DISTDIR) + $(INSTALL_FILE) $(LIBRARY_NAME)-meta.pd $(DISTDIR) + test -z "$(strip $(ALLSOURCES))" || \ + $(INSTALL_FILE) $(ALLSOURCES) $(DISTDIR) + test -z "$(strip $(ALLSOURCES))" || \ + $(INSTALL_FILE) $(ALLSOURCES:.c=-help.pd) $(DISTDIR) + test -z "$(strip $(PDOBJECTS))" || \ + $(INSTALL_FILE) $(PDOBJECTS) $(DISTDIR) + test -z "$(strip $(PDOBJECTS))" || \ + $(INSTALL_FILE) $(PDOBJECTS:.pd=-help.pd) $(DISTDIR) + test -z "$(strip $(EXTRA_DIST))" || \ + $(INSTALL_FILE) $(EXTRA_DIST) $(DISTDIR) + tar --exclude-vcs -czpf $(DISTDIR).tar.gz $(DISTDIR) -test_locations: - make -C $(EXTERNALS_ROOT) test_locations etags: - etags *.[ch] ~/code/pure-data/trunk/pd/src/*.[ch] /usr/include/*.h /usr/include/sys/*.h + etags *.h $(SOURCES) ../../pd/src/*.[ch] /usr/include/*.h /usr/include/*/*.h + +showpaths: + @echo "PD_PATH: $(PD_PATH)" + @echo "objectsdir: $(objectsdir)" + @echo "LIBRARY_NAME: $(LIBRARY_NAME)" + @echo "SOURCES: $(SOURCES)" + @echo "ALLSOURCES: $(ALLSOURCES)" + @echo "UNAME: $(UNAME)" + @echo "CPU: $(CPU)" + -- cgit v1.2.1 From e0d1bd98943fd82b2a1456946fda28e1c59a52f2 Mon Sep 17 00:00:00 2001 From: mescalinum Date: Wed, 15 Sep 2010 12:37:05 +0000 Subject: remove -mcpu/-mtune flags as it breaks x64 build. we should eventually figure a way of determining automatically the CPU, but 'uname -m' doesn't tell the truth svn path=/trunk/externals/io/; revision=14145 --- sixaxis/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sixaxis') diff --git a/sixaxis/Makefile b/sixaxis/Makefile index 5e8fe8a..51c9331 100644 --- a/sixaxis/Makefile +++ b/sixaxis/Makefile @@ -118,7 +118,7 @@ ifeq (MINGW,$(findstring MINGW,$(UNAME))) SOURCES += $(SOURCES_windows) EXTENSION = dll OS = windows - OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer -march=i686 -mtune=pentium4 + OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer WINDOWS_HACKS = -D'O_NONBLOCK=1' CFLAGS += -mms-bitfields $(WINDOWS_HACKS) LDFLAGS += -s -shared -Wl,--enable-auto-import -- cgit v1.2.1