Update with support for stipled LED rings

Fix bug in linear driver that did out of index reading.
This commit is contained in:
Charles Lohr 2016-05-27 23:54:34 -04:00
parent b34a1340ab
commit cb048b7866
3 changed files with 96 additions and 7 deletions

View file

@ -27,9 +27,11 @@ struct DPODriver
{
int leds;
int skipfirst;
int fliprg;
int firstval;
int port;
int oldport;
int skittlequantity; //When LEDs are in a ring, backwards and forwards This is the number of LEDs in the ring.
char address[PARAM_BUFF];
char oldaddress[PARAM_BUFF];
struct sockaddr_in servaddr;
@ -75,7 +77,9 @@ static void DPOUpdate(void * id, struct NoteFinder*nf)
if( d->socket > 0 )
{
char buffer[MAX_BUFFER];
uint8_t buffer[MAX_BUFFER];
uint8_t lbuff[MAX_BUFFER];
i = 0;
while( i < d->skipfirst )
buffer[i++] = d->firstval;
@ -83,12 +87,54 @@ static void DPOUpdate(void * id, struct NoteFinder*nf)
if( d->leds * 3 + i >= MAX_BUFFER )
d->leds = (MAX_BUFFER-1)/3;
for( j = 0; j < d->leds; j++ )
if( d->fliprg )
{
buffer[i++] = OutLEDs[j*3+0]; //RED
buffer[i++] = OutLEDs[j*3+2]; //BLUE
buffer[i++] = OutLEDs[j*3+1]; //GREEN
for( j = 0; j < d->leds; j++ )
{
lbuff[i++] = OutLEDs[j*3+1]; //GREEN??
lbuff[i++] = OutLEDs[j*3+0]; //RED??
lbuff[i++] = OutLEDs[j*3+2]; //BLUE
}
}
else
{
for( j = 0; j < d->leds; j++ )
{
lbuff[i++] = OutLEDs[j*3+0]; //RED
lbuff[i++] = OutLEDs[j*3+2]; //BLUE
lbuff[i++] = OutLEDs[j*3+1]; //GREEN
}
}
if( d->skittlequantity )
{
i = d->skipfirst;
for( j = 0; j < d->leds; j++ )
{
int ledw = j;
int ledpor = ledw % d->skittlequantity;
int ol;
if( ledw >= d->skittlequantity )
{
ol = ledpor*2-1;
ol = d->skittlequantity*2 - ol -2;
}
else
{
ol = ledpor*2;
}
buffer[i++] = lbuff[ol*3+0+d->skipfirst];
buffer[i++] = lbuff[ol*3+1+d->skipfirst];
buffer[i++] = lbuff[ol*3+2+d->skipfirst];
}
}
else
{
memcpy( buffer, lbuff, i );
}
int r = sendto( d->socket, buffer, i, MSG_NOSIGNAL,(const struct sockaddr *) &d->servaddr, sizeof( d->servaddr ) );
if( r < 0 )
{
@ -110,6 +156,8 @@ static void DPOParams(void * id )
d->port = 7777; RegisterValue( "port", PAINT, &d->port, sizeof( d->port ) );
d->firstval = 0; RegisterValue( "firstval", PAINT, &d->firstval, sizeof( d->firstval ) );
RegisterValue( "address", PABUFFER, d->address, sizeof( d->address ) );
d->fliprg = 0; RegisterValue( "fliprg", PAINT, &d->fliprg, sizeof( d->fliprg ) );
d->skittlequantity=0;RegisterValue( "skittlequantity", PAINT, &d->skittlequantity, sizeof( d->skittlequantity ) );
d->socket = -1;
d->oldaddress[0] = 0;
}

View file

@ -59,6 +59,7 @@ static void LEDUpdate(void * id, struct NoteFinder*nf)
// if( totbins > led_bins ) totbins = led_bins;
for( i = 0; i < totbins; i++ )
{
binpos[i] = nf->note_positions[i] / nf->freqbins;
@ -72,6 +73,7 @@ static void LEDUpdate(void * id, struct NoteFinder*nf)
}
float newtotal = 0;
for( i = 0; i < totbins; i++ )
{
@ -84,7 +86,6 @@ static void LEDUpdate(void * id, struct NoteFinder*nf)
if( binvals[i] / totalbinval < led->led_floor )
binvals[i] = binvalsQ[i] = 0;
#endif
newtotal += binvals[i];
}
totalbinval = newtotal;
@ -94,6 +95,8 @@ static void LEDUpdate(void * id, struct NoteFinder*nf)
float rledampQ[led->total_leds];
int rbinout = 0;
for( i = 0; i < totbins; i++ )
{
int nrleds = (int)((binvals[i] / totalbinval) * led->total_leds);
@ -107,13 +110,22 @@ static void LEDUpdate(void * id, struct NoteFinder*nf)
}
}
if( rbinout == 0 )
{
rledpos[0] = 0;
rledamp[0] = 0;
rledampQ[0] = 0;
rbinout++;
}
for( ; rbinout < led->total_leds; rbinout++ )
{
rledpos[rbinout] = rledpos[rbinout-1];
rledamp[rbinout] = rledamp[rbinout-1];
rledampQ[rbinout] = rledampQ[rbinout-1];
}
}
//Now we have to minimize "advance".
int minadvance = 0;

View file

@ -0,0 +1,29 @@
#for a two-ring WS2812 light, 24 LEDs per layer, one layer clockwise, the other counter-clockwise.
outdrivers = DisplayPie,DisplayNetwork,OutputLinear
leds = 48
light_siding = 1.0 #Turn this to ~1.9 for more uniformity, ~1.0 for less.
satamp = 1.600
is_loop=1
led_floor = .1 #Turn to .25 for more uniformity, .1 for less.
steady_bright = 0
skipfirst = 3
firstval = 0
port = 7777
#address = 192.168.11.231
address = 192.168.43.128
slope=.10
amplify=.3
lightx = 20
lighty = 20
sourcename = alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
fliprg = 1
skittlequantity = 24