Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

campapp: RGB LED amplifying #141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions campapp/rgb_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
#include <r0ketlib/fs_util.h>
#include <r0ketlib/keyin.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <campapp/rad1oconfig.h>

#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));
Expand All @@ -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(&amplified[0], 3*8);
framectr++;
if(framectr >= frames)
framectr = 0;
Expand Down
1 change: 1 addition & 0 deletions r0ketlib/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down
1 change: 1 addition & 0 deletions r0ketlib/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down