add DMX output

This commit is contained in:
cnlohr 2015-01-24 20:37:22 -05:00
parent 1dea23c286
commit a7096180ac
4 changed files with 145 additions and 2 deletions

124
DisplayDMX.c Normal file
View file

@ -0,0 +1,124 @@
#include "outdrivers.h"
#include "notefinder.h"
#include <stdio.h>
#include <string.h>
#include "parameters.h"
#include <stdlib.h>
#include <libusb-1.0/libusb.h>
#include "color.h"
#include <math.h>
#include <unistd.h>
struct DMXOutDriver
{
struct libusb_device_handle *devh;
int did_init;
int byte_offset;
int total_leds;
float outamp;
uint8_t * last_leds;
volatile int readyFlag;
};
static void * DMXOutThread( void * v )
{
struct DMXOutDriver * led = (struct DMXOutDriver*)v;
while(1)
{
if( led->readyFlag && led->devh )
{
/* int r = libusb_control_transfer( led->devh,
0x40, //reqtype
0xA5, //request
0x0100, //wValue
0x0000, //wIndex
led->last_leds,
(led->total_leds*3)+1,
1000 );*/
int r = libusb_control_transfer( led->devh, 0, 0xc6, 0x100, 0,
led->last_leds,
(led->total_leds*3)+led->byte_offset+1,
2000 );
if( r < 0 )
{
led->did_init = 0;
printf( "Fault sending DMXs.\n" );
}
}
led->readyFlag = 0;
usleep(100);
}
return 0;
}
static void DMXUpdate(void * id, struct NoteFinder*nf)
{
int i;
struct DMXOutDriver * led = (struct DMXOutDriver*)id;
if( !led->did_init )
{
led->did_init = 1;
if( libusb_init(NULL) < 0 )
{
fprintf( stderr, "Error: Could not initialize libUSB\n" );
// exit( -99 );
}
led->devh = libusb_open_device_with_vid_pid( NULL, 0x16c0, 0x27dd );
// led->devh = libusb_open_device_with_vid_pid( NULL, 0x1d6b, 0x0002 );
if( !led->devh )
{
fprintf( stderr, "Error: Cannot find device.\n" );
// exit( -98 );
}
}
while( led->readyFlag ) usleep(100);
//Advance the DMXs to this position when outputting the values.
for( i = 0; i < led->total_leds; i++ )
{
int source = i;
led->last_leds[i*3+0 + led->byte_offset] = OutLEDs[source*3+0] * led->outamp;
led->last_leds[i*3+1 + led->byte_offset] = OutLEDs[source*3+1] * led->outamp;
led->last_leds[i*3+2 + led->byte_offset] = OutLEDs[source*3+2] * led->outamp;
}
led->readyFlag = 1;
}
static void DMXParams(void * id )
{
struct DMXOutDriver * led = (struct DMXOutDriver*)id;
led->total_leds = GetParameterI( "leds", 10 );
led->byte_offset = 32; RegisterValue( "byte_offset", PAINT, &led->byte_offset, sizeof( led->byte_offset ) );
led->last_leds = malloc( 1026 );
led->outamp = .1; RegisterValue( "ledoutamp", PAFLOAT, &led->outamp, sizeof( led->outamp ) );
led->did_init = 0;
}
static struct DriverInstances * DisplayDMX()
{
struct DriverInstances * ret = malloc( sizeof( struct DriverInstances ) );
memset( ret, 0, sizeof( struct DriverInstances ) );
struct DMXOutDriver * led = ret->id = malloc( sizeof( struct DMXOutDriver ) );
ret->Func = DMXUpdate;
ret->Params = DMXParams;
OGCreateThread( DMXOutThread, led );
led->readyFlag = 0;
DMXParams( led );
return ret;
}
REGISTER_OUT_DRIVER(DisplayDMX);

View file

@ -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 DisplayNetwork.o DisplayUSB2812.o
OUTS := OutputVoronoi.o DisplayArray.o OutputLinear.o DisplayPie.o DisplayNetwork.o DisplayUSB2812.o DisplayDMX.o
WINGCC:=i586-mingw32msvc-gcc
WINGCCFLAGS:= -lwinmm -lgdi32 -lws2_32 -O2 -ffast-math -g

View file

@ -24,7 +24,8 @@ wininput = 0
#sound_source = PULSE
#-1 indicates left and right, 0 left, 1 right.
sample_channel = -1
sourcename = alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
sourcename =
alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
##################################
# General ColorChord properties. #

18
dmx.conf Normal file
View file

@ -0,0 +1,18 @@
outdrivers = DisplayDMX, OutputLinear, DisplayArray
byte_offset = 32
ledoutamp = 1.0
leds = 4
lightx = 2
lighty = 2
note_attach_amp_iir = .3000
note_attach_amp_iir2 = .1500
note_attach_freq_iir = 0.3000
steady_bright = 0
skipfirst = 1
firstval = 0
port = 7777
address = 192.168.0.245