keymap.c (10212B)
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 #define _QWERTY 0 24 #define _LOWER 1 25 #define _RAISE 2 26 #define _ADJUST 3 27 28 enum custom_keycodes { 29 LOWER = SAFE_RANGE, 30 RAISE, 31 ADJUST, 32 }; 33 34 // define variables for reactive RGB 35 bool TOG_STATUS = false; 36 int RGB_current_mode; 37 38 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 39 /* Qwerty 40 * ,-----------------------------------------------------------------------------------. 41 * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp | 42 * |------+------+------+------+------+-------------+------+------+------+------+------| 43 * | Esc | A | S | D | F | G | H | J | K | L | ; | ' | 44 * |------+------+------+------+------+------|------+------+------+------+------+------| 45 * | Shift| Z | X | C | V | B | N | M | , | . |//GUI |Enter | 46 * |------+------+------+------+------+------+------+------+------+------+------+------| 47 * | Ctrl | GUI | Alt | GUI |Lower |Space |Enter |Raise | Left | Down | Up |Right | 48 * `-----------------------------------------------------------------------------------' 49 */ 50 [_QWERTY] = LAYOUT( 51 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, 52 KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, 53 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, GUI_T(KC_SLSH), KC_ENT, 54 KC_LCTL, KC_LGUI, KC_LALT, KC_RGUI, LOWER, KC_SPC, KC_ENT, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT 55 ), 56 57 /* Lower 58 * ,-----------------------------------------------------------------------------------. 59 * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | DEL | 60 * |------+------+------+------+------+-------------+------+------+------+------+------| 61 * | | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | 62 * |------+------+------+------+------+------|------+------+------+------+------+------| 63 * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | | | | 64 * |------+------+------+------+------+------+------+------+------+------+------+------| 65 * | | | | | | | | | Home | PgUp | PgDn | End | 66 * `-----------------------------------------------------------------------------------' 67 */ 68 [_LOWER] = LAYOUT( 69 KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL, 70 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, 71 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), _______, _______, _______, 72 _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END 73 ), 74 75 /* Raise 76 * ,-----------------------------------------------------------------------------------. 77 * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | DEL | 78 * |------+------+------+------+------+-------------+------+------+------+------+------| 79 * | | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ | 80 * |------+------+------+------+------+------|------+------+------+------+------+------| 81 * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / | | | | 82 * |------+------+------+------+------+------+------+------+------+------+------+------| 83 * | | | | | | | | | Home | PgUp | PgDn | End | 84 * `-----------------------------------------------------------------------------------' 85 */ 86 [_RAISE] = LAYOUT( 87 KC_GRV , KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, 88 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, 89 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, _______, _______, _______, 90 _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END 91 ), 92 93 /* Adjust (Lower + Raise) 94 * ,-----------------------------------------------------------------------------------. 95 * | | Reset| | | | | | | | | | Del | 96 * |------+------+------+------+------+-------------+------+------+------+------+------| 97 * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty| | | | | 98 * |------+------+------+------+------+------|------+------+------+------+------+------| 99 * | | | | | | | | | | | | | 100 * |------+------+------+------+------+------+------+------+------+------+------+------| 101 * | | | | | | | | | | | | 102 * `-----------------------------------------------------------------------------------' 103 */ 104 [_ADJUST] = LAYOUT( 105 BL_TOGG, QK_BOOT, _______, KC_MRWD, KC_MPLY, KC_MFFD, KC_PSCR, _______, KC_MUTE, KC_VOLD, KC_VOLU, KC_DEL, 106 BL_STEP, UG_NEXT, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, _______, 107 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, 108 _______, KC_PSCR, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ 109 ) 110 }; 111 112 // Setting ADJUST layer RGB back to default 113 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) { 114 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { 115 #ifdef RGBLIGHT_ENABLE 116 rgblight_mode(RGB_current_mode); 117 #endif 118 layer_on(layer3); 119 } else { 120 layer_off(layer3); 121 } 122 } 123 124 bool process_record_user(uint16_t keycode, keyrecord_t *record) { 125 switch (keycode) { 126 case LOWER: 127 if (record->event.pressed) { 128 //not sure how to have keyboard check mode and set it to a variable, so my work around 129 //uses another variable that would be set to true after the first time a reactive key is pressed. 130 if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false 131 } else { 132 TOG_STATUS = !TOG_STATUS; 133 #ifdef RGBLIGHT_ENABLE 134 rgblight_mode(16); 135 #endif 136 } 137 layer_on(_LOWER); 138 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); 139 } else { 140 #ifdef RGBLIGHT_ENABLE 141 rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change 142 #endif 143 TOG_STATUS = false; 144 layer_off(_LOWER); 145 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); 146 } 147 return false; 148 break; 149 case RAISE: 150 if (record->event.pressed) { 151 //not sure how to have keyboard check mode and set it to a variable, so my work around 152 //uses another variable that would be set to true after the first time a reactive key is pressed. 153 if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false 154 } else { 155 TOG_STATUS = !TOG_STATUS; 156 #ifdef RGBLIGHT_ENABLE 157 rgblight_mode(15); 158 #endif 159 } 160 layer_on(_RAISE); 161 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); 162 } else { 163 #ifdef RGBLIGHT_ENABLE 164 rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change 165 #endif 166 layer_off(_RAISE); 167 TOG_STATUS = false; 168 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); 169 } 170 return false; 171 break; 172 case ADJUST: 173 // FIXME add RGB feedback 174 if (record->event.pressed) { 175 layer_on(_ADJUST); 176 } else { 177 layer_off(_ADJUST); 178 } 179 return false; 180 break; 181 case BL_STEP: 182 if (record->event.pressed) { 183 print("Stepping backlight\n"); 184 #ifdef BACKLIGHT_ENABLE 185 print("Really stepping backlight\n"); 186 backlight_step(); 187 #endif 188 189 } 190 return false; 191 break; 192 //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 193 #ifdef RGBLIGHT_ENABLE 194 case QK_UNDERGLOW_MODE_NEXT: 195 if (record->event.pressed) { 196 rgblight_mode(RGB_current_mode); 197 rgblight_step(); 198 RGB_current_mode = rgblight_config.mode; 199 } 200 return false; 201 break; 202 #endif 203 // case BL_UP: 204 // meira_inc_backlight_level(); 205 // return false; 206 // break; 207 } 208 return true; 209 }