aboutsummaryrefslogtreecommitdiff
path: root/users/jonavin/jonavin_encoder.c
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2021-10-30 18:54:36 +0000
committerQMK Bot <hello@qmk.fm>2021-10-30 18:54:36 +0000
commit9e4dd8bfcba41ccac0d28ee8ea218142e7aba674 (patch)
treec9fe4c255d0665067e330918e313f66978749e20 /users/jonavin/jonavin_encoder.c
parentfb739a67c92483f6c072886b9ffbb90e55b6582d (diff)
parent5334e087ef848d54266537ecdc0b87cac976517e (diff)
downloadqmk_firmware-9e4dd8bfcba41ccac0d28ee8ea218142e7aba674.tar.gz
qmk_firmware-9e4dd8bfcba41ccac0d28ee8ea218142e7aba674.zip
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'users/jonavin/jonavin_encoder.c')
-rw-r--r--users/jonavin/jonavin_encoder.c219
1 files changed, 219 insertions, 0 deletions
diff --git a/users/jonavin/jonavin_encoder.c b/users/jonavin/jonavin_encoder.c
new file mode 100644
index 000000000..387ed5f43
--- /dev/null
+++ b/users/jonavin/jonavin_encoder.c
@@ -0,0 +1,219 @@
1
2/* Copyright 2021 Jonavin Eng @Jonavin
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
18
19#include QMK_KEYBOARD_H
20#include "jonavin.h"
21
22#ifdef ENCODER_ENABLE
23 #ifndef DYNAMIC_KEYMAP_LAYER_COUNT
24 #define DYNAMIC_KEYMAP_LAYER_COUNT 4 //default in case this is not already defined elsewhere
25 #endif
26 #ifndef ENCODER_DEFAULTACTIONS_INDEX
27 #define ENCODER_DEFAULTACTIONS_INDEX 0 // can select encoder index if there are multiple encoders
28 #endif
29
30 void encoder_action_volume(bool clockwise) {
31 if (clockwise)
32 tap_code(KC_VOLU);
33 else
34 tap_code(KC_VOLD);
35 }
36
37 void encoder_action_mediatrack(bool clockwise) {
38 if (clockwise)
39 tap_code(KC_MEDIA_NEXT_TRACK);
40 else
41 tap_code(KC_MEDIA_PREV_TRACK);
42 }
43
44 void encoder_action_navword(bool clockwise) {
45 if (clockwise)
46 tap_code16(LCTL(KC_RGHT));
47 else
48 tap_code16(LCTL(KC_LEFT));
49 }
50
51 void encoder_action_navpage(bool clockwise) {
52 if (clockwise)
53 tap_code16(KC_PGUP);
54 else
55 tap_code16(KC_PGDN);
56 }
57
58 // LAYER HANDLING
59 uint8_t selected_layer = 0;
60
61 uint8_t get_selected_layer(void) {
62 return selected_layer;
63 }
64
65 void encoder_action_layerchange(bool clockwise) {
66 if (clockwise) {
67 if(selected_layer < (DYNAMIC_KEYMAP_LAYER_COUNT - 1)) {
68 selected_layer ++;
69 layer_move(selected_layer);
70 }
71 } else {
72 if (selected_layer > 0) {
73 selected_layer --;
74 layer_move(selected_layer);
75 }
76 }
77 }
78
79 #ifdef RGB_MATRIX_ENABLE
80 void encoder_action_rgb_speed(bool clockwise) {
81 if (clockwise)
82 rgb_matrix_increase_speed_noeeprom();
83 else
84 rgb_matrix_decrease_speed_noeeprom();
85 }
86 void encoder_action_rgb_hue(bool clockwise) {
87 if (clockwise)
88 rgb_matrix_increase_hue_noeeprom();
89 else
90 rgb_matrix_decrease_hue_noeeprom();
91 }
92 void encoder_action_rgb_saturation(bool clockwise) {
93 if (clockwise)
94 rgb_matrix_increase_sat_noeeprom();
95 else
96 rgb_matrix_decrease_sat_noeeprom();
97 }
98 void encoder_action_rgb_brightness(bool clockwise) {
99 if (clockwise)
100 rgb_matrix_increase_val_noeeprom();
101 else
102 rgb_matrix_decrease_val_noeeprom();
103 }
104 void encoder_action_rgb_mode(bool clockwise) {
105 if (clockwise)
106 rgb_matrix_step_noeeprom();
107 else
108 rgb_matrix_step_reverse_noeeprom();
109 }
110 #elif defined(RGBLIGHT_ENABLE)
111 void encoder_action_rgb_speed(bool clockwise) {
112 if (clockwise)
113 rgblight_increase_speed_noeeprom();
114 else
115 rgblight_decrease_speed_noeeprom();
116 }
117 void encoder_action_rgb_hue(bool clockwise) {
118 if (clockwise)
119 rgblight_increase_hue_noeeprom();
120 else
121 rgblight_decrease_hue_noeeprom();
122 }
123 void encoder_action_rgb_saturation(bool clockwise) {
124 if (clockwise)
125 rgblight_increase_sat_noeeprom();
126 else
127 rgblight_decrease_sat_noeeprom();
128 }
129 void encoder_action_rgb_brightness(bool clockwise) {
130 if (clockwise)
131 rgblight_increase_val_noeeprom();
132 else
133 rgblight_decrease_val_noeeprom();
134 }
135 void encoder_action_rgb_mode(bool clockwise) {
136 if (clockwise)
137 rgblight_step_noeeprom();
138 else
139 rgblight_step_reverse_noeeprom();
140 }
141 #endif // RGB_MATRIX_ENABLE || RGBLIGHT_ENABLE
142
143 #ifdef ALTTAB_SCROLL_ENABLE
144 bool is_tab_scrolling = false;
145 bool is_alt_tab_active = false;
146 uint16_t alt_tab_timer = 0;
147
148
149 void encoder_toggle_alttabscroll(void) {
150 is_tab_scrolling = !is_tab_scrolling;
151 }
152
153 void encoder_action_alttabscroll(bool clockwise) {
154 if (clockwise) {
155 if (!is_alt_tab_active) {
156 is_alt_tab_active = true;
157 register_mods(MOD_RALT);
158 }
159 tap_code16(KC_TAB);
160 }
161 else {
162 tap_code16(S(KC_TAB));
163 }
164 alt_tab_timer = timer_read();
165 }
166
167 void encoder_tick_alttabscroll(void) {
168 if (is_alt_tab_active) {
169 if (timer_elapsed(alt_tab_timer) > 600) {
170 unregister_mods(MOD_RALT);
171 is_alt_tab_active = false;
172 }
173 }
174 }
175 #endif // ALTTAB_SCROLL_ENABLE
176#endif // ENCODER_ENABLE
177
178#if defined(ENCODER_ENABLE) && defined(ENCODER_DEFAULTACTIONS_ENABLE) // Encoder Functionality
179
180 __attribute__((weak)) bool encoder_update_keymap(uint8_t index, bool clockwise) { return true; }
181
182 bool encoder_update_user(uint8_t index, bool clockwise) {
183 if (!encoder_update_keymap(index, clockwise)) { return false; }
184 if (index != ENCODER_DEFAULTACTIONS_INDEX) {return true;} // exit if the index doesn't match
185 uint8_t mods_state = get_mods();
186 if (mods_state & MOD_BIT(KC_LSFT) ) { // If you are holding L shift, encoder changes layers
187 encoder_action_layerchange(clockwise);
188 } else if (mods_state & MOD_BIT(KC_RSFT) ) { // If you are holding R shift, Page up/dn
189 unregister_mods(MOD_BIT(KC_RSFT));
190 encoder_action_navpage(clockwise);
191 register_mods(MOD_BIT(KC_RSFT));
192 } else if (mods_state & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate next/prev word
193 encoder_action_navword(clockwise);
194 } else if (mods_state & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media next/prev track
195 encoder_action_mediatrack(clockwise);
196 } else {
197 switch(get_highest_layer(layer_state)) {
198 case _FN1:
199 #ifdef IDLE_TIMEOUT_ENABLE
200 timeout_update_threshold(clockwise);
201 #endif
202 break;
203 default:
204 #ifdef ALTTAB_SCROLL_ENABLE
205 if (is_tab_scrolling)
206 encoder_action_alttabscroll(clockwise);
207 else
208 encoder_action_volume(clockwise); // Otherwise it just changes volume
209 #else
210 encoder_action_volume(clockwise); // Otherwise it just changes volume
211 #endif // ALTTAB_SCROLL_ENABLE
212 break;
213 }
214 }
215 return false;
216 }
217#endif // ENCODER_ENABLE
218
219