qmk_firmware

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

keymap.c (2715B)


      1 /* Copyright 2020-2021 SergioPoverony
      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  
     17  #include QMK_KEYBOARD_H
     18 
     19 /* enum layers num */
     20 enum layer_number {
     21     _HOME = 0,
     22     _RED,
     23     _BLUE,
     24     _GREEN
     25 };
     26 
     27 /* Encoder function with layers function */
     28 bool encoder_update_user(uint8_t index, bool clockwise) {
     29     if (index == 0) {
     30         switch (get_highest_layer(layer_state)) {
     31 			
     32             case _HOME:
     33                 if (clockwise) {
     34                     tap_code(KC_VOLU);
     35                 } else {
     36                     tap_code(KC_VOLD);
     37                 }
     38                 break;
     39 				
     40             case _RED:
     41                 if (clockwise) {
     42                     tap_code(MS_WHLU);
     43                 } else {
     44                     tap_code(MS_WHLD);
     45                 }
     46                 break;		
     47 				
     48             case _BLUE:
     49 			    if (clockwise) {
     50                     tap_code(KC_PGUP);
     51                 } else {
     52                     tap_code(KC_PGDN);
     53                 }
     54                 break;
     55 				
     56             case _GREEN:
     57             default:
     58                 if (clockwise) {
     59 					tap_code16(KC_LEFT);
     60                 } else {
     61 					tap_code16(KC_RIGHT);
     62                 }
     63                 break;
     64         }
     65     }
     66     return true;
     67 }
     68 
     69 
     70 /* Layout */
     71 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     72   [_HOME] = LAYOUT(
     73     KC_1, KC_2, KC_3, KC_4,
     74 									TO(_RED), 
     75 	KC_5, KC_6, KC_7, KC_8
     76     ),
     77 	
     78   [_RED] = LAYOUT(
     79     KC_Q, KC_W, KC_E, KC_R,
     80 									TO(_BLUE), 
     81 	KC_A, KC_S, KC_D, KC_F
     82     ),
     83 	
     84   [_BLUE] = LAYOUT(
     85     KC_1, KC_2, KC_3, KC_4,
     86 									TO(_GREEN), 
     87 	KC_5, KC_6, KC_7, KC_8
     88     ),
     89 	
     90   [_GREEN] = LAYOUT(
     91     KC_1, KC_2, KC_3, KC_4,
     92 									TO(_HOME), 
     93 	KC_5, KC_6, KC_7, KC_8
     94     ),
     95 };
     96 
     97  	
     98 /* Select led layout */
     99 layer_state_t layer_state_set_user(layer_state_t state)
    100 {
    101     turn_off_leds();
    102 
    103     switch (get_highest_layer(state))
    104     {
    105 		case _HOME:
    106 		turn_on_led(RED_LED);
    107 		turn_on_led(BLUE_LED);
    108 		break;
    109 
    110 		case _RED:
    111 		turn_on_led(RED_LED);
    112 		break;
    113 
    114 		case _BLUE:
    115 		turn_on_led(BLUE_LED);
    116 		break;
    117 
    118 		case _GREEN:
    119 		turn_on_led(GREEN_LED);
    120 		break;
    121 	}
    122     return state;
    123 };