ArtNet node to drive TM1809 LED strips

Dependencies:   DMX DmxArtNet EthernetNetIf mbed

Fork of ArtNode by Suga koubou

Revision:
1:6ea5c460fdf2
Parent:
0:e3d0bc58141e
Child:
2:6d6e8afeb3b7
--- a/main.cpp	Thu Oct 06 04:13:35 2011 +0000
+++ b/main.cpp	Tue Sep 24 20:41:05 2013 +0000
@@ -31,6 +31,8 @@
 DMX dmx2(p28, p27);
 Serial pc(USBTX, USBRX);
 
+SPI spi(p11, p12, p13); // mosi, miso, sclk
+
 void no_memory () {
     printf("panic: can't allocate to memory!\r\n");
     exit(-1);
@@ -43,11 +45,63 @@
    art.Done();
 }
 
+void PutLed(long GRB)
+{    
+    int SpiPack = 0;
+    int c = 0;
+    int i;
+    for(i = 0; i < 24; i++)
+    {
+        if(GRB & ((long)(1) << (23-i)))
+            SpiPack += 6;
+           else
+            SpiPack += 4;
+        
+        if(c++ >= 3)
+        {
+        
+            // First don't write to the FIFO buffer if it is full
+    while (!(LPC_SSP0->SR & 2))   // While TNF-Bit = 0 (FIFO full)...
+        ;                           // Wait
+    LPC_SSP0->DR = SpiPack;            // Write to FIFO buffer
+           
+           
+       //     spi.write(SpiPack);
+            SpiPack = 0;
+            c = 0;  
+        }
+        
+        SpiPack = SpiPack << 3;
+    
+    }
+}
+
+
 int main () {
     int i, u;
     char mac[6];
     IpAddr ip;
     EthernetErr ethErr;
+    
+    uint32_t PixIn;
+
+    spi.format(12,0); //4 bit alla volta
+    //spi.frequency(1000000);
+   spi.frequency(3125000);
+   
+
+/*    PutLed(0);
+    PutLed(0);
+    PutLed(0);
+    PutLed(0);
+    PutLed(0);
+    PutLed(0);
+    PutLed(0);
+    PutLed(0);
+    PutLed(0);
+    wait_us(25);*/
+
+//while(1){};
 
     set_new_handler(no_memory); // new handler function
 
@@ -94,8 +148,41 @@
         } else {
             LED_NET_GY_OFF;
         }
-
+        
         if (art.Work()) {
+            u = art.LastRecievedUniverse;
+            if(u == 0){
+                led1 = 1;
+               for(i = 0; i < 510; i += 3)
+               {
+                   PixIn =  art.DmxIn[u][i+1];
+                   PixIn <<= 8;
+                   PixIn +=  art.DmxIn[u][i];
+                   PixIn <<= 8;
+                   PixIn +=  art.DmxIn[u][i+2];
+                   PutLed(PixIn);
+               }
+               wait_us(25);
+               led1 = 0;
+            }
+            pc.printf("recv, node %d, data %x %x %x\r\n", u, art.DmxIn[u][0], art.DmxIn[u][1], art.DmxIn[u][2]);
+            /*if (u == 0) {
+                led1 = 1;
+                for (i = 0; i < 512; i ++) {
+                    dmx1.put(i, art.DmxIn[u][i]);
+                }
+            } else
+            if (u == 1) {
+                led2 = 1;
+                for (i = 0; i < 512; i ++) {
+                    dmx2.put(i, art.DmxIn[u][i]);
+                }
+            }*/
+//            pc.printf("recv, node %d, data %d\r\n", u, art.DmxIn[u][0]);
+         }
+        
+        
+        /*if (art.Work()) {
             LED_NET_ACT_ON;
             led_yellow = 1;
             u = art.LastRecievedUniverse;
@@ -115,9 +202,9 @@
             led1 = 0;
             led2 = 0;
             led_yellow = 0;
-        }
+        }*/
         
-        if (dmx1.is_recived) {
+        /*if (dmx1.is_recived) {
             led3 = 1;
             led_yellow = 1;
             dmx1.is_recived = 0;
@@ -149,7 +236,7 @@
             led_yellow = 0;
         }
 
-        LED_NET_ACT_OFF;
+        LED_NET_ACT_OFF;*/
     }
 }