LED-Wavepool: Make astyle happy

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/510/head
Gergely Nagy 6 years ago
parent 84a364ba75
commit 1228c52c1e
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -25,17 +25,17 @@ namespace plugin {
#define MS_PER_FRAME 40 // 40 = 25 fps #define MS_PER_FRAME 40 // 40 = 25 fps
#define FRAMES_PER_DROP 120 // max time between raindrops during idle animation #define FRAMES_PER_DROP 120 // max time between raindrops during idle animation
int8_t WavepoolEffect::surface[2][WP_WID*WP_HGT]; int8_t WavepoolEffect::surface[2][WP_WID * WP_HGT];
uint8_t WavepoolEffect::page = 0; uint8_t WavepoolEffect::page = 0;
uint8_t WavepoolEffect::frames_since_event = 0; uint8_t WavepoolEffect::frames_since_event = 0;
uint16_t WavepoolEffect::idle_timeout = 5000; // 5 seconds uint16_t WavepoolEffect::idle_timeout = 5000; // 5 seconds
// map native keyboard coordinates (16x4) into geometric space (14x5) // map native keyboard coordinates (16x4) into geometric space (14x5)
PROGMEM const uint8_t WavepoolEffect::rc2pos[ROWS*COLS] = { PROGMEM const uint8_t WavepoolEffect::rc2pos[ROWS * COLS] = {
0, 1, 2, 3, 4, 5, 6, 59, 66, 7, 8, 9, 10, 11, 12, 13, 0, 1, 2, 3, 4, 5, 6, 59, 66, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 34, 60, 65, 35, 22, 23, 24, 25, 26, 27, 14, 15, 16, 17, 18, 19, 34, 60, 65, 35, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 48, 61, 64, 49, 36, 37, 38, 39, 40, 41, 28, 29, 30, 31, 32, 33, 48, 61, 64, 49, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 58,62, 63,67, 50, 51, 52, 53, 54, 55, 42, 43, 44, 45, 46, 47, 58, 62, 63, 67, 50, 51, 52, 53, 54, 55,
}; };
EventHandlerResult WavepoolEffect::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) { EventHandlerResult WavepoolEffect::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) {
@ -43,7 +43,7 @@ EventHandlerResult WavepoolEffect::onKeyswitchEvent(Key &mapped_key, byte row, b
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (keyIsPressed(key_state)) { if (keyIsPressed(key_state)) {
uint8_t offset = (row*COLS)+col; uint8_t offset = (row * COLS) + col;
surface[page][pgm_read_byte(rc2pos + offset)] = 0x7f; surface[page][pgm_read_byte(rc2pos + offset)] = 0x7f;
frames_since_event = 0; frames_since_event = 0;
} }
@ -52,13 +52,13 @@ EventHandlerResult WavepoolEffect::onKeyswitchEvent(Key &mapped_key, byte row, b
} }
void WavepoolEffect::raindrop(uint8_t x, uint8_t y, int8_t *page) { void WavepoolEffect::raindrop(uint8_t x, uint8_t y, int8_t *page) {
uint8_t rainspot = (y*WP_WID) + x; uint8_t rainspot = (y * WP_WID) + x;
page[rainspot] = 0x7f; page[rainspot] = 0x7f;
if (y > 0) page[rainspot-WP_WID] = 0x60; if (y > 0) page[rainspot - WP_WID] = 0x60;
if (y < (WP_HGT-1)) page[rainspot+WP_WID] = 0x60; if (y < (WP_HGT - 1)) page[rainspot + WP_WID] = 0x60;
if (x > 0) page[rainspot-1] = 0x60; if (x > 0) page[rainspot - 1] = 0x60;
if (x < (WP_WID-1)) page[rainspot+1] = 0x60; if (x < (WP_WID - 1)) page[rainspot + 1] = 0x60;
} }
// this is a lot smaller than the standard library's rand(), // this is a lot smaller than the standard library's rand(),
@ -66,7 +66,7 @@ void WavepoolEffect::raindrop(uint8_t x, uint8_t y, int8_t *page) {
uint8_t WavepoolEffect::wp_rand() { uint8_t WavepoolEffect::wp_rand() {
static uint16_t offset = 0x400; static uint16_t offset = 0x400;
offset = ((offset + 1) & 0x4fff) | 0x400; offset = ((offset + 1) & 0x4fff) | 0x400;
return (millis()/MS_PER_FRAME) + pgm_read_byte(offset); return (millis() / MS_PER_FRAME) + pgm_read_byte(offset);
} }
void WavepoolEffect::update(void) { void WavepoolEffect::update(void) {
@ -89,21 +89,21 @@ void WavepoolEffect::update(void) {
frames_since_event ++; frames_since_event ++;
// needs two pages of height map to do the calculations // needs two pages of height map to do the calculations
int8_t *newpg = &surface[page^1][0]; int8_t *newpg = &surface[page ^ 1][0];
int8_t *oldpg = &surface[page][0]; int8_t *oldpg = &surface[page][0];
// rain a bit while idle // rain a bit while idle
static uint8_t frames_till_next_drop = 0; static uint8_t frames_till_next_drop = 0;
static int8_t prev_x = -1; static int8_t prev_x = -1;
static int8_t prev_y = -1; static int8_t prev_y = -1;
#ifdef INTERPOLATE #ifdef INTERPOLATE
// even frames: water movement and page flipping // even frames: water movement and page flipping
// odd frames: raindrops and tweening // odd frames: raindrops and tweening
// (this arrangement seems to look best overall) // (this arrangement seems to look best overall)
if (((now & 1)) && (idle_timeout > 0)) { if (((now & 1)) && (idle_timeout > 0)) {
#else #else
if (idle_timeout > 0) { if (idle_timeout > 0) {
#endif #endif
// repeat previous raindrop to give it a slightly better effect // repeat previous raindrop to give it a slightly better effect
if (prev_x >= 0) { if (prev_x >= 0) {
raindrop(prev_x, prev_y, oldpg); raindrop(prev_x, prev_y, oldpg);
@ -128,36 +128,34 @@ void WavepoolEffect::update(void) {
// (originally skipped edges, but this keyboard is too small for that) // (originally skipped edges, but this keyboard is too small for that)
//for (uint8_t y = 1; y < WP_HGT-1; y++) { //for (uint8_t y = 1; y < WP_HGT-1; y++) {
// for (uint8_t x = 1; x < WP_WID-1; x++) { // for (uint8_t x = 1; x < WP_WID-1; x++) {
#ifdef INTERPOLATE #ifdef INTERPOLATE
if (!(now & 1)) { // even frames only if (!(now & 1)) { // even frames only
#endif #endif
for (uint8_t y = 0; y < WP_HGT; y++) { for (uint8_t y = 0; y < WP_HGT; y++) {
for (uint8_t x = 0; x < WP_WID; x++) { for (uint8_t x = 0; x < WP_WID; x++) {
uint8_t offset = (y*WP_WID) + x; uint8_t offset = (y * WP_WID) + x;
int16_t value; int16_t value;
int8_t offsets[] = { -WP_WID, WP_WID, int8_t offsets[] = { -WP_WID, WP_WID,
-1, 1, -1, 1,
-WP_WID-1, -WP_WID+1, -WP_WID - 1, -WP_WID + 1,
WP_WID-1, WP_WID+1 WP_WID - 1, WP_WID + 1
}; };
// don't wrap around edges or go out of bounds // don't wrap around edges or go out of bounds
if (y==0) { if (y == 0) {
offsets[0] = 0; offsets[0] = 0;
offsets[4] += WP_WID; offsets[4] += WP_WID;
offsets[5] += WP_WID; offsets[5] += WP_WID;
} } else if (y == WP_HGT - 1) {
else if (y==WP_HGT-1) {
offsets[1] = 0; offsets[1] = 0;
offsets[6] -= WP_WID; offsets[6] -= WP_WID;
offsets[7] -= WP_WID; offsets[7] -= WP_WID;
} }
if (x==0) { if (x == 0) {
offsets[2] = 0; offsets[2] = 0;
offsets[4] += 1; offsets[4] += 1;
offsets[6] += 1; offsets[6] += 1;
} } else if (x == WP_WID - 1) {
else if (x==WP_WID-1) {
offsets[3] = 0; offsets[3] = 0;
offsets[5] -= 1; offsets[5] -= 1;
offsets[7] -= 1; offsets[7] -= 1;
@ -165,7 +163,7 @@ void WavepoolEffect::update(void) {
// add up all samples, divide, subtract prev frame's center // add up all samples, divide, subtract prev frame's center
int8_t *p; int8_t *p;
for(p=offsets, value=0; p<offsets+8; p++) for (p = offsets, value = 0; p < offsets + 8; p++)
value += oldpg[offset + (*p)]; value += oldpg[offset + (*p)];
value = (value >> 2) - newpg[offset]; value = (value >> 2) - newpg[offset];
@ -173,43 +171,43 @@ void WavepoolEffect::update(void) {
newpg[offset] = value - (value >> 3); newpg[offset] = value - (value >> 3);
} }
} }
#ifdef INTERPOLATE #ifdef INTERPOLATE
} }
#endif #endif
// draw the water on the keys // draw the water on the keys
for (byte r = 0; r < ROWS; r++) { for (byte r = 0; r < ROWS; r++) {
for (byte c = 0; c < COLS; c++) { for (byte c = 0; c < COLS; c++) {
uint8_t offset = (r*COLS) + c; uint8_t offset = (r * COLS) + c;
int8_t height = oldpg[pgm_read_byte(rc2pos+offset)]; int8_t height = oldpg[pgm_read_byte(rc2pos + offset)];
#ifdef INTERPOLATE #ifdef INTERPOLATE
if (now & 1) { // odd frames only if (now & 1) { // odd frames only
// average height with other frame // average height with other frame
height = ((int16_t)height + newpg[pgm_read_byte(rc2pos+offset)]) >> 1; height = ((int16_t)height + newpg[pgm_read_byte(rc2pos + offset)]) >> 1;
} }
#endif #endif
uint8_t intensity = abs(height) * 2; uint8_t intensity = abs(height) * 2;
// color starts white but gets dimmer and more saturated as it fades, // color starts white but gets dimmer and more saturated as it fades,
// with hue wobbling according to height map // with hue wobbling according to height map
int16_t hue = (current_hue + height + (height>>1)) & 0xff; int16_t hue = (current_hue + height + (height >> 1)) & 0xff;
cRGB color = hsvToRgb(hue, cRGB color = hsvToRgb(hue,
0xff - intensity, 0xff - intensity,
((uint16_t)intensity)*2); ((uint16_t)intensity) * 2);
::LEDControl.setCrgbAt(r, c, color); ::LEDControl.setCrgbAt(r, c, color);
} }
} }
#ifdef INTERPOLATE #ifdef INTERPOLATE
// swap pages every other frame // swap pages every other frame
if (!(now & 1)) page ^= 1; if (!(now & 1)) page ^= 1;
#else #else
// swap pages every frame // swap pages every frame
page ^= 1; page ^= 1;
#endif #endif
} }

@ -40,9 +40,9 @@ class WavepoolEffect : public LEDMode {
private: private:
static uint8_t frames_since_event; static uint8_t frames_since_event;
static int8_t surface[2][WP_WID*WP_HGT]; static int8_t surface[2][WP_WID * WP_HGT];
static uint8_t page; static uint8_t page;
static PROGMEM const uint8_t rc2pos[ROWS*COLS]; static PROGMEM const uint8_t rc2pos[ROWS * COLS];
static void raindrop(uint8_t x, uint8_t y, int8_t *page); static void raindrop(uint8_t x, uint8_t y, int8_t *page);
static uint8_t wp_rand(); static uint8_t wp_rand();

Loading…
Cancel
Save