/* dmxout.c by Michael Thorpe 2023-05-29 */ #include #include #include #include #include "runner.h" /* PIBASE is 40 for Surf City, 150 for MBCC */ //#define PIBASE 40 #define PIBASE 150 #define PILEN 4 int pifd=-1; static unsigned char oldpi[PILEN]="\xFE\xFE\xFE\xFE"; struct dmx dmxout={len:120,fd:-1}; static void output_pi_packets(struct dmx *data) { char outbuf[6*PILEN+1]=""; if(-1==pifd) return; if(data->lendata[PIBASE+0]) { oldpi[0]=data->data[PIBASE+0]; sprintf(outbuf+strlen(outbuf),"a=%u\n",(unsigned int)data->data[PIBASE+0]); } if(oldpi[1] != data->data[PIBASE+1]) { oldpi[1]=data->data[PIBASE+1]; sprintf(outbuf+strlen(outbuf),"b=%u\n",(unsigned int)data->data[PIBASE+1]); } if(oldpi[2] != data->data[PIBASE+2]) { oldpi[2]=data->data[PIBASE+2]; sprintf(outbuf+strlen(outbuf),"c=%u\n",(unsigned int)data->data[PIBASE+2]); } if(oldpi[3] != data->data[PIBASE+3]) { oldpi[3]=data->data[PIBASE+3]; sprintf(outbuf+strlen(outbuf),"d=%u\n",(unsigned int)data->data[PIBASE+3]); } if(outbuf[0]) write(pifd,outbuf,strlen(outbuf)); } static void dmxout_redraw() { dmx_redraw(&dmxoutframe,&dmxout); } static void output_dmx_packet(struct dmx *data) { int i,j=0; unsigned char out[2+2*(1+DMX_MAXCHAN)]; out[j++]=0xFE; out[j++]=0; for(i=0;i<=data->len;i++) { out[j++]=data->data[i]; if(0xFE==data->data[i]) out[j++]=1; } write(dmxout.fd,out,j); output_pi_packets(data); } static double nexttime=0; void dmxout_doit() { int i; double now=gettime(); if(nowupdate(curlook,now); mhl_update(); dmxout.data[0]=0; for(i=1;i<=dmxout.len;i++) { if(mhl_base_pos<=i && i<=mhl_last_pos) dmxout.data[i]=mhl_output(i-mhl_base_pos); else dmxout.data[i]=curlook->func(curlook,i); } if(dmxoutframe.h && dmxoutframe.w) dmxout_redraw(); if(-1==dmxout.fd) return; output_dmx_packet(&dmxout); #ifdef ARTNET_SUPPORT output_artnet_packet(&dmxout); #endif } void dmxout_save() { if(-1 != dmxout.fd) write(dmxout.fd,"\xFE\x04",2); } struct frame dmxoutframe={draw:dmxout_redraw};