Skip to content

Commit

Permalink
Add dilemma max layer indicator (#47)
Browse files Browse the repository at this point in the history
* 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 <git@zvecr.com>

* Update keyboards/bastardkb/dilemma/4x6_4/rules.mk

per requested changes

Co-authored-by: Joel Challis <git@zvecr.com>

* Update keyboards/bastardkb/dilemma/4x6_4/keymaps/via/config.h

per requested changes

Co-authored-by: Joel Challis <git@zvecr.com>

* Update keyboards/bastardkb/dilemma/4x6_4/keymaps/via/keymap.c

per requested changes

Co-authored-by: Joel Challis <git@zvecr.com>

* Update keyboards/bastardkb/dilemma/4x6_4/config.h

per requested changes

Co-authored-by: Joel Challis <git@zvecr.com>

* 4x6_4/config.h formatting change per review request

Co-authored-by: Drashna Jaelre <drashna@live.com>

* 4x6_4/info.json formatting change per review request

Co-authored-by: Drashna Jaelre <drashna@live.com>

* 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 <gms.rulz@hotmail.com>
Co-authored-by: casuanoob <96005765+casuanoob@users.noreply.github.com>
Co-authored-by: Joel Challis <git@zvecr.com>
Co-authored-by: Drashna Jaelre <drashna@live.com>
Co-authored-by: Ying Kun Zhan <yingkun@zhan.co.nl>
  • Loading branch information
6 people authored Dec 26, 2023
1 parent 8b07442 commit aad1a32
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 6 deletions.
65 changes: 63 additions & 2 deletions keyboards/bastardkb/dilemma/4x6_4/4x6_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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};
Expand All @@ -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
2 changes: 2 additions & 0 deletions keyboards/bastardkb/dilemma/4x6_4/keymaps/via/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
#pragma once

#define DYNAMIC_KEYMAP_LAYER_COUNT 8
#define SPLIT_LAYER_STATE_ENABLE
#define SPLIT_LED_STATE_ENABLE
6 changes: 3 additions & 3 deletions keyboards/bastardkb/dilemma/4x6_4/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion keyboards/bastardkb/dilemma/4x6_4/readme.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit aad1a32

Please sign in to comment.