summaryrefslogtreecommitdiff
path: root/keyboards/teleport/native/iso/keymaps/perfmode/keymap.c
blob: 3be8eec3ddf963f4af6fd8fa39d39d61ff105b95 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* Copyright 2023 Moritz Plattner
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include QMK_KEYBOARD_H

enum layers{
    BASE,
    GAME,
    PERF,
    _FN1,
    _FN2
};

/* Create a keycode to toggle RGB without writing to eeprom, important to enable/disable the non-eeprom-stored custom lighting on PERF layer */
enum my_keycodes {
  RGB_TOG_NO = SAFE_RANGE,
  RGB_M_2,
  RGB_M_3,
  RGB_M_4,
  RGB_M_5,
  RGB_M_6,
  RGB_M_7,
  RGB_M_8,
  RGB_M_9,
  RGB_M_0
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  switch (keycode) {
    case RGB_TOG_NO:
      if (record->event.pressed) {
        rgb_matrix_toggle_noeeprom();
      }
      return false;
    case RGB_M_2:
      if (record->event.pressed) {
        rgb_matrix_mode(RGB_MATRIX_ALPHAS_MODS);
      }
      return false;
    case RGB_M_3:
      if (record->event.pressed) {
        rgb_matrix_mode(RGB_MATRIX_BREATHING);
      }
      return false;
    case RGB_M_4:
      if (record->event.pressed) {
        rgb_matrix_mode(RGB_MATRIX_CYCLE_UP_DOWN);
      }
      return false;
    case RGB_M_5:
      if (record->event.pressed) {
        rgb_matrix_mode(RGB_MATRIX_CYCLE_ALL);
      }
      return false;
    case RGB_M_6:
      if (record->event.pressed) {
        rgb_matrix_mode(RGB_MATRIX_CYCLE_SPIRAL);
      }
      return false;
    case RGB_M_7:
      if (record->event.pressed) {
        rgb_matrix_mode(RGB_MATRIX_TYPING_HEATMAP);
      }
      return false;
    case RGB_M_8:
      if (record->event.pressed) {
        rgb_matrix_mode(RGB_MATRIX_SOLID_REACTIVE);
      }
      return false;
    case RGB_M_9:
      if (record->event.pressed) {
        rgb_matrix_mode(RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE);
      }
      return false;
    case RGB_M_0:
      if (record->event.pressed) {
        rgb_matrix_mode(RGB_MATRIX_CUSTOM_SINGLE_COLOR_RAINDROPS);
      }
      return false;
    default:
      return true; // Process all other keycodes normally
  }
}

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

    [BASE] = LAYOUT_75_iso(    /* keymap for layer 0 */
        KC_ESC,  KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12, KC_F13, KC_PSCR,   KC_DEL,
        KC_GRV,  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_PGUP,
        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_PGDN,
        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_NUHS,      KC_ENT,      KC_HOME,
        KC_LSFT, KC_NUBS, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_RSFT,          KC_UP,   KC_END,
        KC_LCTL, KC_LGUI, KC_LALT,                            KC_SPC,                             KC_RALT, MO(_FN1),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
    ),

    [GAME] = LAYOUT_75_iso(    /* keymap for layer 1 - GAME disables WIN key and has RGB layer indicators */
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                   KC_TRNS,
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,          KC_TRNS, KC_TRNS,
        KC_TRNS, KC_NO,   KC_TRNS,                            KC_TRNS,                            KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
    ),

    [PERF] = LAYOUT_75_iso(    /* keymap for layer 2 - PERF has a static LED display to increase matrix scan rates */
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                   KC_TRNS,
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,          KC_TRNS, KC_TRNS,
        KC_TRNS, KC_NO,   KC_TRNS,                            KC_TRNS,                            KC_TRNS, MO(_FN2),KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
    ),

    [_FN1] = LAYOUT_75_iso(    /* keymap for layer 3 */
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_TOG, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_TRNS, KC_TRNS,
        KC_TRNS, RGB_M_P, RGB_M_2, RGB_M_3, RGB_M_4, RGB_M_5, RGB_M_6, RGB_M_7, RGB_M_8, RGB_M_9, RGB_M_0, KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,
        RGB_TOG, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                   KC_TRNS,
        KC_TRNS, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,
        KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, MAGIC_TOGGLE_NKRO,KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
        KC_TRNS, TG(GAME),KC_TRNS,                            TO(PERF),                           KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
    ),

    [_FN2] = LAYOUT_75_iso(    /* keymap for layer 4 */
        KC_TRNS,   KC_TRNS, KC_TRNS, KC_TRNS, RGB_TOG_NO,KC_NO, KC_NO,   KC_MPRV, KC_MPLY, KC_MNXT, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_TRNS, KC_TRNS,
        KC_TRNS,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,
        RGB_TOG_NO,KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                   KC_TRNS,
        KC_TRNS,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,      KC_TRNS,     KC_TRNS,
        KC_TRNS,   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,          KC_TRNS, KC_TRNS,
        KC_TRNS,   KC_NO,   KC_TRNS,                            TG(PERF),                           KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
    ),
};

