Skip to content

Instantly share code, notes, and snippets.

@knoopx
Last active March 31, 2022 12:59
Show Gist options
  • Save knoopx/f84d9b41fb03f17c0e23c428cf8d21b3 to your computer and use it in GitHub Desktop.
Save knoopx/f84d9b41fb03f17c0e23c428cf8d21b3 to your computer and use it in GitHub Desktop.

Revisions

  1. knoopx revised this gist Mar 31, 2022. 1 changed file with 0 additions and 9 deletions.
    9 changes: 0 additions & 9 deletions keymap.c
    Original file line number Diff line number Diff line change
    @@ -27,15 +27,6 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
    }
    }

    // disable any led unless on layer 0
    bool led_update_user(led_t led_state) {
    if (get_highest_layer(layer_state) == 0) {
    return true;
    }
    writePin(LED_CAPS_LOCK_PIN, 1);
    return false;
    }

    layer_state_t layer_state_set_user(layer_state_t state) {
    uint8_t layer = get_highest_layer(state);

  2. knoopx created this gist Mar 30, 2022.
    61 changes: 61 additions & 0 deletions keymap.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
    uint8_t layer = get_highest_layer(layer_state);
    for (uint8_t row = 0; row < MATRIX_ROWS; ++row) {
    for (uint8_t col = 0; col < MATRIX_COLS; ++col) {
    uint8_t index = g_led_config.matrix_co[row][col];
    keypos_t keypos = {col, row};

    if (g_led_config.flags[index] == LED_FLAG_NONE) {
    rgb_matrix_set_color(index, RGB_OFF);
    continue;
    }

    // caps lock indicator
    if (row == 3 && col == 0) {
    if (host_keyboard_led_state().caps_lock) {
    g_led_config.flags[index] = LED_FLAG_INDICATOR;
    } else {
    g_led_config.flags[index] = keymap_key_to_keycode(layer, keypos) == KC_TRNS ? LED_FLAG_NONE : LED_FLAG_KEYLIGHT;
    }
    }

    if (g_led_config.flags[index] == LED_FLAG_INDICATOR) {
    rgb_matrix_set_color(index, RGB_RED);
    continue;
    }
    }
    }
    }

    // disable any led unless on layer 0
    bool led_update_user(led_t led_state) {
    if (get_highest_layer(layer_state) == 0) {
    return true;
    }
    writePin(LED_CAPS_LOCK_PIN, 1);
    return false;
    }

    layer_state_t layer_state_set_user(layer_state_t state) {
    uint8_t layer = get_highest_layer(state);

    for (uint8_t row = 0; row < MATRIX_ROWS; ++row) {
    for (uint8_t col = 0; col < MATRIX_COLS; ++col) {
    uint8_t index = g_led_config.matrix_co[row][col];
    keypos_t keypos = {col, row};

    // transparent keys
    if (keymap_key_to_keycode(layer, keypos) == KC_TRNS) {
    g_led_config.flags[index] = LED_FLAG_NONE;
    continue;
    }

    g_led_config.flags[index] = LED_FLAG_KEYLIGHT;
    }
    }

    return state;
    }

    // make effects apply only to keys flagged as keylights
    void keyboard_post_init_user(void) { rgb_matrix_set_flags(LED_FLAG_KEYLIGHT); }