aboutsummaryrefslogtreecommitdiff
path: root/keyboards/owlab/spring/spring.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/owlab/spring/spring.c')
-rw-r--r--keyboards/owlab/spring/spring.c125
1 files changed, 125 insertions, 0 deletions
diff --git a/keyboards/owlab/spring/spring.c b/keyboards/owlab/spring/spring.c
new file mode 100644
index 000000000..60982c151
--- /dev/null
+++ b/keyboards/owlab/spring/spring.c
@@ -0,0 +1,125 @@
1/*
2Copyright 2021 OwLab
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "spring.h"
18
19enum caps_modes{
20 CAPS_MODE_UPPER = 0, //UPPER CASE
21 CAPS_MODE_LOWER //LOWER CASE
22};
23
24uint8_t caps_mode_index;
25rgblight_config_t pre_rgb;
26uint8_t dir_hue, dir_sat;
27
28bool caps_in = false;
29uint32_t caps_timer;
30
31
32
33
34void 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
54void 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
67void 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
79void matrix_scan_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 matrix_scan_user();
89}
90
91
92bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
93 if (record->event.pressed) {
94 switch(keycode) {
95 case RGB_TOG:
96 case RGB_MOD:
97 case RGB_RMOD:
98 case RGB_HUI:
99 case RGB_HUD:
100 case RGB_SAI:
101 case RGB_SAD:
102 case RGB_VAI:
103 case RGB_VAD:
104 if(caps_in){
105 return false;
106 }
107 break;
108
109
110 case KC_CAPS:
111 if(IS_LED_ON(host_keyboard_leds(), USB_LED_CAPS_LOCK)){
112 caps_mode_index = CAPS_MODE_LOWER;
113 } else{
114 caps_mode_index = CAPS_MODE_UPPER;
115 }
116 set_caps_mode(caps_mode_index);
117 break;
118
119
120 default:
121 break;
122 }
123 }
124 return process_record_user(keycode, record);
125}