ArtNet node to drive TM1809 LED strips
Dependencies: DMX DmxArtNet EthernetNetIf mbed
Fork of ArtNode by
main.cpp
00001 /* 00002 * "Node" Device 00003 * "Universe" 512 DMX datas 00004 * "Sub-Net" 16 Universe 00005 * "Server" Controller 00006 * 00007 * can use over 40 Sub-Net on network. 00008 */ 00009 00010 #include "mbed.h" 00011 #include "EthernetNetIf.h" 00012 #include "DmxArtNet.h" 00013 #include "DMX.h" 00014 00015 00016 #define LED_NET_ACT_ON led_yk = 0 00017 #define LED_NET_ACT_OFF led_yk = 1 00018 #define LED_NET_G_ON led_gayk = 1; led_gkya = 0 00019 #define LED_NET_Y_ON led_gayk = 0; led_gkya = 1 00020 #define LED_NET_GY_OFF led_gayk = 0; led_gkya = 0 00021 00022 extern "C" void mbed_mac_address(char *s); 00023 00024 DigitalOut led_red(p22), led_yellow(p23); 00025 DigitalOut led_gayk(p24),led_gkya(p25), led_yk(p26); 00026 DigitalIn eth_link(P1_25), eth_speed(P1_26); 00027 DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); 00028 EthernetNetIf *eth; 00029 DmxArtNet art; 00030 //DMX dmx1(p13, p14); 00031 //DMX dmx2(p28, p27); 00032 Serial pc(USBTX, USBRX); 00033 00034 SPI spi(p11, p12, p13); // mosi, miso, sclk 00035 00036 void no_memory () { 00037 printf("panic: can't allocate to memory!\r\n"); 00038 exit(-1); 00039 } 00040 00041 void shutdown () { 00042 art.ArtPollReply.NumPorts = 0; 00043 strcpy(art.ArtPollReply.NodeReport, "Shutdown"); 00044 art.SendArtPollReply(); 00045 art.Done(); 00046 } 00047 00048 void PutLed(unsigned long GRB) 00049 { 00050 int SpiPack = 0; 00051 int c = 0; 00052 int i; 00053 for(i = 0; i < 24; i++) 00054 { 00055 if(GRB & ((long)(1) << (23-i))) 00056 SpiPack += 6; 00057 else 00058 SpiPack += 4; 00059 00060 if(c++ >= 3) 00061 { 00062 00063 // First don't write to the FIFO buffer if it is full 00064 while (!(LPC_SSP0->SR & 2)) // While TNF-Bit = 0 (FIFO full)... 00065 ; // Wait 00066 LPC_SSP0->DR = SpiPack; // Write to FIFO buffer 00067 00068 00069 // spi.write(SpiPack); 00070 SpiPack = 0; 00071 c = 0; 00072 } 00073 00074 SpiPack = SpiPack << 3; 00075 00076 } 00077 } 00078 00079 00080 int main () { 00081 int i, u; 00082 char mac[6]; 00083 IpAddr ip; 00084 EthernetErr ethErr; 00085 00086 uint32_t PixIn; 00087 00088 spi.format(12,0); //4 bit alla volta 00089 //spi.frequency(1000000); 00090 spi.frequency(3125000); 00091 00092 /* 00093 unsigned long j = 0; 00094 while(1){ 00095 PutLed(0x000055); 00096 PutLed(0x005500); 00097 PutLed(0x550000); 00098 PutLed(j+10); 00099 PutLed(j+10); 00100 PutLed(j+10); 00101 PutLed(j+10); 00102 j+=10; 00103 wait_ms(1); 00104 00105 //wait_ms(25); 00106 }; 00107 */ 00108 00109 set_new_handler(no_memory); // new handler function 00110 00111 pc.baud(112500); 00112 00113 eth_link.mode(PullUp); 00114 eth_speed.mode(PullUp); 00115 00116 if (! eth_link) { 00117 LED_NET_G_ON; 00118 } 00119 LED_NET_ACT_ON; 00120 00121 mbed_mac_address(mac); 00122 ip = IpAddr(2, mac[3], mac[4], mac[5]); 00123 eth = new EthernetNetIf(ip, IpAddr(255,0,0,0), IpAddr(0,0,0,0), IpAddr(0,0,0,0)); 00124 ethErr = eth->setup(); 00125 if (ethErr) { 00126 LED_NET_Y_ON; 00127 led_red = 1; 00128 return -1; 00129 } 00130 pc.printf("Bind to interface: %d.%d.%d.%d\r\n", (unsigned char)ip[0], (unsigned char)ip[1], (unsigned char)ip[2], (unsigned char)ip[3]); 00131 00132 art.BindIpAddress = ip; 00133 art.BCastAddress = IpAddr(2,255,255,255); 00134 00135 art.InitArtPollReplyDefaults(); 00136 // Device 00137 art.ArtPollReply.PortType[0] = 128; // output 00138 art.ArtPollReply.PortType[1] = 128; // output 00139 art.ArtPollReply.PortType[2] = 64; // input 00140 art.ArtPollReply.GoodInput[2] = 4; 00141 art.ArtPollReply.PortType[3] = 64; // input 00142 art.ArtPollReply.GoodInput[3] = 4; 00143 00144 art.Init(); 00145 art.SendArtPollReply(); // announce to art-net nodes 00146 00147 while (1) { 00148 Net::poll(); 00149 if (! eth_link) { 00150 LED_NET_G_ON; 00151 } else { 00152 LED_NET_GY_OFF; 00153 } 00154 00155 if (art.Work()) { 00156 u = art.LastRecievedUniverse; 00157 if(u == 0){ 00158 led1 = 1; 00159 for(i = 0; i < 510; i += 3) 00160 { 00161 PixIn = art.DmxIn[u][i+1]; 00162 PixIn <<= 8; 00163 PixIn += art.DmxIn[u][i]; 00164 PixIn <<= 8; 00165 PixIn += art.DmxIn[u][i+2]; 00166 PutLed(PixIn); 00167 } 00168 wait_us(25); 00169 wait_us(25); 00170 wait_us(25); 00171 wait_us(25); 00172 led1 = 0; 00173 } 00174 pc.printf("recv, node %d, data %x %x %x\r\n", u, art.DmxIn[u][0], art.DmxIn[u][1], art.DmxIn[u][2]); 00175 /*if (u == 0) { 00176 led1 = 1; 00177 for (i = 0; i < 512; i ++) { 00178 dmx1.put(i, art.DmxIn[u][i]); 00179 } 00180 } else 00181 if (u == 1) { 00182 led2 = 1; 00183 for (i = 0; i < 512; i ++) { 00184 dmx2.put(i, art.DmxIn[u][i]); 00185 } 00186 }*/ 00187 // pc.printf("recv, node %d, data %d\r\n", u, art.DmxIn[u][0]); 00188 } 00189 00190 00191 /*if (art.Work()) { 00192 LED_NET_ACT_ON; 00193 led_yellow = 1; 00194 u = art.LastRecievedUniverse; 00195 if (u == 0) { 00196 led1 = 1; 00197 for (i = 0; i < 512; i ++) { 00198 dmx1.put(i, art.DmxIn[u][i]); 00199 } 00200 } else 00201 if (u == 1) { 00202 led2 = 1; 00203 for (i = 0; i < 512; i ++) { 00204 dmx2.put(i, art.DmxIn[u][i]); 00205 } 00206 } 00207 pc.printf("recv, node %d, data %d\r\n", u, art.DmxIn[u][0]); 00208 led1 = 0; 00209 led2 = 0; 00210 led_yellow = 0; 00211 }*/ 00212 00213 /*if (dmx1.is_recived) { 00214 led3 = 1; 00215 led_yellow = 1; 00216 dmx1.is_recived = 0; 00217 u = 0; 00218 for (i = 0; i < 512; i ++) { 00219 art.DmxIn[u][i] = dmx1.get(i); 00220 } 00221 LED_NET_ACT_ON; 00222 art.ArtPollReply.GoodInput[u] = 128; 00223 art.Send_ArtDmx(u, 0, (char*)art.DmxIn[u], 512); 00224 pc.printf("send, node %d, data %d\r\n", u, art.DmxIn[u][0]); 00225 led3 = 0; 00226 led_yellow = 0; 00227 } 00228 00229 if (dmx2.is_recived) { 00230 led4 = 1; 00231 led_yellow = 1; 00232 dmx2.is_recived = 0; 00233 u = 1; 00234 for (i = 0; i < 512; i ++) { 00235 art.DmxIn[u][i] = dmx2.get(i); 00236 } 00237 LED_NET_ACT_ON; 00238 art.ArtPollReply.GoodInput[u] = 128; 00239 art.Send_ArtDmx(u, 0, (char*)art.DmxIn[u], 512); 00240 pc.printf("send, node %d, data %d\r\n", u, art.DmxIn[u][0]); 00241 led4 = 0; 00242 led_yellow = 0; 00243 } 00244 00245 LED_NET_ACT_OFF;*/ 00246 } 00247 } 00248
Generated on Fri Jul 15 2022 02:28:23 by 1.7.2