From aad1a32b1e239c92b5e5aa18b14607c36f21015e Mon Sep 17 00:00:00 2001 From: burkfers Date: Tue, 26 Dec 2023 16:15:59 +0100 Subject: [PATCH] Add dilemma max layer indicator (#47) * tentatively add dilemma 4x6_4 WIP untested * Add dilemma 4x6_4 WIP set max brightness to 128 pending testing migrate rgbmatrix layout macro to info.json migrate other settings to info.json add default keymap and readme add via keymap readme * 4x6_4 Remove files that shouldn't be in main KLE and Via JSONs should not be included in qmk_firmware * 4x6_4 Add RGBMATRIX coordinates in info.json WIP Still pending testing to validate coordinates Add copyright lines * 4x6_4 Change RGB matrix centre * 4x6_4 update rgb flags for outer columns * 4x6_4 add swap_hands config from Drashna * 4x6_4 explicitly set some defaults some things were only working because "processor: RP2040" defaults to GENERIC_PROMICRO_RP2040. explicitly set "board": "GENERIC_RP_RP2040" instead. correctly enable SPI0 and SPID0 instead of SPI1 * Update dilemma/readme.md * 4x6_4 migrate more items to info.json Forgot to move rgb matrix animations to info.json Didn't realise RGB_MATRIX_CENTER had an info.json mapping Missed migrating some rules.mk options to info.json * Update keyboards/bastardkb/dilemma/4x6_4/rules.mk per requested changes Co-authored-by: Joel Challis * Update keyboards/bastardkb/dilemma/4x6_4/rules.mk per requested changes Co-authored-by: Joel Challis * Update keyboards/bastardkb/dilemma/4x6_4/keymaps/via/config.h per requested changes Co-authored-by: Joel Challis * Update keyboards/bastardkb/dilemma/4x6_4/keymaps/via/keymap.c per requested changes Co-authored-by: Joel Challis * Update keyboards/bastardkb/dilemma/4x6_4/config.h per requested changes Co-authored-by: Joel Challis * 4x6_4/config.h formatting change per review request Co-authored-by: Drashna Jaelre * 4x6_4/info.json formatting change per review request Co-authored-by: Drashna Jaelre * Add layer indicators * Use predefined rgb colors for layers * Refactor layer indicators from keymap to keyboard * swap encoder volume directions for CW=volup * Revert wrong conflict solutions following review * Update keyboards/bastardkb/dilemma/4x6_4/info.json * Update keyboards/bastardkb/dilemma/4x6_4/config.h * Update keyboards/bastardkb/dilemma/4x6_4/keymaps/default/readme.md * Update keyboards/bastardkb/dilemma/4x6_4/config.h * Apply suggested changes from code review * Apply suggested changes from code review * Break the brightness interval out into defines for configurability from keymap * Formatting * Add documentation for indicator brightness boosts * narrow scope of kb-internal function * fix type of counting variable * remove unneccessary condition * Remove shutdown_user Instead of rewriting for breaking change, simply removed akin to new 3x5_3 on qmk:develop * Formatting --------- Co-authored-by: casuanoob Co-authored-by: casuanoob <96005765+casuanoob@users.noreply.github.com> Co-authored-by: Joel Challis Co-authored-by: Drashna Jaelre Co-authored-by: Ying Kun Zhan --- keyboards/bastardkb/dilemma/4x6_4/4x6_4.c | 65 ++++++++++++++++++- .../dilemma/4x6_4/keymaps/via/config.h | 2 + .../dilemma/4x6_4/keymaps/via/keymap.c | 6 +- keyboards/bastardkb/dilemma/4x6_4/readme.md | 14 +++- 4 files changed, 81 insertions(+), 6 deletions(-) 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.