diff options
author | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2008-07-02 11:31:27 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@iem.at> | 2015-10-14 15:08:24 +0200 |
commit | be5bf77657bdf9a55ba2ab3ef0ddd1be90038458 (patch) | |
tree | ec0e9b6840c85578ca4a7d2e295fdf600af0e295 | |
parent | 8a92ec9b79cf44f14ebaf517bc19e76e4d111233 (diff) |
cleaned up a bit
svn path=/trunk/externals/iem/dmx512/; revision=10131
-rw-r--r-- | dmx512/src/dmxout.c | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/dmx512/src/dmxout.c b/dmx512/src/dmxout.c index 83f5260..968110d 100644 --- a/dmx512/src/dmxout.c +++ b/dmx512/src/dmxout.c @@ -14,11 +14,11 @@ * ******************************************************/ - #include "dmx4pd.h" #include <unistd.h> #include <string.h> +#include <stdio.h> static t_class *dmxout_class; static t_class *dmxout_class2; @@ -36,7 +36,6 @@ typedef struct _dmxout int x_portrange; dmx_t x_values[NUM_DMXVALUES]; - } t_dmxout; static void dmxout_clearbuf(t_dmxout*x) @@ -62,6 +61,8 @@ static void dmxout_open(t_dmxout*x, t_symbol*s_devname) const char*devname=""; int fd; + dmxout_close(x); + if(s_devname && s_devname->s_name) devname=s_devname->s_name; @@ -75,39 +76,32 @@ static void dmxout_open(t_dmxout*x, t_symbol*s_devname) } verbose(1, "[dmxout] opening %s", devname); - fd = open (devname, O_WRONLY); + fd = open (devname, O_WRONLY | O_NONBLOCK); if(fd!=-1) { - dmxout_close(x); x->x_device=fd; + dmxout_clearbuf(x); } else { - error("failed to open DMX-device '%s'",devname); + pd_error(x, "failed to open DMX-device '%s'",devname); } } -static void dmxout_doout(t_dmxout*x, dmx_t values[NUM_DMXVALUES]) -{ - int i; - if(x->x_device<=0) { +static void dmxout_doout(t_dmxout*x) { + int device = x->x_device; + if(device<=0) { pd_error(x, "no DMX universe found"); return; } -#if 0 - for(i=0; i<NUM_DMXVALUES; i++) { - post("dmx[%d]=%03d", i, values[i]); - } - endpost(); -#endif - lseek (x->x_device, 0, SEEK_SET); /* set to the current channel */ - write (x->x_device, values, NUM_DMXVALUES); /* write the channel */ + lseek (device, 0, SEEK_SET); /* set to the current channel */ + write (device, x->x_values, NUM_DMXVALUES); /* write the channel */ } + static void dmxout_doout1(t_dmxout*x, short port, unsigned char value) { - dmxout_clearbuf(x); x->x_values[port]=value; - dmxout_doout(x, x->x_values); + dmxout_doout(x); } @@ -139,9 +133,6 @@ static void dmxout_list(t_dmxout*x, t_symbol*s, int argc, t_atom*argv) port=NUM_DMXVALUES-count; } - dmxout_clearbuf(x); - - for(i=0; i<count; i++) { t_float f=atom_getfloat(argv+i); if(f<0. || f>255.) { @@ -155,7 +146,7 @@ static void dmxout_list(t_dmxout*x, t_symbol*s, int argc, t_atom*argv) pd_error(x, "%d valu%s out of bound [0..255]", errors, (1==errors)?"e":"es"); } - dmxout_doout(x, x->x_values); + dmxout_doout(x); } static void dmxout_port(t_dmxout*x, t_float f_baseport, t_floatarg f_portrange) |