Add the network displayer
This commit is contained in:
parent
a377262c80
commit
fd917417bf
122
DisplayNetwork.c
Normal file
122
DisplayNetwork.c
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
#include "outdrivers.h"
|
||||||
|
#include "notefinder.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "parameters.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include "color.h"
|
||||||
|
#include "DrawFunctions.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@ all : colorchord
|
||||||
|
|
||||||
RAWDRAW:=DrawFunctions.o XDriver.o
|
RAWDRAW:=DrawFunctions.o XDriver.o
|
||||||
SOUND:=sound.o sound_alsa.o sound_pulse.o sound_null.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
|
#LEDOUTDriver.o DisplayOUTDriver.o
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ base_hz = 55.0000
|
||||||
# default_sigma = 1.4000
|
# default_sigma = 1.4000
|
||||||
|
|
||||||
# DFT properties for the DFT up top.
|
# DFT properties for the DFT up top.
|
||||||
dft_iir = 0.0
|
dft_iir = 0.6
|
||||||
dft_q = 20.0000
|
dft_q = 20.0000
|
||||||
dft_speedup = 1000.0000
|
dft_speedup = 1000.0000
|
||||||
octaves = 5
|
octaves = 5
|
||||||
|
|
21
netlight.conf
Normal file
21
netlight.conf
Normal file
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue