From 7910c7e02918290ce2afdf91d6aa8426ba82c9b0 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 20 May 2018 21:50:29 -0400 Subject: [PATCH] Bump versions - add file writer for USB keyboard --- colorchord2/DisplayFileWrite.c | 115 +++++++++++++++++++++++++++++ colorchord2/Makefile | 2 +- colorchord2/keyboard_rgb_test.conf | 59 +++++++++++++++ colorchord2/main.c | 6 +- colorchord2/shmtest.conf | 5 +- 5 files changed, 182 insertions(+), 5 deletions(-) create mode 100644 colorchord2/DisplayFileWrite.c create mode 100644 colorchord2/keyboard_rgb_test.conf diff --git a/colorchord2/DisplayFileWrite.c b/colorchord2/DisplayFileWrite.c new file mode 100644 index 0000000..3c049d0 --- /dev/null +++ b/colorchord2/DisplayFileWrite.c @@ -0,0 +1,115 @@ +//Copyright 2015 <>< Charles Lohr under the ColorChord License. + +#include "outdrivers.h" +#include "notefinder.h" +#include +#include "parameters.h" +#include +#include +#include +#include "color.h" +#include "DrawFunctions.h" +#include +#include /* For mode constants */ +#include /* For O_* constants */ +#include + +extern struct NoteFinder * nf; + +#ifndef O_DIRECT + #define O_DIRECT 00040000 +#endif + +struct FileWriteDriver +{ + int lights_file; + int total_leds; + int inflate_to_u32; + int asynchronous; + uint32_t pass_buffer[MAX_LEDS]; + og_thread_t rt_thread; +}; + +static void * LightsWrite( void * v ) +{ + struct FileWriteDriver * d = (struct FileWriteDriver *)v; + while(1) + { + + + if( d->lights_file > 0 ) + { + int btos = ((d->inflate_to_u32)?4:3)*d->total_leds; + int r = write( d->lights_file, d->pass_buffer, btos ); + if( r != btos ) goto fail_write; + } + else + { + const char * lightsfile = GetParameterS( "lightsfile", 0 ); + if( lightsfile ) + { + d->lights_file = open( lightsfile, O_WRONLY ); + if( d->lights_file <= 0 ) + { + fprintf( stderr, "Error: Can't open \"%s\" (%d)\n", lightsfile, d->lights_file ); + } + else + { + fprintf( stderr, "File %s opened OK\n", lightsfile ); + } + } + } + continue; + fail_write: + fprintf( stderr, "File writing fault\n" ); + close( d->lights_file ); + d->lights_file = 0; + } +} + +static void FileWriteUpdate(void * id, struct NoteFinder*nf) +{ + struct FileWriteDriver * d = (struct FileWriteDriver*)id; + + + if( !d->inflate_to_u32 ) + { + memcpy( d->pass_buffer, OutLEDs, d->total_leds*3 ); + } + else + { + int i; + for( i = 0; i < d->total_leds; i++ ) + { + uint8_t * ol = &OutLEDs[i*3]; + d->pass_buffer[i] = ol[0] | (ol[1]<<8) | (ol[2]<<16) | 0xff000000; + } + } + +} + +static void FileWriteParams(void * id ) +{ + struct FileWriteDriver * d = (struct FileWriteDriver*)id; + + d->total_leds = 300; RegisterValue( "leds", PAINT, &d->total_leds, sizeof( d->total_leds )); + d->inflate_to_u32 = 1; RegisterValue( "inflate_to_u32", PAINT, &d->inflate_to_u32, sizeof( d->inflate_to_u32 )); + d->asynchronous = 1; RegisterValue( "file_async", PAINT, &d->asynchronous, sizeof( d->asynchronous )); +} + +static struct DriverInstances * DisplayFileWrite(const char * parameters) +{ + struct DriverInstances * ret = malloc( sizeof( struct DriverInstances ) ); + struct FileWriteDriver * d = ret->id = malloc( sizeof( struct FileWriteDriver ) ); + memset( d, 0, sizeof( struct FileWriteDriver ) ); + ret->Func = FileWriteUpdate; + ret->Params = FileWriteParams; + FileWriteParams( d ); + printf( "Loaded DisplayFileWrite\n" ); + d->rt_thread = OGCreateThread( LightsWrite, d ); + return ret; +} + +REGISTER_OUT_DRIVER(DisplayFileWrite); + + diff --git a/colorchord2/Makefile b/colorchord2/Makefile index 64d16a8..f393fc3 100644 --- a/colorchord2/Makefile +++ b/colorchord2/Makefile @@ -3,7 +3,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 DisplayDMX.o OutputProminent.o RecorderPlugin.o DisplayHIDAPI.o hidapi.o OutputCells.o DisplaySHM.o +OUTS := OutputVoronoi.o DisplayArray.o OutputLinear.o DisplayPie.o DisplayNetwork.o DisplayUSB2812.o DisplayDMX.o OutputProminent.o RecorderPlugin.o DisplayHIDAPI.o hidapi.o OutputCells.o DisplaySHM.o DisplayFileWrite.o WINGCC:= i686-w64-mingw32-gcc diff --git a/colorchord2/keyboard_rgb_test.conf b/colorchord2/keyboard_rgb_test.conf new file mode 100644 index 0000000..311425a --- /dev/null +++ b/colorchord2/keyboard_rgb_test.conf @@ -0,0 +1,59 @@ +# This is the keyboard test for Clevo and PowerSpec 1510 and 1710 laptops, using the kernel module found here: +# https://github.com/cnlohr/clevo_xsm_wmi + +cpu_autolimit = 1 +headless=0 + +#General GUI properties. +title = PA Test +set_screenx = 720 +set_screeny = 480 +in_amplitude = 1.0 + +sample_channel = -1 +sourcename = alsa_output.pci-0000_00_1f.3.analog-stereo.monitor +#bluez_sink.40_EF_4C_CA_A4_5D.monitor +#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor +## alsa_output.pci-0000_00_1b.0.analog-stereo.monitor +# alsa_output.pci-0000_01_00.1.hdmi-stereo-extra2.monitor (On desktop) + + +#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor +#default +# alsa_output.pci-0000_00_1b.0.analog-stereo.monitor +#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor << New laptop +#use pactl list | grep pci- | grep monitor + + +#How many bins a note can jump from frame to frame to be considered a slide. +#this is used to prevent notes from popping in and out a lot. +note_combine_distance = 0.5000 +note_jumpability = 1.8000 +note_minimum_new_distribution_value = 0.0200 +note_out_chop = 0.05000 + +#compress_coefficient = 4.0 +#compress_exponent = .5 + + +#======================================================================= +#Outputs + + +#DisplayArray +outdrivers = OutputCells, DisplayFileWrite, DisplayArray + +lightsfile = /sys/devices/platform/clevo_xsm_wmi/kb_rgb +inflate_to_u32 = 1 +lightx = 1 +lighty = 3 +fromsides = 1 +leds = 3 +qtyamp = 20 + +satamp = 4.800 +amppow = 2.510 +distpow = 1.500 + + + diff --git a/colorchord2/main.c b/colorchord2/main.c index 0a902de..fa4741f 100644 --- a/colorchord2/main.c +++ b/colorchord2/main.c @@ -53,6 +53,7 @@ int cpu_autolimit = 1; REGISTER_PARAM( cpu_autolimit, PAINT ); float cpu_autolimit_interval = 0.016; REGISTER_PARAM( cpu_autolimit_interval, PAFLOAT ); int sample_channel = -1;REGISTER_PARAM( sample_channel, PAINT ); int showfps = 0; REGISTER_PARAM( showfps, PAINT ); +float in_amplitude = 1; REGISTER_PARAM( in_amplitude, PAFLOAT ); struct NoteFinder * nf; @@ -133,7 +134,7 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun } fo /= channelin; - sound[soundhead] = fo; + sound[soundhead] = fo*in_amplitude; soundhead = (soundhead+1)%SOUNDCBSIZE; } else @@ -147,7 +148,7 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun //printf( "Sound fault B %d/%d\n", i, samplesr ); - sound[soundhead] = f; + sound[soundhead] = f*in_amplitude; soundhead = (soundhead+1)%SOUNDCBSIZE; } @@ -353,7 +354,6 @@ int main(int argc, char ** argv) int thisy = sound[thissoundhead] * 128 + 128; thissoundhead = (thissoundhead-1+SOUNDCBSIZE)%SOUNDCBSIZE; for( i = 0; i < screenx; i++ ) { - if( thisy < 0 || thisy > 256 ) printf( "%d/%d\n", thisy,thissoundhead ); CNFGTackSegment( i, lasty, i+1, thisy ); lasty = thisy; thisy = sound[thissoundhead] * 128 + 128; thissoundhead = (thissoundhead-1+SOUNDCBSIZE)%SOUNDCBSIZE; diff --git a/colorchord2/shmtest.conf b/colorchord2/shmtest.conf index d18986d..a1dbefb 100644 --- a/colorchord2/shmtest.conf +++ b/colorchord2/shmtest.conf @@ -5,9 +5,12 @@ headless=1 title = PA Test set_screenx = 720 set_screeny = 480 +in_amplitude = 3.0 sample_channel = -1 -sourcename =alsa_output.pci-0000_00_1b.0.analog-stereo.monitor +sourcename = bluez_sink.40_EF_4C_CA_A4_5D.monitor +#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor +## alsa_output.pci-0000_00_1b.0.analog-stereo.monitor # alsa_output.pci-0000_01_00.1.hdmi-stereo-extra2.monitor (On desktop)