From 8741ee679ca8dc14b6c397b1fba69ec0333e8666 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 4 Mar 2021 10:39:27 -0700 Subject: [PATCH] Add active_keys effect --- keyboards/system76/launch_1/rgb_matrix_kb.inc | 48 +++++++++++++++++++ keyboards/system76/system76_ec.c | 2 + 2 files changed, 50 insertions(+) diff --git a/keyboards/system76/launch_1/rgb_matrix_kb.inc b/keyboards/system76/launch_1/rgb_matrix_kb.inc index cd3836c025c..6914cddfab8 100644 --- a/keyboards/system76/launch_1/rgb_matrix_kb.inc +++ b/keyboards/system76/launch_1/rgb_matrix_kb.inc @@ -1,7 +1,55 @@ +RGB_MATRIX_EFFECT(active_keys) RGB_MATRIX_EFFECT(raw_rgb) RGB_MATRIX_EFFECT(unlocked) #if defined(RGB_MATRIX_CUSTOM_EFFECT_IMPLS) +#include "dynamic_keymap.h" + +static bool active_keys_initialized = false; +static uint8_t active_keys_table[DRIVER_LED_TOTAL] = { 0 }; + +static void active_keys_initialize(void) { + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + uint8_t led = g_led_config.matrix_co[row][col]; + if (led < DRIVER_LED_TOTAL && row < 16 && col < 16) { + active_keys_table[led] = (row << 4) | col; + } + } + } + active_keys_initialized = true; +} + +static bool active_keys(effect_params_t* params) { + if (!active_keys_initialized) { + active_keys_initialize(); + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + uint8_t layer = get_highest_layer(layer_state); + RGB rgb = hsv_to_rgb(rgb_matrix_config.hsv); + + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + + uint8_t rowcol = active_keys_table[i]; + uint8_t row = rowcol >> 4; + uint8_t col = rowcol & 0xF; + uint16_t keycode = dynamic_keymap_get_keycode(layer, row, col); + switch (keycode) { + case KC_NO: + case KC_TRNS: + rgb_matrix_set_color(i, 0, 0, 0); + break; + default: + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + break; + } + } + + return led_max < DRIVER_LED_TOTAL; +} + RGB raw_rgb_data[DRIVER_LED_TOTAL] = { 0 }; static uint8_t normalize_component(uint8_t component) { diff --git a/keyboards/system76/system76_ec.c b/keyboards/system76/system76_ec.c index db0e33156af..51c1b77b3ad 100644 --- a/keyboards/system76/system76_ec.c +++ b/keyboards/system76/system76_ec.c @@ -48,6 +48,7 @@ enum Mode { MODE_RAINDROPS, MODE_SPLASH, MODE_MULTISPLASH, + MODE_ACTIVE_KEYS, MODE_LAST, }; @@ -65,6 +66,7 @@ static enum rgb_matrix_effects mode_map[] = { RGB_MATRIX_RAINDROPS, RGB_MATRIX_SPLASH, RGB_MATRIX_MULTISPLASH, + RGB_MATRIX_CUSTOM_active_keys, }; _Static_assert(sizeof(mode_map) == MODE_LAST, "mode_map_length");