]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/meira/keymaps/default/keymap.c
Meira updates for bluetooth and audio (#2731)
[qmk_firmware.git] / keyboards / meira / keymaps / default / keymap.c
1 /* Copyright 2017 Cole Markham
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 "meira.h"
17 #include "lighting.h"
18
19 #ifdef RGBLIGHT_ENABLE
20 //Following line allows macro to read current RGB settings
21 extern rgblight_config_t rgblight_config;
22 #endif
23
24 #define _QWERTY 0
25 #define _COLEMAK 1
26 #define _DVORAK 2
27 #define _LOWER 3
28 #define _RAISE 4
29 #define _ADJUST 16
30
31 enum custom_keycodes {
32   QWERTY = SAFE_RANGE,
33   COLEMAK,
34   DVORAK,
35   LOWER,
36   RAISE,
37   ADJUST,
38 };
39
40 #ifdef AUDIO_ENABLE
41
42 float tone_my_startup[][2] = SONG(ODE_TO_JOY);
43 float tone_my_goodbye[][2] = SONG(ROCK_A_BYE_BABY);
44
45 float tone_qwerty[][2]     = SONG(QWERTY_SOUND);
46 float tone_dvorak[][2]     = SONG(DVORAK_SOUND);
47 float tone_colemak[][2]    = SONG(COLEMAK_SOUND);
48
49 #endif /* AUDIO_ENABLE */
50
51 // define variables for reactive RGB
52 bool TOG_STATUS = false;
53 int RGB_current_mode;
54
55 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
56         /* Qwerty
57          * ,-----------------------------------------------------------------------------------.
58          * | Esc  |   Q  |   W  |   E  |   R  |   T  |   Y  |   U  |   I  |   O  |   P  | Bksp |
59          * |------+------+------+------+------+-------------+------+------+------+------+------|
60          * | Tab  |   A  |   S  |   D  |   F  |   G  |   H  |   J  |   K  |   L  |   ;  |  '   |
61          * |------+------+------+------+------+------|------+------+------+------+------+------|
62          * | Shift|   Z  |   X  |   C  |   V  |   B  |   N  |   M  |   ,  |   .  |   /  |Enter |
63          * |------+------+------+------+------+------+------+------+------+------+------+------|
64          * |Adjust| Ctrl | Ctrl  | Alt  |Lower | Cmd  |Space |Raise | Left | Down |  Up  |Right |
65          * `-----------------------------------------------------------------------------------'
66          */
67         [_QWERTY] = KEYMAP( \
68                 KC_ESC,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_BSPC, \
69                 KC_TAB,  KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, KC_QUOT, \
70                 KC_LSFT, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH,  KC_ENT, \
71                 ADJUST,  KC_LCTL, KC_LALT, KC_LALT, LOWER,   KC_LGUI,  KC_SPC,  RAISE,   KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT \
72         ),
73
74         /* Colemak
75          * ,-----------------------------------------------------------------------------------.
76          * | Tab  |   Q  |   W  |   F  |   P  |   G  |   J  |   L  |   U  |   Y  |   ;  | Bksp |
77          * |------+------+------+------+------+-------------+------+------+------+------+------|
78          * | Esc  |   A  |   R  |   S  |   T  |   D  |   H  |   N  |   E  |   I  |   O  |  "   |
79          * |------+------+------+------+------+------|------+------+------+------+------+------|
80          * | Shift|   Z  |   X  |   C  |   V  |   B  |   K  |   M  |   ,  |   .  |   /  |Enter |
81          * |------+------+------+------+------+------+------+------+------+------+------+------|
82          * |Adjust| Ctrl | Alt  | GUI  |Lower |Space |Space |Raise | Left | Down |  Up  |Right |
83          * `-----------------------------------------------------------------------------------'
84          */
85         [_COLEMAK] = KEYMAP( \
86                 KC_TAB,  KC_Q,    KC_W,    KC_F,    KC_P,    KC_G,    KC_J,    KC_L,    KC_U,    KC_Y,    KC_SCLN, KC_BSPC, \
87                 KC_ESC,  KC_A,    KC_R,    KC_S,    KC_T,    KC_D,    KC_H,    KC_N,    KC_E,    KC_I,    KC_O,    KC_QUOT, \
88                 KC_LSFT, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_K,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_ENT , \
89                 ADJUST,  KC_LCTL, KC_LALT, KC_LGUI, LOWER,   KC_SPC,  KC_SPC,  RAISE,   KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT \
90         ),
91
92         /* Dvorak
93          * ,-----------------------------------------------------------------------------------.
94          * | Tab  |   "  |   ,  |   .  |   P  |   Y  |   F  |   G  |   C  |   R  |   L  | Bksp |
95          * |------+------+------+------+------+-------------+------+------+------+------+------|
96          * | Esc  |   A  |   O  |   E  |   U  |   I  |   D  |   H  |   T  |   N  |   S  |  /   |
97          * |------+------+------+------+------+------|------+------+------+------+------+------|
98          * | Shift|   ;  |   Q  |   J  |   K  |   X  |   B  |   M  |   W  |   V  |   Z  |Enter |
99          * |------+------+------+------+------+------+------+------+------+------+------+------|
100          * |Adjust| Ctrl | Alt  | GUI  |Lower |Space |Space |Raise | Left | Down |  Up  |Right |
101          * `-----------------------------------------------------------------------------------'
102          */
103         [_DVORAK] = KEYMAP( \
104                 KC_TAB,  KC_QUOT, KC_COMM, KC_DOT,  KC_P,    KC_Y,    KC_F,    KC_G,    KC_C,    KC_R,    KC_L,    KC_BSPC, \
105                 KC_ESC,  KC_A,    KC_O,    KC_E,    KC_U,    KC_I,    KC_D,    KC_H,    KC_T,    KC_N,    KC_S,    KC_SLSH, \
106                 KC_LSFT, KC_SCLN, KC_Q,    KC_J,    KC_K,    KC_X,    KC_B,    KC_M,    KC_W,    KC_V,    KC_Z,    KC_ENT , \
107                 ADJUST,  KC_LCTL, KC_LALT, KC_LGUI, LOWER,   KC_SPC,  KC_SPC,  RAISE,   KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT \
108         ),
109
110         /* Lower
111          * ,-----------------------------------------------------------------------------------.
112          * |      |   !  |   @  |   #  |   $  |   %  |   ^  |   &  |   *  |   (  |   )  | Bksp |
113          * |------+------+------+------+------+-------------+------+------+------+------+------|
114          * |   ~  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   _  |   +  |     |    \  |  |   |
115          * |------+------+------+------+------+------|------+------+------+------+------+------|
116          * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO ~ |ISO | |      |      |Enter |
117          * |------+------+------+------+------+------+------+------+------+------+------+------|
118          * |      |      |      |      |      |             |      | Next | Vol- | Vol+ | Play |
119          * `-----------------------------------------------------------------------------------'
120          */
121         [_LOWER] = KEYMAP( \
122                 _______, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL, \
123                 KC_TILD,  KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
124                 _______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,S(KC_NUHS),S(KC_NUBS),_______, _______, KC_QUOT, \
125                 _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END \
126         ),
127
128         /* Raise
129          * ,-----------------------------------------------------------------------------------.
130          * |      |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  | Bksp |
131          * |------+------+------+------+------+-------------+------+------+------+------+------|
132          * |   `  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   -  |   =  |   [  |   ]  |  \   |
133          * |------+------+------+------+------+------|------+------+------+------+------+------|
134          * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO # |ISO / |      |      |Enter |
135          * |------+------+------+------+------+------+------+------+------+------+------+------|
136          * |      |      |      |      |      |             |      | Home | PgUp | PgDn | End  |
137          * `-----------------------------------------------------------------------------------'
138          */
139         [_RAISE] = KEYMAP( \
140                 _______,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_DEL, \
141                 KC_GRV,  KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_MINS, KC_EQL,  KC_LBRC, KC_RBRC, KC_BSLS, \
142                 _______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  KC_NUHS, KC_NUBS, _______, _______, _______, \
143                 _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END \
144         ),
145
146         /* Adjust (Lower + Raise)
147          * ,-----------------------------------------------------------------------------------.
148          * |      | Reset|      |      |      |      |      |      |      |      |      |  Del |
149          * |------+------+------+------+------+-------------+------+------+------+------+------|
150          * |      |      |      |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak|      |      |
151          * |------+------+------+------+------+------|------+------+------+------+------+------|
152          * |      |      |      |      |      |      |      |      |      |      |      |      |
153          * |------+------+------+------+------+------+------+------+------+------+------+------|
154          * |      |      |      |      |      |             |      |      |      |      |      |
155          * `-----------------------------------------------------------------------------------'
156          */
157         [_ADJUST] =  KEYMAP( \
158                 BL_TOGG, RESET,   _______, KC_MRWD, KC_MPLY, KC_MFFD, KC_PSCR, _______, KC_MUTE, KC_VOLD, KC_VOLU, KC_DEL, \
159                 BL_STEP, RGB_MOD, _______, AU_ON,   AU_OFF,  AG_NORM, AG_SWAP, QWERTY,  COLEMAK, DVORAK,  _______, _______, \
160                 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
161                 _______, KC_PSCR, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
162         )
163 };
164
165 const uint16_t PROGMEM fn_actions[] = {
166
167 };
168
169 // Setting ADJUST layer RGB back to default
170 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
171   if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
172 #ifdef RGBLIGHT_ENABLE
173     rgblight_mode(RGB_current_mode);
174 #endif
175     layer_on(layer3);
176   } else {
177     layer_off(layer3);
178   }
179 }
180
181 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
182 {
183   // MACRODOWN only works in this function
184       switch(id) {
185         case 0:
186           if (record->event.pressed) {
187             register_code(KC_RSFT);
188           } else {
189             unregister_code(KC_RSFT);
190           }
191         break;
192       }
193     return MACRO_NONE;
194 };
195
196
197 void matrix_init_user(void) {
198
199 }
200
201 void matrix_scan_user(void) {
202
203 }
204
205 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
206   switch (keycode) {
207     case QWERTY:
208       if (record->event.pressed) {
209         #ifdef AUDIO_ENABLE
210           PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
211         #endif
212 //        persistent_default_layer_set(1UL<<_QWERTY);
213       }
214       return false;
215       break;
216     case COLEMAK:
217       if (record->event.pressed) {
218         #ifdef AUDIO_ENABLE
219           PLAY_NOTE_ARRAY(tone_colemak, false, 0);
220         #endif
221 //        persistent_default_layer_set(1UL<<_COLEMAK);
222       }
223       return false;
224       break;
225     case DVORAK:
226       if (record->event.pressed) {
227         #ifdef AUDIO_ENABLE
228           PLAY_NOTE_ARRAY(tone_dvorak, false, 0);
229         #endif
230 //        persistent_default_layer_set(1UL<<_DVORAK);
231       }
232       return false;
233       break;
234     case LOWER:
235         if (record->event.pressed) {
236             //not sure how to have keyboard check mode and set it to a variable, so my work around
237             //uses another variable that would be set to true after the first time a reactive key is pressed.
238             if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
239             } else {
240                 TOG_STATUS = !TOG_STATUS;
241 #ifdef RGBLIGHT_ENABLE
242                 rgblight_mode(16);
243 #endif
244             }
245             layer_on(_LOWER);
246             update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
247         } else {
248 #ifdef RGBLIGHT_ENABLE
249             rgblight_mode(RGB_current_mode);   // revert RGB to initial mode prior to RGB mode change
250 #endif
251             TOG_STATUS = false;
252             layer_off(_LOWER);
253             update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
254         }
255         return false;
256         break;
257     case RAISE:
258         if (record->event.pressed) {
259             //not sure how to have keyboard check mode and set it to a variable, so my work around
260             //uses another variable that would be set to true after the first time a reactive key is pressed.
261             if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
262             } else {
263                 TOG_STATUS = !TOG_STATUS;
264 #ifdef RGBLIGHT_ENABLE
265                 rgblight_mode(15);
266 #endif
267             }
268             layer_on(_RAISE);
269             update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
270         } else {
271 #ifdef RGBLIGHT_ENABLE
272             rgblight_mode(RGB_current_mode);  // revert RGB to initial mode prior to RGB mode change
273 #endif
274             layer_off(_RAISE);
275             TOG_STATUS = false;
276             update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
277         }
278         return false;
279         break;
280     case ADJUST:
281         // FIXME add RGB feedback
282         if (record->event.pressed) {
283             layer_on(_ADJUST);
284         } else {
285             layer_off(_ADJUST);
286         }
287         return false;
288         break;
289     case BL_TOGG:
290 #ifdef BACKLIGHT_ENABLE
291         if (record->event.pressed) {
292             print("Enabling backlight\n");
293             backlight_init_ports();
294         }
295 #endif
296         return false;
297         break;
298     case BL_STEP:
299         if (record->event.pressed) {
300             print("Stepping backlight\n");
301 #ifdef BACKLIGHT_ENABLE
302             print("Really stepping backlight\n");
303             backlight_step();
304 #endif
305
306         }
307         return false;
308         break;
309         //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released
310 #ifdef RGBLIGHT_ENABLE
311     case RGB_MOD:
312         if (record->event.pressed) {
313             rgblight_mode(RGB_current_mode);
314             rgblight_step();
315             RGB_current_mode = rgblight_config.mode;
316         }
317         return false;
318         break;
319 #endif
320 //    case BL_INC:
321 //              meira_inc_backlight_level();
322 //            return false;
323 //              break;
324   }
325   return true;
326 }
327
328 void led_set_user(uint8_t usb_led) {
329
330 }