From fd917417bfd90209c2b5e53eb9fac1db5a347e00 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Fri, 16 Jan 2015 02:28:24 -0500 Subject: [PATCH] Add the network displayer --- DisplayNetwork.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 2 +- default.conf | 2 +- netlight.conf | 21 ++++++++ 4 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 DisplayNetwork.c create mode 100644 netlight.conf diff --git a/DisplayNetwork.c b/DisplayNetwork.c new file mode 100644 index 0000000..a72a6a3 --- /dev/null +++ b/DisplayNetwork.c @@ -0,0 +1,122 @@ +#include "outdrivers.h" +#include "notefinder.h" +#include +#include "parameters.h" +#include +#include +#include +#include +#include +#include +#include +#include "color.h" +#include "DrawFunctions.h" +#include + +#define MAX_BUFFER 1487 + +struct DPODriver +{ + int leds; + int skipfirst; + int firstval; + int port; + int oldport; + char address[PARAM_BUFF]; + char oldaddress[PARAM_BUFF]; + struct sockaddr_in servaddr; + int socket; +}; + + +static void DPOUpdate(void * id, struct NoteFinder*nf) +{ + struct DPODriver * d = (struct DPODriver*)id; + int i, j; + + if( strcmp( d->oldaddress, d->address ) != 0 || d->socket == -1 || d->oldport != d->port ) + { + d->socket = socket(AF_INET,SOCK_DGRAM,0); + + + struct hostent *hname; + hname = gethostbyname(d->address); + + if( hname ) + { + bzero(&d->servaddr, sizeof(d->servaddr)); + d->servaddr.sin_family = hname->h_addrtype; + d->servaddr.sin_port = htons( d->port ); + d->servaddr.sin_addr.s_addr = *(long*)hname->h_addr; + + if( d->socket >= 0 ) + { + d->oldport = d->port; + memcpy( d->oldaddress, d->address, PARAM_BUFF ); + } + else + { + fprintf( stderr, "Socket Error.\n" ); + } + } + else + { + fprintf( stderr, "Error: Cannot find host \"%s\":%d\n", d->address, d->port ); + } + } + + if( d->socket > 0 ) + { + char buffer[MAX_BUFFER]; + i = 0; + while( i < d->skipfirst ) + buffer[i++] = d->firstval; + + if( d->leds * 3 + i >= MAX_BUFFER ) + d->leds = (MAX_BUFFER-1)/3; + + for( j = 0; j < d->leds; j++ ) + { + buffer[i++] = OutLEDs[j*3+2]; + buffer[i++] = OutLEDs[j*3+0]; + buffer[i++] = OutLEDs[j*3+1]; + } + int r = sendto( d->socket, buffer, i, MSG_NOSIGNAL, &d->servaddr, sizeof( d->servaddr ) ); + if( r < 0 ) + { + fprintf( stderr, "Send fault.\n" ); + close( d->socket ); + d->socket = -1; + } + } + +} + +static void DPOParams(void * id ) +{ + struct DPODriver * d = (struct DPODriver*)id; + strcpy( d->address, "localhost" ); + + d->leds = 10; RegisterValue( "leds", PINT, &d->leds, sizeof( d->leds ) ); + d->skipfirst = 1; RegisterValue( "skipfirst", PINT, &d->skipfirst, sizeof( d->skipfirst ) ); + d->port = 7777; RegisterValue( "port", PINT, &d->port, sizeof( d->port ) ); + d->firstval = 0; RegisterValue( "firstval", PINT, &d->firstval, sizeof( d->firstval ) ); + RegisterValue( "address", PBUFFER, d->address, sizeof( d->address ) ); + d->socket = -1; + d->oldaddress[0] = 0; +} + +static struct DriverInstances * DisplayNetwork(const char * parameters) +{ + struct DriverInstances * ret = malloc( sizeof( struct DriverInstances ) ); + struct DPODriver * d = ret->id = malloc( sizeof( struct DPODriver ) ); + memset( d, 0, sizeof( struct DPODriver ) ); + ret->Func = DPOUpdate; + ret->Params = DPOParams; + DPOParams( d ); + return ret; +} + +REGISTER_OUT_DRIVER(DisplayNetwork); + + diff --git a/Makefile b/Makefile index 8632152..a2a011d 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all : colorchord RAWDRAW:=DrawFunctions.o XDriver.o SOUND:=sound.o sound_alsa.o sound_pulse.o sound_null.o -OUTS := OutputVoronoi.o DisplayArray.o OutputLinear.o DisplayPie.o +OUTS := OutputVoronoi.o DisplayArray.o OutputLinear.o DisplayPie.o DisplayNetwork.o #LEDOUTDriver.o DisplayOUTDriver.o diff --git a/default.conf b/default.conf index 7cce114..29a70f3 100644 --- a/default.conf +++ b/default.conf @@ -39,7 +39,7 @@ base_hz = 55.0000 # default_sigma = 1.4000 # DFT properties for the DFT up top. -dft_iir = 0.0 +dft_iir = 0.6 dft_q = 20.0000 dft_speedup = 1000.0000 octaves = 5 diff --git a/netlight.conf b/netlight.conf new file mode 100644 index 0000000..cb099f6 --- /dev/null +++ b/netlight.conf @@ -0,0 +1,21 @@ + +#What display output driver should be used? +outdrivers = DisplayNetwork, OutputLinear +leds = 296 +light_siding = 1.4 +satamp = 6.000 +is_loop=0 +led_floor = .2 +note_attach_amp_iir2 = .0500 +note_attach_amp_iir2 = .1500 +note_attach_freq_iir = 0.3000 +steady_bright = 0 +#dft_iir = 0.0 +#dft_q = 20.0000 +#dft_speedup = 1000.0000 + +skipfirst = 1 +firstval = 0 +port = 7777 +address = 192.168.0.245 +