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