qmk_firmware

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

keymap.c (3702B)


      1 #include QMK_KEYBOARD_H
      2 
      3 // please change this value to the desired layer definitions
      4 #define LAYERNUM 3
      5 
      6 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
      7 
      8     /*
      9      * | Knob: Layer +/-                                |
     10      * .------------------------------------------------.
     11      * | Volume Mute | Media Play/Pause | Hold: Layer 2 |
     12      * |-------------|------------------|---------------|
     13      * | Media Prev  | Up               | Media Next    |
     14      * |-------------|------------------|---------------|
     15      * | Left        | Down             | Right         |
     16      * '------------------------------------------------'
     17      */
     18     [0] =
     19         LAYOUT(
     20                 KC_MUTE,  KC_MPLY, MO(2)  ,
     21                 KC_MPRV,  KC_UP  , KC_MNXT,
     22                 KC_LEFT, KC_DOWN , KC_RGHT
     23               ),
     24 
     25     /*
     26      * | Knob: Layer +/-                                   |
     27      * .---------------------------------------------------.
     28      * | RGB Toggle     | Media Play/Pause | Hold: Layer 2 |
     29      * |----------------|------------------|---------------|
     30      * | Media Previous | RGB Bright+      | Media Next    |
     31      * |----------------|------------------|---------------|
     32      * | RGB Anim-      | RGB Bright-      | RGB Anim+     |
     33      * '---------------------------------------------------'
     34      */
     35     [1] =
     36         LAYOUT(
     37                 UG_TOGG , KC_TRNS, KC_TRNS,
     38                 KC_TRNS , UG_VALU, KC_TRNS,
     39                 UG_PREV,  UG_VALD, UG_NEXT
     40               ),
     41 
     42     /*
     43      * | Knob: Volume +/-                     |
     44      * .--------------------------------------.
     45      * | N/A          | N/A   | Hold: Layer 2 |
     46      * |--------------|-------|---------------|
     47      * | Clear EEPROM | Bootloader | Debug    |
     48      * |--------------|-------|---------------|
     49      * | N/A          | N/A   | N/A           |
     50      * '--------------------------------------'
     51      */
     52     [2] =
     53         LAYOUT(
     54                 KC_NO  , KC_NO, KC_TRNS,
     55                 EE_CLR,  QK_BOOT, DB_TOGG,
     56                 KC_NO  , KC_NO, KC_NO
     57               )
     58 
     59 };
     60 
     61 const rgblight_segment_t PROGMEM _base_layer[] = RGBLIGHT_LAYER_SEGMENTS(
     62         {0, RGBLIGHT_LED_COUNT, HSV_BLUE}
     63         );
     64 const rgblight_segment_t PROGMEM _middle_layer[] = RGBLIGHT_LAYER_SEGMENTS(
     65         {0, RGBLIGHT_LED_COUNT, HSV_GREEN}
     66         );
     67 const rgblight_segment_t PROGMEM _top_layer[] = RGBLIGHT_LAYER_SEGMENTS(
     68         {0, RGBLIGHT_LED_COUNT, HSV_RED}
     69         );
     70 
     71 const rgblight_segment_t* const PROGMEM _rgb_layers[] =
     72 RGBLIGHT_LAYERS_LIST(
     73         _base_layer,
     74         _middle_layer,
     75         _top_layer
     76         );
     77 
     78 void keyboard_post_init_user(void) {
     79     rgblight_layers = _rgb_layers;
     80 }
     81 
     82 layer_state_t layer_state_set_user(layer_state_t state) {
     83 
     84     switch (get_highest_layer(state)) {
     85         case 0:
     86             rgblight_blink_layer(0, 500);
     87             break;
     88         case 1:
     89             rgblight_blink_layer(1, 500);
     90             break;
     91         case 2:
     92             rgblight_blink_layer(2, 500);
     93             break;
     94     }
     95     return state;
     96 }
     97 
     98 uint8_t selected_layer = 0;
     99 bool encoder_update_user(uint8_t index, bool clockwise) {
    100     if (index == 0) {
    101         if (layer_state_is(2)) {
    102             if (clockwise) {
    103                 tap_code(KC_VOLU);
    104             } else {
    105                 tap_code(KC_VOLD);
    106             }
    107         } else {
    108             if (clockwise && selected_layer < (LAYERNUM-2)) { /* Prevent switch to layer 2 using encoder */
    109                 selected_layer++;
    110                 layer_move(selected_layer);
    111             } else if (!clockwise && selected_layer > 0) {
    112                 selected_layer--;
    113                 layer_move(selected_layer);
    114             }
    115         }
    116     }
    117     return true;
    118 }