diff --git a/keyboards/bastardkb/dilemma/4x6_4/4x6_4.c b/keyboards/bastardkb/dilemma/4x6_4/4x6_4.c index c80ccbc8eb83..7ff4c9ac45e9 100644 --- a/keyboards/bastardkb/dilemma/4x6_4/4x6_4.c +++ b/keyboards/bastardkb/dilemma/4x6_4/4x6_4.c @@ -20,6 +20,14 @@ #include "quantum.h" +#ifndef LAYER_INDICATOR_BRIGHTNESS_INC +# define LAYER_INDICATOR_BRIGHTNESS_INC 22 +#endif + +#ifndef CAPSLOCK_INDICATOR_BRIGHTNESS_INC +# define CAPSLOCK_INDICATOR_BRIGHTNESS_INC 76 +#endif + #ifdef SWAP_HANDS_ENABLE const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { /* Left hand, matrix positions */ @@ -33,8 +41,7 @@ const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { {{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}}, {{0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2}}, {{0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}}, - {{0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4}} -}; + {{0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4}}}; # ifdef ENCODER_MAP_ENABLE const uint8_t PROGMEM encoder_hand_swap_config[NUM_ENCODERS] = {1, 0}; @@ -57,3 +64,57 @@ bool encoder_update_kb(uint8_t index, bool clockwise) { return true; } #endif // ENCODER_ENABLE + +#ifdef RGB_MATRIX_ENABLE +static HSV _get_hsv_for_layer_index(uint8_t layer) { + switch (layer) { + case 1: + return (HSV){HSV_BLUE}; + case 2: + return (HSV){HSV_AZURE}; + case 3: + return (HSV){HSV_ORANGE}; + case 4: + return (HSV){HSV_GREEN}; + case 5: + return (HSV){HSV_TEAL}; + case 6: + return (HSV){HSV_PURPLE}; + default: + return (HSV){HSV_RED}; + }; +} + +// Layer state indicator +bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) { + if (!rgb_matrix_indicators_advanced_user(led_min, led_max)) { + return false; + } + // Set indicator LEDs to red if caps lock is enabled + if (host_keyboard_led_state().caps_lock) { + for (int i = led_min; i <= led_max; i++) { + if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) { + // set modifier-flagged LEDs to a pure a configured interval brighter than the current brightness, clamped to 255 (ie. uint8_t max value). + rgb_matrix_set_color(i, MIN(rgb_matrix_get_val() + CAPSLOCK_INDICATOR_BRIGHTNESS_INC, 255), 0, 0); + } + } + } + + // Set underglow to a solid color for highest active layer apart from the base layer. + const uint8_t layer = get_highest_layer(layer_state); + if (layer > 0) { + HSV hsv = _get_hsv_for_layer_index(layer); + + // Set brightness to the configured interval brighter than current brightness, clamped to 255 (ie. uint8_t max value). This compensates for the dimmer appearance of the underglow LEDs. + hsv.v = MIN(rgb_matrix_get_val() + LAYER_INDICATOR_BRIGHTNESS_INC, 255); + const RGB rgb = hsv_to_rgb(hsv); + + for (int i = led_min; i < led_max; i++) { + if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) { + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + } + } + return true; +}; +#endif // RGB_MATRIX_ENABLE diff --git a/keyboards/bastardkb/dilemma/4x6_4/keymaps/via/config.h b/keyboards/bastardkb/dilemma/4x6_4/keymaps/via/config.h index 24322f990440..ef638901c57d 100644 --- a/keyboards/bastardkb/dilemma/4x6_4/keymaps/via/config.h +++ b/keyboards/bastardkb/dilemma/4x6_4/keymaps/via/config.h @@ -18,3 +18,5 @@ #pragma once #define DYNAMIC_KEYMAP_LAYER_COUNT 8 +#define SPLIT_LAYER_STATE_ENABLE +#define SPLIT_LED_STATE_ENABLE diff --git a/keyboards/bastardkb/dilemma/4x6_4/keymaps/via/keymap.c b/keyboards/bastardkb/dilemma/4x6_4/keymaps/via/keymap.c index 6ac228d7231f..354f82a63bc7 100644 --- a/keyboards/bastardkb/dilemma/4x6_4/keymaps/via/keymap.c +++ b/keyboards/bastardkb/dilemma/4x6_4/keymaps/via/keymap.c @@ -111,14 +111,14 @@ layer_state_t layer_state_set_user(layer_state_t state) { #ifdef RGB_MATRIX_ENABLE // Forward-declare this helper function since it is defined in rgb_matrix.c. void rgb_matrix_update_pwm_buffers(void); -#endif +#endif // RGB_MATRIX_ENABLE #ifdef ENCODER_MAP_ENABLE // clang-format off const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { - [LAYER_BASE] = {ENCODER_CCW_CW(KC_WH_U, KC_WH_D), ENCODER_CCW_CW(KC_VOLU, KC_VOLD)}, + [LAYER_BASE] = {ENCODER_CCW_CW(KC_WH_U, KC_WH_D), ENCODER_CCW_CW(KC_VOLD, KC_VOLU)}, [LAYER_LOWER] = {ENCODER_CCW_CW(KC_UP, KC_DOWN), ENCODER_CCW_CW(KC_LEFT, KC_RGHT)}, - [LAYER_RAISE] = {ENCODER_CCW_CW(KC_PGUP, KC_PGDN), ENCODER_CCW_CW(KC_VOLU, KC_VOLD)}, + [LAYER_RAISE] = {ENCODER_CCW_CW(KC_PGUP, KC_PGDN), ENCODER_CCW_CW(KC_VOLD, KC_VOLU)}, [LAYER_POINTER] = {ENCODER_CCW_CW(RGB_HUD, RGB_HUI), ENCODER_CCW_CW(RGB_SAD, RGB_SAI)}, }; // clang-format on diff --git a/keyboards/bastardkb/dilemma/4x6_4/readme.md b/keyboards/bastardkb/dilemma/4x6_4/readme.md index 30dd2a99f1de..0addad630c6f 100644 --- a/keyboards/bastardkb/dilemma/4x6_4/readme.md +++ b/keyboards/bastardkb/dilemma/4x6_4/readme.md @@ -1,5 +1,17 @@ # Dilemma Max (4x6+4) - This keyboard is an upsized version of the [3x5+3 Dilemma](../3x5_3/). The Dilemma Max is available at [bastardkb.com](https://bastardkb.com). + +## Layer and capslock indicators +The Dilemma Max comes with layer indicators using the underglow LEDs and a capslock indicator using the outermost columns of per-key LEDs. + +The brightness of both indicators is boosted to counteract them being perceived as dimmer (the underglow has to go through an acrylic plate, and pure red appears dimmer than other colors on these LEDs). This has the side effect that the indicators are visible even if the current RGB brightness is set to zero. + +The brightness boosts can be adjusted from your keymap using two defines: +```c +#define LAYER_INDICATOR_BRIGHTNESS_INC 22 +#define CAPSLOCK_INDICATOR_BRIGHTNESS_INC 76 +``` + +A value of 255 would make the indicators appear at maximum brightness regardless of the RGB effect brightness. A value of 0 will disable the brightness boosts.