diff --git a/campapp/rgb_leds.c b/campapp/rgb_leds.c index 399ca3a1..53bdde4b 100644 --- a/campapp/rgb_leds.c +++ b/campapp/rgb_leds.c @@ -6,15 +6,17 @@ #include #include #include +#include +#include #include #define MAX_LED_FRAMES 50 #define BUF_SIZE 3*8*MAX_LED_FRAMES+2 -unsigned char leds[BUF_SIZE]; -unsigned int frames = 0; -unsigned int ctr = 0; -unsigned int framectr = 0; +uint8_t leds[BUF_SIZE]; +uint8_t frames = 0; +uint16_t ctr = 0; +uint8_t framectr = 0; void readRgbLedFile(void) { int size = getFileSize(GLOBAL(ledfile)); @@ -40,7 +42,35 @@ void tick_rgbLeds(void) { if(GLOBAL(rgbleds)) { if(frames > 0) { if(ctr == 0) { - ws2812_sendarray(&leds[framectr*3*8+2], 3*8); + uint8_t amplified[3*8]; + + // determine amplifier level based on the config + int8_t amplvl = GLOBAL(rgbleds_amp) - 8; + if (amplvl > 0) { + amplvl = round(sqrt(pow(2,amplvl+1))); + } else if (amplvl < 0) { + amplvl = -round(sqrt(pow(2,-amplvl+1))); + } else { + amplvl = 1; + } + + // iterate through every value in the frame (3 channels * 8 LEDs) + for (int8_t i=0; i<3*8; i++) { + // copy original value + uint8_t origval = leds[(framectr*3*8+2)+i]; + // set the amplified value + if (amplvl >= 0) { + amplified[i] = origval * amplvl; + if (amplvl != 0 && amplified[i] / amplvl != origval) { + // overflow! + amplified[i] = 255; + } + } else { + amplified[i] = origval / -amplvl; + } + } + + ws2812_sendarray(&lified[0], 3*8); framectr++; if(framectr >= frames) framectr = 0; diff --git a/r0ketlib/config.c b/r0ketlib/config.c index 8712cf70..2e5ef535 100644 --- a/r0ketlib/config.c +++ b/r0ketlib/config.c @@ -35,6 +35,7 @@ struct CDESC the_config[]= { {"nickbg", 255, 0, 255, 1, CFG_TYPE_DEVEL}, {"vdd_fix", 0, 0, 1, 0, 0}, {"rgbleds", 0, 0, 1, 0, 0}, + {"rgbleds_amp", 8, 0, 16, 0, 0}, { NULL, 0, 0, 0 , 0, 0}, }; diff --git a/r0ketlib/config.h b/r0ketlib/config.h index f43537bf..c6eb0f8c 100644 --- a/r0ketlib/config.h +++ b/r0ketlib/config.h @@ -49,6 +49,7 @@ extern char ledfile[]; #define GLOBALnickbg (the_config[13].value) #define GLOBALvdd_fix (the_config[14].value) #define GLOBALrgbleds (the_config[15].value) +#define GLOBALrgbleds_amp (the_config[16].value) #define GLOBAL(x) GLOBAL ## x