From be5bf77657bdf9a55ba2ab3ef0ddd1be90038458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Wed, 2 Jul 2008 11:31:27 +0000 Subject: cleaned up a bit svn path=/trunk/externals/iem/dmx512/; revision=10131 --- dmx512/src/dmxout.c | 37 ++++++++++++++----------------------- 1 file 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 #include +#include 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; ix_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; i255.) { @@ -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) -- cgit v1.2.1