spring.c (2928B)
1 /* 2 Copyright 2021 OwLab 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 #include "quantum.h" 18 19 enum caps_modes{ 20 CAPS_MODE_UPPER = 0, //UPPER CASE 21 CAPS_MODE_LOWER //LOWER CASE 22 }; 23 24 uint8_t caps_mode_index; 25 rgblight_config_t pre_rgb; 26 uint8_t dir_hue, dir_sat; 27 28 bool caps_in = false; 29 uint32_t caps_timer; 30 31 32 33 34 void switch_caps_mode(uint8_t mode){ 35 switch(mode){ 36 case CAPS_MODE_UPPER: 37 dir_hue = 0; 38 dir_sat = 240; 39 break; 40 41 case CAPS_MODE_LOWER: 42 dir_hue = 88; 43 dir_sat = 255; 44 break; 45 46 default: 47 break; 48 } 49 rgblight_sethsv_noeeprom(dir_hue,dir_sat,pre_rgb.val); 50 51 } 52 53 54 void init_caps_mode(uint8_t mode){ 55 pre_rgb.mode = rgblight_get_mode(); 56 pre_rgb.hue = rgblight_get_hue(); 57 pre_rgb.sat = rgblight_get_sat(); 58 pre_rgb.val = rgblight_get_val(); 59 caps_in = true; 60 61 rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); 62 switch_caps_mode(mode); 63 64 } 65 66 67 void set_caps_mode(uint8_t mode){ 68 if(caps_in == false){ 69 init_caps_mode(mode); 70 }else{ 71 switch_caps_mode(mode); 72 } 73 caps_timer = timer_read32(); 74 75 76 } 77 78 79 void housekeeping_task_kb(void) { 80 if(caps_in){ 81 if(timer_elapsed32(caps_timer) > 3000){ 82 rgblight_sethsv(pre_rgb.hue, pre_rgb.sat, pre_rgb.val); 83 rgblight_mode(pre_rgb.mode); 84 caps_in = false; 85 } 86 } 87 } 88 89 90 bool process_record_kb(uint16_t keycode, keyrecord_t *record) { 91 if (record->event.pressed) { 92 switch(keycode) { 93 case QK_UNDERGLOW_TOGGLE: 94 case QK_UNDERGLOW_MODE_NEXT: 95 case QK_UNDERGLOW_MODE_PREVIOUS: 96 case QK_UNDERGLOW_HUE_UP: 97 case QK_UNDERGLOW_HUE_DOWN: 98 case QK_UNDERGLOW_SATURATION_UP: 99 case QK_UNDERGLOW_SATURATION_DOWN: 100 case QK_UNDERGLOW_VALUE_UP: 101 case QK_UNDERGLOW_VALUE_DOWN: 102 if(caps_in){ 103 return false; 104 } 105 break; 106 107 108 case KC_CAPS: 109 if(host_keyboard_led_state().caps_lock){ 110 caps_mode_index = CAPS_MODE_LOWER; 111 } else{ 112 caps_mode_index = CAPS_MODE_UPPER; 113 } 114 set_caps_mode(caps_mode_index); 115 break; 116 117 118 default: 119 break; 120 } 121 } 122 return process_record_user(keycode, record); 123 }