From f5251a0e4127ce8bb86626937f6cec37021d0c8d Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 20 May 2018 22:24:20 -0400 Subject: [PATCH] Make asynchronous operation better. --- colorchord2/DisplayFileWrite.c | 10 ++++++++-- colorchord2/keyboard_rgb_test.conf | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/colorchord2/DisplayFileWrite.c b/colorchord2/DisplayFileWrite.c index 3c049d0..915a259 100644 --- a/colorchord2/DisplayFileWrite.c +++ b/colorchord2/DisplayFileWrite.c @@ -25,8 +25,10 @@ struct FileWriteDriver int lights_file; int total_leds; int inflate_to_u32; + int file_thread_usleep; int asynchronous; uint32_t pass_buffer[MAX_LEDS]; + volatile int flagchanges; og_thread_t rt_thread; }; @@ -35,8 +37,9 @@ static void * LightsWrite( void * v ) struct FileWriteDriver * d = (struct FileWriteDriver *)v; while(1) { - - + usleep( d->file_thread_usleep ); + if( !d->flagchanges ) continue; + d->flagchanges = 0; if( d->lights_file > 0 ) { int btos = ((d->inflate_to_u32)?4:3)*d->total_leds; @@ -65,6 +68,7 @@ static void * LightsWrite( void * v ) close( d->lights_file ); d->lights_file = 0; } + return 0; } static void FileWriteUpdate(void * id, struct NoteFinder*nf) @@ -85,6 +89,7 @@ static void FileWriteUpdate(void * id, struct NoteFinder*nf) d->pass_buffer[i] = ol[0] | (ol[1]<<8) | (ol[2]<<16) | 0xff000000; } } + d->flagchanges = 1; } @@ -95,6 +100,7 @@ static void FileWriteParams(void * 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 )); + d->file_thread_usleep = 10000; RegisterValue( "file_thread_usleep", PAINT, &d->file_thread_usleep, sizeof( d->file_thread_usleep )); } static struct DriverInstances * DisplayFileWrite(const char * parameters) diff --git a/colorchord2/keyboard_rgb_test.conf b/colorchord2/keyboard_rgb_test.conf index 311425a..d660bf8 100644 --- a/colorchord2/keyboard_rgb_test.conf +++ b/colorchord2/keyboard_rgb_test.conf @@ -2,7 +2,7 @@ # https://github.com/cnlohr/clevo_xsm_wmi cpu_autolimit = 1 -headless=0 +headless=1 #General GUI properties. title = PA Test @@ -41,7 +41,7 @@ note_out_chop = 0.05000 #DisplayArray -outdrivers = OutputCells, DisplayFileWrite, DisplayArray +outdrivers = OutputCells, DisplayFileWrite # DisplayArray lightsfile = /sys/devices/platform/clevo_xsm_wmi/kb_rgb inflate_to_u32 = 1 @@ -50,8 +50,9 @@ lighty = 3 fromsides = 1 leds = 3 qtyamp = 20 +file_thread_usleep = 18000 -satamp = 4.800 +satamp = 3.00 amppow = 2.510 distpow = 1.500