[PD-cvs] SF.net SVN: pure-data: [10056] trunk/externals/iem/dmx512/src/dmxout.c

zmoelnig at users.sourceforge.net zmoelnig at users.sourceforge.net
Fri Jun 20 17:33:18 CEST 2008


Revision: 10056
          http://pure-data.svn.sourceforge.net/pure-data/?rev=10056&view=rev
Author:   zmoelnig
Date:     2008-06-20 08:33:18 -0700 (Fri, 20 Jun 2008)

Log Message:
-----------
hmm, fixed a problem; seems to work now with an 
openDMX-USB

Modified Paths:
--------------
    trunk/externals/iem/dmx512/src/dmxout.c

Modified: trunk/externals/iem/dmx512/src/dmxout.c
===================================================================
--- trunk/externals/iem/dmx512/src/dmxout.c	2008-06-20 12:06:44 UTC (rev 10055)
+++ trunk/externals/iem/dmx512/src/dmxout.c	2008-06-20 15:33:18 UTC (rev 10056)
@@ -33,8 +33,16 @@
   t_float  x_port;
   int  x_portrange;
 
+  dmx_t x_values[512];
+
 } t_dmxout;
 
+static void dmxout_clearbuf(t_dmxout*x)
+{
+  int i=0;
+  for(i=0; i<512; i++) x->x_values[i]=0;
+}
+
 static void dmxout_close(t_dmxout*x)
 {
   if(x->x_device>=0) {
@@ -49,7 +57,7 @@
   int argc=2;
   const char *args[2] = {"--dmx", s_devname->s_name};
   const char**argv=args;
-  char*devname="";
+  const char*devname="";
   int fd;
 
   if(s_devname && s_devname->s_name)
@@ -57,8 +65,14 @@
 
   //  strncpy(args[0], "--dmx", MAXPDSTRING);
   //  strncpy(args[1], devname, MAXPDSTRING);
+  devname=DMXdev(&argc, argv);
+  if(!devname){
+  	pd_error(x, "couldn't find DMX device");
+	return;
+  }
+  verbose(1, "[dmxout] opening %s", devname);
 
-  fd = open (DMXdev(&argc, argv), O_WRONLY);
+  fd = open (devname, O_WRONLY);
 
   if(fd!=-1) {
     dmxout_close(x);
@@ -66,21 +80,29 @@
   }
 }
 
-static void dmxout_doout(t_dmxout*x, short baseport, short portrange, dmx_t*values)
+static void dmxout_doout(t_dmxout*x, dmx_t values[512])
 {
+  int i;
   if(x->x_device<=0) {
     pd_error(x, "no DMX universe found");
     return;
   }
+#if 0
+  for(i=0; i<512; i++) {
+    post("dmx[%d]=%03d", i, values[i]);
+  }
+  endpost();
+#endif
 
-  lseek (x->x_device, sizeof(dmx_t)*baseport, SEEK_SET);  /* set to the current channel */
-  write (x->x_device, values, portrange*sizeof(dmx_t)); /* write the channel */
+  lseek (x->x_device, 0, SEEK_SET);  /* set to the current channel */
+  write (x->x_device, values, 512); /* write the channel */
 }
 
 static void dmxout_doout1(t_dmxout*x, short port, unsigned char value)
 {
-  dmx_t buffer[1] = {value};
-  dmxout_doout(x, port, 1, buffer);
+  dmxout_clearbuf(x);
+  x->x_values[port]=value;
+  dmxout_doout(x, x->x_values);
 }
 
 
@@ -103,11 +125,18 @@
 static void dmxout_list(t_dmxout*x, t_symbol*s, int argc, t_atom*argv)
 {
   int count=(argc<x->x_portrange)?argc:x->x_portrange;
-  dmx_t*buffer=(dmx_t*)getbytes(count*sizeof(dmx_t));
   int i=0;
-
   int errors=0;
 
+  int port=x->x_port;
+  if((port+count)>=512) {
+    if(count>512)count=512;
+    port=512-count;
+  }
+
+  dmxout_clearbuf(x);
+
+
   for(i=0; i<count; i++) {
     t_float f=atom_getfloat(argv+i);
     if(f<0. || f>255.) {
@@ -115,13 +144,13 @@
       if(f<0.)f=0.;
       if(f>255)f=255;
     }
-    buffer[i]=(unsigned char)f;
+    x->x_values[port+i]=(unsigned char)f;
   }
   if(errors) {
     pd_error(x, "%d valu%s out of bound [0..255]", errors, (1==errors)?"e":"es");
   }
 
-  dmxout_doout(x, x->x_port, count, buffer);
+  dmxout_doout(x, x->x_values);
 }
 
 static void dmxout_port(t_dmxout*x, t_float f_baseport, t_floatarg f_portrange)


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Pd-cvs mailing list