qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

keymap.c (7214B)


      1 /* Copyright 2019 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 // define variables for reactive RGB
     42 bool TOG_STATUS = false;
     43 int RGB_current_mode;
     44 
     45 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     46         [_QWERTY] = LAYOUT_65_xt_ansi_split_space_split_bs(
     47         KC_F1, KC_F2,   KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6,KC_7,KC_8,KC_9,KC_0,KC_MINS,KC_EQL,KC_BSPC, KC_DEL, KC_PGUP,
     48         KC_F3, KC_F4,   KC_TAB,KC_Q,KC_W,KC_E,KC_R,KC_T,KC_Y,KC_U,KC_I,KC_O,KC_P,KC_LBRC,KC_RBRC,KC_BSLS, KC_PGDN,
     49         KC_F5, KC_F6,   KC_CAPS,KC_A,KC_S,KC_D,KC_F, KC_G, KC_H,KC_J,KC_K,KC_L, KC_SCLN,KC_QUOT,KC_ENT, KC_HOME,
     50         KC_F7, KC_F8,   KC_LSFT,KC_Z,KC_X,KC_C,KC_V,KC_B,KC_N,KC_M,KC_COMM,KC_DOT,KC_SLASH,KC_RSFT,KC_UP,KC_END,
     51         KC_F9, KC_F10,  KC_LCTL,KC_LGUI,KC_LALT, RAISE, KC_SPACE, LOWER, KC_RALT,KC_APP,KC_RCTL,KC_LEFT,KC_DOWN,KC_RIGHT),
     52 
     53         [_RAISE] = LAYOUT_65_xt_ansi_split_space_split_bs(
     54         UG_NEXT, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, _______,
     55         _______, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,
     56         _______, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,
     57         _______, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,
     58         _______, _______,  _______,_______,_______, _______, _______, _______, _______,_______,_______,_______,_______,_______),
     59 
     60         [_LOWER] = LAYOUT_65_xt_ansi_split_space_split_bs(
     61         UG_NEXT, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, _______,
     62         _______, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,
     63         _______, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,  _______,
     64         _______, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,
     65         _______, _______,  _______,_______,_______, _______, _______, _______, _______,_______,_______,_______,_______,_______),
     66 
     67         [_ADJUST] = LAYOUT_65_xt_ansi_split_space_split_bs(
     68         QK_BOOT, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, _______,
     69         _______, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,
     70         _______, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,  _______,
     71         _______, _______,   _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,
     72         _______, _______,  _______,_______,_______, _______, _______, _______, _______,_______,_______,_______,_______,_______)
     73 };
     74 
     75 // Setting ADJUST layer RGB back to default
     76 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
     77   if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
     78 #ifdef RGBLIGHT_ENABLE
     79     rgblight_mode(RGB_current_mode);
     80 #endif
     81     layer_on(layer3);
     82   } else {
     83     layer_off(layer3);
     84   }
     85 }
     86 
     87 #ifdef AUDIO_ENABLE
     88 
     89   float tone_qwerty[][2]     = SONG(QWERTY_SOUND);
     90 #endif
     91 
     92 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
     93   switch (keycode) {
     94     case LOWER:
     95         if (record->event.pressed) {
     96             //not sure how to have keyboard check mode and set it to a variable, so my work around
     97             //uses another variable that would be set to true after the first time a reactive key is pressed.
     98             if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
     99             } else {
    100                 TOG_STATUS = !TOG_STATUS;
    101 #ifdef RGBLIGHT_ENABLE
    102                 rgblight_mode(16);
    103 #endif
    104             }
    105             layer_on(_LOWER);
    106             update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    107         } else {
    108 #ifdef RGBLIGHT_ENABLE
    109             rgblight_mode(RGB_current_mode);   // revert RGB to initial mode prior to RGB mode change
    110 #endif
    111             TOG_STATUS = false;
    112             layer_off(_LOWER);
    113             update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    114         }
    115         return false;
    116         break;
    117     case RAISE:
    118         if (record->event.pressed) {
    119             //not sure how to have keyboard check mode and set it to a variable, so my work around
    120             //uses another variable that would be set to true after the first time a reactive key is pressed.
    121             if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
    122             } else {
    123                 TOG_STATUS = !TOG_STATUS;
    124 #ifdef RGBLIGHT_ENABLE
    125                 rgblight_mode(15);
    126 #endif
    127             }
    128             layer_on(_RAISE);
    129             update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    130         } else {
    131 #ifdef RGBLIGHT_ENABLE
    132             rgblight_mode(RGB_current_mode);  // revert RGB to initial mode prior to RGB mode change
    133 #endif
    134             layer_off(_RAISE);
    135             TOG_STATUS = false;
    136             update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    137         }
    138         return false;
    139         break;
    140     case ADJUST:
    141         // FIXME add RGB feedback
    142         if (record->event.pressed) {
    143             layer_on(_ADJUST);
    144         } else {
    145             layer_off(_ADJUST);
    146         }
    147         return false;
    148         break;
    149         break;
    150         //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
    151 #ifdef RGBLIGHT_ENABLE
    152     case QK_UNDERGLOW_MODE_NEXT:
    153         if (record->event.pressed) {
    154             rgblight_mode(RGB_current_mode);
    155             rgblight_step();
    156             RGB_current_mode = rgblight_config.mode;
    157         }
    158         return false;
    159         break;
    160 #endif
    161   }
    162   return true;
    163 }