/* RGB matrix indicator code
It reads the current matrix color, offsets the hue by 30, 
and sets val to either 255 or, if defined, RGB_MATRIX_MAXIMUM_BRIGHTNESS
This is applied to both caps lock, and other indicator keys for layer 1 */

bool rgb_matrix_indicators_user(void) {
  /* Layer 2 (perf mode on this keymap) is not supposed to have LED refreshes, hence excluded */
  if (!IS_LAYER_ON(2)) {
    HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS};
    RGB rgb_ind = hsv_to_rgb(hsv_ind);

    /* Sets Caps to different color as indicator. If RGB mode is rain, and caps indicator is off, the LED will always be off.
    This is to avoid having the LED persist on until the animation randomly refreshes it. */
    if (host_keyboard_led_state().caps_lock) {
      rgb_matrix_set_color(CAPS_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b);
    } else if (rgb_matrix_get_mode() == 10) {
      rgb_matrix_set_color(CAPS_LED_INDEX, 0, 0, 0);
    }

    /* Sets W, A, S, D, LGUI to a different color as layer indicator */
    if(IS_LAYER_ON(1)) {
      HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS};
      RGB rgb_ind = hsv_to_rgb(hsv_ind);

      rgb_matrix_set_color(W_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b);
      rgb_matrix_set_color(A_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b);
      rgb_matrix_set_color(S_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b);
      rgb_matrix_set_color(D_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b);
      rgb_matrix_set_color(WIN_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b);
    }
  }
  return true;
}

layer_state_t layer_state_set_user(layer_state_t state) {
  /* Set LEDs to "GAME_MODE" custom animation when entering layer 2 (perf mode), reload matrix from eeprom when exiting */
  if(IS_LAYER_ON_STATE(state, 2)) {
    rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_STATIC_GAME_MODE);
  } else {
    rgb_matrix_reload_from_eeprom();
  }
    
  /* If reverting to base layer (no special LED effects) and single color rain is on, set "layer 1" mods back to matrix color to avoid single key persistence */
  if(!IS_LAYER_ON_STATE(state, 2) && !IS_LAYER_ON_STATE(state, 1) && rgb_matrix_get_mode() == 10) {
    HSV hsv_mat = rgb_matrix_get_hsv();
    RGB rgb_mat = hsv_to_rgb(hsv_mat);

    rgb_matrix_set_color(W_LED_INDEX, rgb_mat.r, rgb_mat.g, rgb_mat.b);
    rgb_matrix_set_color(A_LED_INDEX, rgb_mat.r, rgb_mat.g, rgb_mat.b);
    rgb_matrix_set_color(S_LED_INDEX, rgb_mat.r, rgb_mat.g, rgb_mat.b);
    rgb_matrix_set_color(D_LED_INDEX, rgb_mat.r, rgb_mat.g, rgb_mat.b);
    rgb_matrix_set_color(WIN_LED_INDEX, rgb_mat.r, rgb_mat.g, rgb_mat.b);
  }
  return state;
}