summaryrefslogtreecommitdiff
path: root/keyboards/mixi/keymaps/default/keymap.c
blob: 22877c1101d95370d883b2e8518111f29e544c2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include QMK_KEYBOARD_H

// please change this value to the desired layer definitions
#define LAYERNUM 3

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

    /*
     * | Knob: Layer +/-                                |
     * .------------------------------------------------.
     * | Volume Mute | Media Play/Pause | Hold: Layer 2 |
     * |-------------|------------------|---------------|
     * | Media Prev  | Up               | Media Next    |
     * |-------------|------------------|---------------|
     * | Left        | Down             | Right         |
     * '------------------------------------------------'
     */
    [0] =
        LAYOUT(
                KC_MUTE,  KC_MPLY, MO(2)  ,
                KC_MPRV,  KC_UP  , KC_MNXT,
                KC_LEFT, KC_DOWN , KC_RGHT
              ),

    /*
     * | Knob: Layer +/-                                   |
     * .---------------------------------------------------.
     * | RGB Toggle     | Media Play/Pause | Hold: Layer 2 |
     * |----------------|------------------|---------------|
     * | Media Previous | RGB Bright+      | Media Next    |
     * |----------------|------------------|---------------|
     * | RGB Anim-      | RGB Bright-      | RGB Anim+     |
     * '---------------------------------------------------'
     */
    [1] =
        LAYOUT(
                RGB_TOG , KC_TRNS, KC_TRNS,
                KC_TRNS , RGB_VAI, KC_TRNS,
                RGB_RMOD, RGB_VAD, RGB_MOD
              ),

    /*
     * | Knob: Volume +/-                     |
     * .--------------------------------------.
     * | N/A          | N/A   | Hold: Layer 2 |
     * |--------------|-------|---------------|
     * | QK_BOOT EEPROM | QK_BOOT | DEBUG MODE    |
     * |--------------|-------|---------------|
     * | N/A          | N/A   | N/A           |
     * '--------------------------------------'
     */
    [2] =
        LAYOUT(
                KC_NO  , KC_NO, KC_TRNS,
                EEP_RST, QK_BOOT, DEBUG  ,
                KC_NO  , KC_NO, KC_NO
              )

};

const rgblight_segment_t PROGMEM _base_layer[] = RGBLIGHT_LAYER_SEGMENTS(
        {0, RGBLED_NUM, HSV_BLUE}
        );
const rgblight_segment_t PROGMEM _middle_layer[] = RGBLIGHT_LAYER_SEGMENTS(
        {0, RGBLED_NUM, HSV_GREEN}
        );
const rgblight_segment_t PROGMEM _top_layer[] = RGBLIGHT_LAYER_SEGMENTS(
        {0, RGBLED_NUM, HSV_RED}
        );

const rgblight_segment_t* const PROGMEM _rgb_layers[] =
RGBLIGHT_LAYERS_LIST(
        _base_layer,
        _middle_layer,
        _top_layer
        );

void keyboard_post_init_user(void) {
    rgblight_layers = _rgb_layers;
}

layer_state_t layer_state_set_user(layer_state_t state) {

    switch (get_highest_layer(state)) {
        case 0:
            rgblight_blink_layer(0, 500);
            break;
        case 1:
            rgblight_blink_layer(1, 500);
            break;
        case 2:
            rgblight_blink_layer(2, 500);
            break;
    }
    return state;
}

uint8_t selected_layer = 0;
bool encoder_update_user(uint8_t index, bool clockwise) {
    if (index == 0) {
        if (layer_state_is(2)) {
            if (clockwise) {
                tap_code(KC_VOLU);
            } else {
                tap_code(KC_VOLD);
            }
        } else {
            if (clockwise && selected_layer < (LAYERNUM-2)) { /* Prevent switch to layer 2 using encoder */
                selected_layer++;
                layer_move(selected_layer);
            } else if (!clockwise && selected_layer > 0) {
                selected_layer--;
                layer_move(selected_layer);
            }
        }
    }
    return true;
}