logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

spring.c (2928B)


  1. /*
  2. Copyright 2021 OwLab
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "quantum.h"
  15. enum caps_modes{
  16. CAPS_MODE_UPPER = 0, //UPPER CASE
  17. CAPS_MODE_LOWER //LOWER CASE
  18. };
  19. uint8_t caps_mode_index;
  20. rgblight_config_t pre_rgb;
  21. uint8_t dir_hue, dir_sat;
  22. bool caps_in = false;
  23. uint32_t caps_timer;
  24. void switch_caps_mode(uint8_t mode){
  25. switch(mode){
  26. case CAPS_MODE_UPPER:
  27. dir_hue = 0;
  28. dir_sat = 240;
  29. break;
  30. case CAPS_MODE_LOWER:
  31. dir_hue = 88;
  32. dir_sat = 255;
  33. break;
  34. default:
  35. break;
  36. }
  37. rgblight_sethsv_noeeprom(dir_hue,dir_sat,pre_rgb.val);
  38. }
  39. void init_caps_mode(uint8_t mode){
  40. pre_rgb.mode = rgblight_get_mode();
  41. pre_rgb.hue = rgblight_get_hue();
  42. pre_rgb.sat = rgblight_get_sat();
  43. pre_rgb.val = rgblight_get_val();
  44. caps_in = true;
  45. rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
  46. switch_caps_mode(mode);
  47. }
  48. void set_caps_mode(uint8_t mode){
  49. if(caps_in == false){
  50. init_caps_mode(mode);
  51. }else{
  52. switch_caps_mode(mode);
  53. }
  54. caps_timer = timer_read32();
  55. }
  56. void housekeeping_task_kb(void) {
  57. if(caps_in){
  58. if(timer_elapsed32(caps_timer) > 3000){
  59. rgblight_sethsv(pre_rgb.hue, pre_rgb.sat, pre_rgb.val);
  60. rgblight_mode(pre_rgb.mode);
  61. caps_in = false;
  62. }
  63. }
  64. }
  65. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  66. if (record->event.pressed) {
  67. switch(keycode) {
  68. case QK_UNDERGLOW_TOGGLE:
  69. case QK_UNDERGLOW_MODE_NEXT:
  70. case QK_UNDERGLOW_MODE_PREVIOUS:
  71. case QK_UNDERGLOW_HUE_UP:
  72. case QK_UNDERGLOW_HUE_DOWN:
  73. case QK_UNDERGLOW_SATURATION_UP:
  74. case QK_UNDERGLOW_SATURATION_DOWN:
  75. case QK_UNDERGLOW_VALUE_UP:
  76. case QK_UNDERGLOW_VALUE_DOWN:
  77. if(caps_in){
  78. return false;
  79. }
  80. break;
  81. case KC_CAPS:
  82. if(host_keyboard_led_state().caps_lock){
  83. caps_mode_index = CAPS_MODE_LOWER;
  84. } else{
  85. caps_mode_index = CAPS_MODE_UPPER;
  86. }
  87. set_caps_mode(caps_mode_index);
  88. break;
  89. default:
  90. break;
  91. }
  92. }
  93. return process_record_user(keycode, record);
  94. }