qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

3x5_3.c (3140B)


      1 /**
      2  * Copyright 2020 Christopher Courtney <drashna@live.com> (@drashna)
      3  * Copyright 2021 Quentin LEBASTARD <qlebastard@gmail.com>
      4  * Copyright 2022 Charly Delay <charly@codesink.dev> (@0xcharly)
      5  * Copyright 2023 casuanoob <casuanoob@hotmail.com> (@casuanoob)
      6  *
      7  * This program is free software: you can redistribute it and/or modify
      8  * it under the terms of the GNU General Publicw License as published by
      9  * the Free Software Foundation, either version 2 of the License, or
     10  * (at your option) any later version.
     11  *
     12  * This program is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  * GNU General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU General Public License
     18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19  */
     20 
     21 #include "dilemma.h"
     22 
     23 #ifdef ENCODER_ENABLE
     24 bool encoder_update_kb(uint8_t index, bool clockwise) {
     25     if (!encoder_update_user(index, clockwise)) {
     26         return false;
     27     }
     28     switch (index) {
     29         case 0: // Left-half encoder, mouse scroll.
     30             tap_code(clockwise ? MS_WHLU : MS_WHLD);
     31             break;
     32         case 1: // Right-half encoder, volume control.
     33             tap_code(clockwise ? KC_AUDIO_VOL_UP : KC_AUDIO_VOL_DOWN);
     34             break;
     35     }
     36     return true;
     37 }
     38 #endif // ENCODER_ENABLE
     39 
     40 #ifdef RGB_MATRIX_ENABLE
     41 // Layer state indicator
     42 bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
     43     if (!rgb_matrix_indicators_advanced_user(led_min, led_max)) { return false; }
     44     if (host_keyboard_led_state().caps_lock) {
     45         for (int i = led_min; i <= led_max; i++) {
     46             if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) {
     47                 rgb_matrix_set_color(i, MIN(rgb_matrix_get_val() + 76, 255), 0x00, 0x00);
     48             }
     49         }
     50     }
     51 
     52     uint8_t layer = get_highest_layer(layer_state);
     53     if (layer > 0) {
     54         hsv_t hsv = rgb_matrix_get_hsv();
     55         switch (get_highest_layer(layer_state)) {
     56             case 1:
     57                 hsv = (hsv_t){HSV_BLUE};
     58                 break;
     59             case 2:
     60                 hsv = (hsv_t){HSV_AZURE};
     61                 break;
     62             case 3:
     63                 hsv = (hsv_t){HSV_ORANGE};
     64                 break;
     65             case 4:
     66                 hsv = (hsv_t){HSV_GREEN};
     67                 break;
     68             case 5:
     69                 hsv = (hsv_t){HSV_TEAL};
     70                 break;
     71             case 6:
     72                 hsv = (hsv_t){HSV_PURPLE};
     73                 break;
     74             case 7:
     75             default:
     76                 hsv = (hsv_t){HSV_RED};
     77                 break;
     78         };
     79 
     80         if (hsv.v > rgb_matrix_get_val()) {
     81             hsv.v = MIN(rgb_matrix_get_val() + 22, 255);
     82         }
     83         rgb_t rgb = hsv_to_rgb(hsv);
     84 
     85         for (uint8_t i = led_min; i < led_max; i++) {
     86             if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) {
     87                 rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
     88             }
     89         }
     90     }
     91     return false;
     92 };
     93 #endif // RGB_MATRIX_ENABLE