diff options
Diffstat (limited to 'keyboards/gmmk/pro/ansi/keymaps/mike1808/encoder.c')
-rw-r--r-- | keyboards/gmmk/pro/ansi/keymaps/mike1808/encoder.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/keyboards/gmmk/pro/ansi/keymaps/mike1808/encoder.c b/keyboards/gmmk/pro/ansi/keymaps/mike1808/encoder.c new file mode 100644 index 000000000..049f4df7e --- /dev/null +++ b/keyboards/gmmk/pro/ansi/keymaps/mike1808/encoder.c | |||
@@ -0,0 +1,111 @@ | |||
1 | /* Copyright 2021 Mikael Manukyan <arm.localhost@gmail.com> | ||
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 "encoder.h" | ||
17 | #include "mike1808.h" | ||
18 | #include "print.h" | ||
19 | #include "utils.h" | ||
20 | #include "process_record.h" | ||
21 | #include "rgb_matrix_ledmaps.h" | ||
22 | |||
23 | static uint8_t state = ENCODER_DEFAULT; | ||
24 | |||
25 | // clang-format off | ||
26 | const encoder_callback encoder_mapping[][2] = { | ||
27 | [ENCODER_VOLUME] = {&volume_up, &volume_down}, | ||
28 | #ifdef RGB_MATRIX_ENABLE | ||
29 | [ENCODER_RGB_HUE] = {&rgb_matrix_increase_hue_noeeprom, &rgb_matrix_decrease_hue_noeeprom}, | ||
30 | [ENCODER_RGB_SAT] = {&rgb_matrix_increase_sat_noeeprom, &rgb_matrix_decrease_sat_noeeprom}, | ||
31 | [ENCODER_RGB_VAL] = {&rgb_matrix_increase_val_noeeprom, &rgb_matrix_decrease_val_noeeprom}, | ||
32 | [ENCODER_RGB_EFFECT] = {&rgb_matrix_step_noeeprom, &rgb_matrix_step_reverse_noeeprom}, | ||
33 | [ENCODER_RGB_EFFECT_SPEED] = {&rgb_matrix_increase_speed_noeeprom, &rgb_matrix_decrease_speed_noeeprom}, | ||
34 | #endif // RGB_MATRIX_ENABLE | ||
35 | }; | ||
36 | |||
37 | // clang-format on | ||
38 | |||
39 | void volume_up() { tap_code(KC_VOLU); } | ||
40 | |||
41 | void volume_down() { tap_code(KC_VOLD); } | ||
42 | |||
43 | bool encoder_update_user(uint8_t index, bool clockwise) { | ||
44 | dprintf("current encoder state is: %d\n", state); | ||
45 | |||
46 | if (clockwise) { | ||
47 | (*encoder_mapping[state][0])(); | ||
48 | } else { | ||
49 | (*encoder_mapping[state][1])(); | ||
50 | } | ||
51 | |||
52 | return true; | ||
53 | } | ||
54 | |||
55 | void handle_rgb_key(bool pressed) { | ||
56 | dprintf("handle_rgb_key %d\f", pressed); | ||
57 | |||
58 | if (pressed) { | ||
59 | rgb_matrix_layers_disable(); | ||
60 | } else { | ||
61 | rgb_matrix_layers_enable(); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | static KeyPressState *rgb_state; | ||
66 | |||
67 | void keyboard_post_init_encoder() { | ||
68 | rgb_state = NewKeyPressState(handle_rgb_key); | ||
69 | } | ||
70 | |||
71 | bool process_record_encoder(uint16_t keycode, keyrecord_t *record) { | ||
72 | #ifdef RGB_MATRIX_ENABLE | ||
73 | switch (keycode) { | ||
74 | case KC_RGB_ENC_HUE ... KC_RGB_ENC_EFFECT: | ||
75 | if (record->event.pressed) { | ||
76 | # ifdef RGB_MATRIX_LEDMAPS_ENABLED | ||
77 | // disable layers so we can adjust RGB effects | ||
78 | rgb_state->press(rgb_state); | ||
79 | # endif // RGB_MATRIX_LEDMAPS_ENABLED | ||
80 | |||
81 | switch (keycode) { | ||
82 | case KC_RGB_ENC_HUE: | ||
83 | state = ENCODER_RGB_HUE; | ||
84 | break; | ||
85 | case KC_RGB_ENC_SAT: | ||
86 | state = ENCODER_RGB_SAT; | ||
87 | break; | ||
88 | case KC_RGB_ENC_VAL: | ||
89 | state = ENCODER_RGB_VAL; | ||
90 | break; | ||
91 | case KC_RGB_ENC_EFFECT_SPEED: | ||
92 | state = ENCODER_RGB_EFFECT_SPEED; | ||
93 | break; | ||
94 | case KC_RGB_ENC_EFFECT: | ||
95 | state = ENCODER_RGB_EFFECT; | ||
96 | break; | ||
97 | } | ||
98 | } else { | ||
99 | # ifdef RGB_MATRIX_LEDMAPS_ENABLED | ||
100 | rgb_state->release(rgb_state); | ||
101 | # endif // RGB_MATRIX_LEDMAPS_ENABLED | ||
102 | state = ENCODER_DEFAULT; | ||
103 | store_rgb_state_to_eeprom(); | ||
104 | } | ||
105 | |||
106 | return false; | ||
107 | } | ||
108 | #endif // RGB_MATRIX_ENABLE | ||
109 | |||
110 | return true; | ||
111 | } | ||