qmk_firmware

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

nz64.c (2404B)


      1 /* Copyright 2021 JasonRen(biu)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 #include "nz64.h"
     17 
     18 #ifdef RGB_MATRIX_ENABLE
     19 
     20 typedef union {
     21     uint32_t raw;
     22     uint8_t underground_rgb_sw :8;
     23 } kb_cums_t;
     24 kb_cums_t kb_cums;
     25 
     26 bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
     27     if (!rgb_matrix_indicators_advanced_user(led_min, led_max)) {
     28         return false;
     29     }
     30     if (rgb_matrix_is_enabled()) {
     31         if (kb_cums.underground_rgb_sw == 1) {
     32             for (uint8_t i = led_min; i < led_max; ++i) {
     33                 if ((g_led_config.flags[i] == 4)) {
     34                     rgb_matrix_set_color(i, 0, 0, 0);
     35                 }
     36             }
     37         } else if (kb_cums.underground_rgb_sw == 2) {
     38             for (uint8_t i = led_min; i < led_max; ++i) {
     39                 if ((g_led_config.flags[i] == 2)) {
     40                     rgb_matrix_set_color(i, 0, 0, 0);
     41                 }
     42             }
     43         }
     44     } else {
     45         rgb_matrix_set_color_all(0,0,0);
     46     }
     47     return true;
     48 }
     49 
     50 void eeconfig_init_kb(void) {
     51     kb_cums.raw = 0;
     52     eeconfig_update_kb(kb_cums.raw);
     53 
     54     eeconfig_init_user();
     55 }
     56 
     57 void keyboard_post_init_kb(void) {
     58     kb_cums.underground_rgb_sw = eeconfig_read_kb();
     59 
     60     keyboard_post_init_user();
     61 }
     62 
     63 #endif
     64 
     65 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
     66     if (!process_record_user(keycode, record)) {
     67         return false;
     68     }
     69 
     70     switch(keycode) {
     71 #ifdef RGB_MATRIX_ENABLE
     72         case URGB_K:
     73             if (rgb_matrix_config.enable && record->event.pressed) {
     74                 kb_cums.underground_rgb_sw += 1;
     75                 kb_cums.underground_rgb_sw %= 3;
     76             }
     77             eeconfig_update_kb(kb_cums.raw);
     78             return false;
     79 #endif
     80         default:
     81             return true;
     82     }
     83     return true;
     84 }