summaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix_animations
diff options
context:
space:
mode:
authorXScorpion2 <rcalt2vt@gmail.com>2019-05-07 21:17:00 -0500
committerDrashna Jaelre <drashna@live.com>2019-05-07 21:49:07 -0700
commitb4dab5b09b617c44213ed97123f8f3744f3ab9d6 (patch)
treecdd83df095bbe1c04d14b00511e243b7e1a75e56 /quantum/rgb_matrix_animations
parent4d57a049b5b04354f7d83ba97b172db22236f5c8 (diff)
RGB Matrix Typing Heatmap (#5786)
* RGB Matrix Typing Heatmap Effect * Fixing file name and effect init
Diffstat (limited to 'quantum/rgb_matrix_animations')
-rw-r--r--quantum/rgb_matrix_animations/digital_rain_anim.h33
-rw-r--r--quantum/rgb_matrix_animations/typing_heatmap_anim.h75
2 files changed, 93 insertions, 15 deletions
diff --git a/quantum/rgb_matrix_animations/digital_rain_anim.h b/quantum/rgb_matrix_animations/digital_rain_anim.h
index 4ba3c1c87d..6ccba392aa 100644
--- a/quantum/rgb_matrix_animations/digital_rain_anim.h
+++ b/quantum/rgb_matrix_animations/digital_rain_anim.h
@@ -1,11 +1,13 @@
#pragma once
-#ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
+#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN)
#ifndef RGB_DIGITAL_RAIN_DROPS
// lower the number for denser effect/wider keyboard
#define RGB_DIGITAL_RAIN_DROPS 24
#endif
+extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
+
bool rgb_matrix_digital_rain(effect_params_t* params) {
// algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
const uint8_t drop_ticks = 28;
@@ -13,24 +15,24 @@ bool rgb_matrix_digital_rain(effect_params_t* params) {
const uint8_t max_brightness_boost = 0xc0;
const uint8_t max_intensity = 0xff;
- static uint8_t map[MATRIX_COLS][MATRIX_ROWS] = {{0}};
static uint8_t drop = 0;
if (params->init) {
rgb_matrix_set_color_all(0, 0, 0);
- memset(map, 0, sizeof map);
+ memset(rgb_frame_buffer, 0, sizeof rgb_frame_buffer);
drop = 0;
}
+
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) {
// top row, pixels have just fallen and we're
// making a new rain drop in this column
- map[col][row] = max_intensity;
+ rgb_frame_buffer[col][row] = max_intensity;
}
- else if (map[col][row] > 0 && map[col][row] < max_intensity) {
+ else if (rgb_frame_buffer[col][row] > 0 && rgb_frame_buffer[col][row] < max_intensity) {
// neither fully bright nor dark, decay it
- map[col][row]--;
+ rgb_frame_buffer[col][row]--;
}
// set the pixel colour
uint8_t led[LED_HITS_TO_REMEMBER];
@@ -38,32 +40,33 @@ bool rgb_matrix_digital_rain(effect_params_t* params) {
// TODO: multiple leds are supported mapped to the same row/column
if (led_count > 0) {
- if (map[col][row] > pure_green_intensity) {
- const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (map[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity));
+ if (rgb_frame_buffer[col][row] > pure_green_intensity) {
+ const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (rgb_frame_buffer[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity));
rgb_matrix_set_color(led[0], boost, max_intensity, boost);
}
else {
- const uint8_t green = (uint8_t) ((uint16_t) max_intensity * map[col][row] / pure_green_intensity);
+ const uint8_t green = (uint8_t) ((uint16_t) max_intensity * rgb_frame_buffer[col][row] / pure_green_intensity);
rgb_matrix_set_color(led[0], 0, green, 0);
}
}
}
}
+
if (++drop > drop_ticks) {
// reset drop timer
drop = 0;
for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) {
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
// if ths is on the bottom row and bright allow decay
- if (row == MATRIX_ROWS - 1 && map[col][row] == max_intensity) {
- map[col][row]--;
+ if (row == MATRIX_ROWS - 1 && rgb_frame_buffer[col][row] == max_intensity) {
+ rgb_frame_buffer[col][row]--;
}
// check if the pixel above is bright
- if (map[col][row - 1] == max_intensity) {
+ if (rgb_frame_buffer[col][row - 1] == max_intensity) {
// allow old bright pixel to decay
- map[col][row - 1]--;
+ rgb_frame_buffer[col][row - 1]--;
// make this pixel bright
- map[col][row] = max_intensity;
+ rgb_frame_buffer[col][row] = max_intensity;
}
}
}
@@ -71,4 +74,4 @@ bool rgb_matrix_digital_rain(effect_params_t* params) {
return false;
}
-#endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
+#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN)
diff --git a/quantum/rgb_matrix_animations/typing_heatmap_anim.h b/quantum/rgb_matrix_animations/typing_heatmap_anim.h
new file mode 100644
index 0000000000..aade53fccc
--- /dev/null
+++ b/quantum/rgb_matrix_animations/typing_heatmap_anim.h
@@ -0,0 +1,75 @@
+#pragma once
+#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
+
+extern rgb_config_t rgb_matrix_config;
+extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
+
+void process_rgb_matrix_typing_heatmap(keyrecord_t *record) {
+ uint8_t row = record->event.key.row;
+ uint8_t col = record->event.key.col;
+ uint8_t m_row = row - 1;
+ uint8_t p_row = row + 1;
+ uint8_t m_col = col - 1;
+ uint8_t p_col = col + 1;
+
+ if (m_col < col)
+ rgb_frame_buffer[row][m_col] = qadd8(rgb_frame_buffer[row][m_col], 16);
+ rgb_frame_buffer[row][col] = qadd8(rgb_frame_buffer[row][col], 32);
+ if (p_col < MATRIX_COLS)
+ rgb_frame_buffer[row][p_col] = qadd8(rgb_frame_buffer[row][p_col], 16);
+
+ if (p_row < MATRIX_ROWS) {
+ if (m_col < col)
+ rgb_frame_buffer[p_row][m_col] = qadd8(rgb_frame_buffer[p_row][m_col], 13);
+ rgb_frame_buffer[p_row][col] = qadd8(rgb_frame_buffer[p_row][col], 16);
+ if (p_col < MATRIX_COLS)
+ rgb_frame_buffer[p_row][p_col] = qadd8(rgb_frame_buffer[p_row][p_col], 13);
+ }
+
+ if (m_row < row) {
+ if (m_col < col)
+ rgb_frame_buffer[m_row][m_col] = qadd8(rgb_frame_buffer[m_row][m_col], 13);
+ rgb_frame_buffer[m_row][col] = qadd8(rgb_frame_buffer[m_row][col], 16);
+ if (p_col < MATRIX_COLS)
+ rgb_frame_buffer[m_row][p_col] = qadd8(rgb_frame_buffer[m_row][p_col], 13);
+ }
+}
+
+bool rgb_matrix_typing_heatmap(effect_params_t* params) {
+ // Modified version of RGB_MATRIX_USE_LIMITS to work off of matrix row / col size
+ uint8_t led_min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter;
+ uint8_t led_max = led_min + RGB_MATRIX_LED_PROCESS_LIMIT;
+ if (led_max > sizeof(rgb_frame_buffer))
+ led_max = sizeof(rgb_frame_buffer);
+
+ if (params->init) {
+ rgb_matrix_set_color_all(0, 0, 0);
+ memset(rgb_frame_buffer, 0, sizeof rgb_frame_buffer);
+ }
+
+ // Render heatmap & decrease
+ for (int i = led_min; i < led_max; i++) {
+ uint8_t row = i % MATRIX_ROWS;
+ uint8_t col = i / MATRIX_ROWS;
+ uint8_t val = rgb_frame_buffer[row][col];
+
+ // set the pixel colour
+ uint8_t led[LED_HITS_TO_REMEMBER];
+ uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
+ for (uint8_t j = 0; j < led_count; ++j)
+ {
+ if (!HAS_ANY_FLAGS(g_led_config.flags[led[j]], params->flags))
+ continue;
+
+ HSV hsv = { 170 - qsub8(val, 85), rgb_matrix_config.sat, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.val) };
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(led[j], rgb.r, rgb.g, rgb.b);
+ }
+
+ rgb_frame_buffer[row][col] = qsub8(val, 1);
+ }
+
+ return led_max < sizeof(rgb_frame_buffer);
+}
+
+#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)