From e2808220e5c57c46088217b531833249f1e27a41 Mon Sep 17 00:00:00 2001 From: Selene Scriven Date: Sat, 5 Aug 2017 21:41:23 -0600 Subject: [PATCH] Made idle animation produce somewhat deeper raindrops. (makes idle mode look a little more like a human tapping random keys) --- src/Kaleidoscope/LED-Wavepool.cpp | 28 +++++++++++++++++++++------- src/Kaleidoscope/LED-Wavepool.h | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Kaleidoscope/LED-Wavepool.cpp b/src/Kaleidoscope/LED-Wavepool.cpp index 8394e989..7264624b 100644 --- a/src/Kaleidoscope/LED-Wavepool.cpp +++ b/src/Kaleidoscope/LED-Wavepool.cpp @@ -64,6 +64,16 @@ Key WavepoolEffect::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t return mapped_key; } +void WavepoolEffect::raindrop(uint8_t x, uint8_t y, int8_t *page) { + uint8_t rainspot = (y*WP_WID) + x; + + page[rainspot] = 0x7f; + if (y > 0) page[rainspot-WP_WID] = 0x60; + if (y < (WP_HGT-1)) page[rainspot+WP_WID] = 0x60; + if (x > 0) page[rainspot-1] = 0x60; + if (x < (WP_WID-1)) page[rainspot+1] = 0x60; +} + void WavepoolEffect::update(void) { // limit the frame rate; one frame every 64 ms @@ -92,20 +102,24 @@ void WavepoolEffect::update(void) { // rain a bit while idle static uint8_t frames_till_next_drop = 0; + static int8_t prev_x = -1; + static int8_t prev_y = -1; if (idle_timeout > 0) { + // repeat previous raindrop to give it a slightly better effect + if (prev_x >= 0) { + raindrop(prev_x, prev_y, oldpg); + prev_x = prev_y = -1; + } if (frames_since_event >= (frames_till_next_drop + (idle_timeout >> 6))) { - frames_till_next_drop = rand() & 0x3f; + frames_till_next_drop = 4 + (rand() & 0x3f); frames_since_event = idle_timeout >> 6; uint8_t x = rand() % WP_WID; uint8_t y = rand() % WP_HGT; - uint8_t rainspot = (y*WP_WID) + x; + raindrop(x, y, oldpg); - oldpg[rainspot] = 0x7f; - if (y > 0) oldpg[rainspot-WP_WID] = 0x50; - if (y < (WP_HGT-1)) oldpg[rainspot+WP_WID] = 0x50; - if (x > 0) oldpg[rainspot-1] = 0x50; - if (x < (WP_WID-1)) oldpg[rainspot+1] = 0x50; + prev_x = x; + prev_y = y; } } diff --git a/src/Kaleidoscope/LED-Wavepool.h b/src/Kaleidoscope/LED-Wavepool.h index 6c9929f6..28440075 100644 --- a/src/Kaleidoscope/LED-Wavepool.h +++ b/src/Kaleidoscope/LED-Wavepool.h @@ -43,6 +43,7 @@ class WavepoolEffect : public LEDMode { static PROGMEM const uint8_t rc2pos[ROWS*COLS]; static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); + static void raindrop(uint8_t x, uint8_t y, int8_t *page); }; }