aboutsummaryrefslogtreecommitdiff
path: root/keyboards/dmqdesign/spin/keymaps/encoderlayers/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/dmqdesign/spin/keymaps/encoderlayers/keymap.c')
-rw-r--r--keyboards/dmqdesign/spin/keymaps/encoderlayers/keymap.c152
1 files changed, 152 insertions, 0 deletions
diff --git a/keyboards/dmqdesign/spin/keymaps/encoderlayers/keymap.c b/keyboards/dmqdesign/spin/keymaps/encoderlayers/keymap.c
new file mode 100644
index 000000000..100f821a6
--- /dev/null
+++ b/keyboards/dmqdesign/spin/keymaps/encoderlayers/keymap.c
@@ -0,0 +1,152 @@
1/* Copyright 2019-2020 DMQ Design
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 QMK_KEYBOARD_H
17#include "midi.h"
18#include "qmk_midi.h"
19
20enum layers
21{
22 _BL,
23 _FL,
24 _TL
25};
26
27uint8_t currentLayer;
28
29//The below layers are intentionally empty in order to give a good starting point for how to configure multiple layers.
30const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
31 [_BL] = LAYOUT(/* Base */
32 KC_KP_7, KC_KP_8, KC_KP_9, TO(_BL),
33 KC_KP_4, KC_KP_5, KC_KP_6, TO(_FL),
34 KC_KP_1, KC_KP_2, KC_KP_3, TO(_TL),
35 KC_KP_0, RGB_TOG, RGB_MOD
36 ),
37
38 [_FL] = LAYOUT(/* Base */
39 KC_NO, KC_NO, KC_NO, KC_TRNS,
40 KC_NO, KC_NO, KC_NO, KC_TRNS,
41 KC_NO, KC_NO, KC_NO, KC_TRNS,
42 KC_MS_BTN1, KC_NO, KC_MS_BTN2
43 ),
44
45 [_TL] = LAYOUT(/* Base */
46 KC_NO, KC_NO, KC_NO, KC_TRNS,
47 KC_NO, KC_NO, KC_NO, KC_TRNS,
48 KC_NO, KC_NO, KC_NO, KC_TRNS,
49 KC_NO, KC_NO, KC_NO
50 )
51};
52
53bool encoder_update_user(uint8_t index, bool clockwise) {
54 if (index == 0) { /* First encoder */
55 switch (currentLayer) { //break each encoder update into a switch statement for the current layer
56 case _BL:
57 if (clockwise) {
58 rgblight_increase_hue();
59 } else {
60 rgblight_decrease_hue();
61 }
62 break;
63 case _FL:
64 if (clockwise) {
65 midi_send_cc(&midi_device, 0, 0x14, 1);
66 } else {
67 midi_send_cc(&midi_device, 0, 0x15, 1);
68 }
69 break;
70 case _TL:
71 if (clockwise) {
72 midi_send_cc(&midi_device, 0, 0x1A, 1);
73 } else {
74 midi_send_cc(&midi_device, 0, 0x1B, 1);
75 }
76 break;
77 }
78 } else if (index == 1) { /* Second encoder */
79 switch (currentLayer) {
80 case _BL:
81 if (clockwise) {
82 tap_code(KC_VOLU);
83 } else {
84 tap_code(KC_VOLD);
85 }
86 break;
87 case _FL:
88 if (clockwise) {
89 midi_send_cc(&midi_device, 0, 0x16, 1);
90 } else {
91 midi_send_cc(&midi_device, 0, 0x17, 1);
92 }
93 break;
94 case _TL:
95 if (clockwise) {
96 midi_send_cc(&midi_device, 0, 0x1C, 1);
97 } else {
98 midi_send_cc(&midi_device, 0, 0x1D, 1);
99 }
100 break;
101 }
102 } else if (index == 2) { /* Third encoder */
103 switch (currentLayer) {
104 case _BL:
105 if (clockwise) {
106 rgblight_increase_val();
107 } else {
108 rgblight_decrease_val();
109 }
110 break;
111 case _FL:
112 if (clockwise) {
113 midi_send_cc(&midi_device, 0, 0x18, 1);
114 } else {
115 midi_send_cc(&midi_device, 0, 0x19, 1);
116 }
117 break;
118 case _TL:
119 if (clockwise) {
120 midi_send_cc(&midi_device, 0, 0x1E, 1);
121 } else {
122 midi_send_cc(&midi_device, 0, 0x1F, 1);
123 }
124 break;
125 }
126 }
127 return true;
128}
129
130layer_state_t layer_state_set_user(layer_state_t state) { //This will run every time the layer is updated
131 currentLayer = get_highest_layer(state);
132
133 switch (currentLayer) {
134 case _BL:
135 setrgb(RGB_WHITE, &led[0]); //Set the top LED to white for the bottom layer
136 setrgb(0, 0, 0, &led[1]);
137 setrgb(0, 0, 0, &led[2]);
138 break;
139 case _FL:
140 setrgb(0, 0, 0, &led[0]); //Set the middle LED to white for the middle layer
141 setrgb(RGB_WHITE, &led[1]);
142 setrgb(0, 0, 0, &led[2]);
143 break;
144 case _TL:
145 setrgb(0, 0, 0, &led[0]);
146 setrgb(0, 0, 0, &led[1]);
147 setrgb(RGB_WHITE, &led[2]); //Set the bottom LED to white for the top layer
148 break;
149 }
150 rgblight_set();
151 return state;
152}