forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeymap.c
373 lines (335 loc) · 9.08 KB
/
keymap.c
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/* Copyright 2021-2022 Simon Arlott
*
* 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
#include <stdio.h>
#include "raw_hid.h"
#include "users/nomis/raw-identify.h"
//#include "users/nomis/unicode-input-mode.h"
#include "users/nomis/usb-events.h"
enum my_layers {
L_BASE,
L_AUTO,
L_REAL,
L_FUNC,
};
enum custom_keycodes {
CK_RATE = SAFE_RANGE,
CK_3_0S,
CK_6_0S,
CK_9_0S,
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap L_BASE: Base Layer (Default Layer)
* ,-------------------.
* |Esc |Calc|Func|Bksp|
* |-------------------|
* |NmLk| / | * | - |
* |-------------------|
* | 7 | 8 | 9 | |
* |--------------| + |
* | 4 | 5 | 6 | |
* |-------------------|
* | 1 | 2 | 3 | |
* |--------------|Ent |
* | 0 | . | |
* `-------------------'
*/
[L_BASE] = LAYOUT_numpad_6x4(
KC_ESC, KC_CALC, MO(L_FUNC),KC_BSPC,
KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS,
KC_7, KC_8, KC_9,
KC_4, KC_5, KC_6, KC_PPLS,
KC_1, KC_2, KC_3,
KC_0, KC_DOT, KC_PENT
),
/* Keymap L_AUTO: Auto Keypad Layer
* ,-------------------.
* | | | | |
* |-------------------|
* | | | | |
* |-------------------|
* | 7 | 8 | 9 | |
* |--------------| |
* | 4 | 5 | 6 | |
* |-------------------|
* | 1 | 2 | 3 | |
* |--------------| |
* | 0 | . | |
* `-------------------'
*/
[L_AUTO] = LAYOUT_numpad_6x4(
_______, _______, _______, _______,
_______, _______, _______, _______,
KC_P7, KC_P8, KC_P9,
KC_P4, KC_P5, KC_P6, _______,
KC_P1, KC_P2, KC_P3,
KC_P0, KC_PDOT, _______
),
/* Keymap L_REAL: Real Keypad Layer
* ,-------------------.
* | | | | |
* |-------------------|
* | | | | |
* |-------------------|
* | 7 | 8 | 9 | |
* |--------------| |
* | 4 | 5 | 6 | |
* |-------------------|
* | 1 | 2 | 3 | |
* |--------------| |
* | 0 | . | |
* `-------------------'
*/
[L_REAL] = LAYOUT_numpad_6x4(
_______, _______, _______, _______,
_______, _______, _______, _______,
KC_P7, KC_P8, KC_P9,
KC_P4, KC_P5, KC_P6, _______,
KC_P1, KC_P2, KC_P3,
KC_P0, KC_PDOT, _______
),
/* Keymap L_FUNC: Function Layer
* ,-------------------.
* |Rset| |Func| |
* |-------------------|
* |Real| | | |
* |-------------------|
* | | | 0*9| |
* |--------------| |
* | | | 0*6| |
* |-------------------|
* | | | 0*3| |
* |--------------|Rate|
* | | , | |
* `-------------------'
*/
[L_FUNC] = LAYOUT_numpad_6x4(
RESET, _______, _______, _______,
TG(L_REAL),_______, _______, _______,
_______, _______, CK_9_0S,
_______, _______, CK_6_0S, _______,
_______, _______, CK_3_0S,
_______, KC_COMM, CK_RATE
),
};
#define BRIGHTNESS 128
#undef HSV_ORANGE
#define HSV_ORANGE 10, 255, 255
#define HSV_LIGHT_BLUE 145, 255, 255
#define HSV_MID_BLUE1 153, 255, 255
#define HSV_MID_BLUE2 162, 255, 255
#define HSV_GREY 0, 0, BRIGHTNESS/2
#define HSV_DIM(x) x*0 + BRIGHTNESS
static const rgblight_segment_t PROGMEM os_none_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 1, HSV_DIM(HSV_CYAN)},
{1, 1, HSV_DIM(HSV_MAGENTA)},
{2, 1, HSV_GREY},
{3, 1, HSV_DIM(HSV_CYAN)},
{4, 1, HSV_DIM(HSV_MAGENTA)},
{5, 1, HSV_GREY}
);
static const rgblight_segment_t PROGMEM os_default_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLED_NUM, HSV_DIM(HSV_WHITE)});
static const rgblight_segment_t PROGMEM os_linux_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLED_NUM, HSV_DIM(HSV_YELLOW)});
static const rgblight_segment_t PROGMEM os_windows_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 1, HSV_DIM(HSV_MID_BLUE1)},
{1, 1, HSV_DIM(HSV_LIGHT_BLUE)},
{2, 1, HSV_DIM(HSV_MID_BLUE1)},
{3, 1, HSV_DIM(HSV_MID_BLUE2)},
{4, 1, HSV_DIM(HSV_BLUE)},
{5, 1, HSV_DIM(HSV_MID_BLUE2)}
);
static const rgblight_segment_t PROGMEM os_apple_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 1, HSV_DIM(HSV_GREEN)},
{1, 1, HSV_DIM(HSV_YELLOW)},
{2, 1, HSV_DIM(HSV_ORANGE)},
{3, 1, HSV_DIM(HSV_RED)},
{4, 1, HSV_DIM(HSV_PURPLE)},
{5, 1, HSV_DIM(HSV_LIGHT_BLUE)}
);
enum rgb_layers {
R_OS_NONE = 0,
R_OS_DEFAULT,
R_OS_LINUX,
R_OS_WINDOWS,
R_OS_MAC,
};
static const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
[R_OS_NONE] = os_none_layer,
[R_OS_DEFAULT] = os_default_layer,
[R_OS_LINUX] = os_linux_layer,
[R_OS_WINDOWS] = os_windows_layer,
[R_OS_MAC] = os_apple_layer
);
static inline void led_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
rgblight_sethsv_noeeprom(hue, sat, val == 255 ? BRIGHTNESS : 0);
}
static inline void led_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t idx) {
sethsv(hue, sat, val == 255 ? BRIGHTNESS : 0, (LED_TYPE *)&led[idx]);
}
static bool led_hsv_eq(HSV hsv1, uint16_t hue2, uint8_t sat2, uint8_t val2) {
return hsv1.h == hue2
&& hsv1.s == sat2
&& hsv1.v == val2;
}
static bool num_lock = false;
static bool real_layer = false;
static void update_leds(void) {
if (real_layer) {
if (num_lock) {
led_sethsv(HSV_ORANGE);
} else {
led_sethsv(HSV_RED);
}
} else {
if (num_lock) {
led_sethsv(HSV_GREEN);
} else {
led_sethsv(HSV_BLACK);
}
}
}
static void update_auto_layer(void) {
if (layer_state_is(L_AUTO) != num_lock) {
if (num_lock) {
layer_on(L_AUTO);
} else {
layer_off(L_AUTO);
}
}
}
static void set_os(enum raw_identify id) {
switch (id) {
case ID_LINUX:
//set_unicode_input_mode_noeeprom(UC_LNX);
break;
case ID_WINDOWS:
//set_unicode_input_mode_noeeprom(UC_WINC);
break;
case ID_MAC:
//set_unicode_input_mode_noeeprom(UC_MAC);
break;
default:
//set_unicode_input_mode_noeeprom(UC_LNX);
break;
}
}
static void blink_os(enum raw_identify id) {
switch (id) {
case ID_LINUX:
rgblight_blink_layer(R_OS_LINUX, 1000);
rgblight_unblink_all_but_layer(R_OS_LINUX);
break;
case ID_WINDOWS:
rgblight_blink_layer(R_OS_WINDOWS, 1000);
rgblight_unblink_all_but_layer(R_OS_WINDOWS);
break;
case ID_MAC:
rgblight_blink_layer(R_OS_MAC, 1000);
rgblight_unblink_all_but_layer(R_OS_MAC);
break;
default:
rgblight_blink_layer(R_OS_DEFAULT, 1000);
rgblight_unblink_all_but_layer(R_OS_DEFAULT);
break;
}
}
static void raw_identify_user(enum raw_identify id) {
set_os(id);
blink_os(id);
}
static void usb_event_user(enum usb_event event) {
switch (event) {
case USB_EVT_CONNECTED:
blink_os(ID_DEFAULT);
break;
case USB_EVT_DISCONNECTED:
set_os(ID_DEFAULT);
rgblight_blink_layer(R_OS_NONE, 1000);
rgblight_unblink_all_but_layer(R_OS_NONE);
break;
case USB_EVT_SUSPENDED:
break;
}
}
void keyboard_post_init_user(void) {
if (!rgblight_is_enabled() || rgblight_get_mode() != RGBLIGHT_MODE_STATIC_LIGHT || !led_hsv_eq(rgblight_get_hsv(), HSV_BLACK)) {
rgblight_enable_noeeprom();
rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
rgblight_sethsv(HSV_BLACK);
led_sethsv(HSV_CYAN);
wait_ms(1000);
}
if (is_backlight_enabled()) {
backlight_disable();
eeconfig_update_backlight_current();
led_sethsv(HSV_CYAN);
wait_ms(1000);
}
rgblight_layers = my_rgb_layers;
set_os(ID_DEFAULT);
num_lock = host_keyboard_led_state().num_lock;
real_layer = layer_state_is(L_REAL);
update_auto_layer();
update_leds();
}
bool led_update_user(led_t led_state) {
if (num_lock != led_state.num_lock) {
num_lock = led_state.num_lock;
update_auto_layer();
update_leds();
}
return true;
}
uint32_t layer_state_set_user(uint32_t state) {
if (real_layer != layer_state_cmp(state, L_REAL)) {
real_layer = layer_state_cmp(state, L_REAL);
update_leds();
}
return state;
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
case RESET:
rgblight_layers = NULL;
led_sethsv(HSV_PURPLE);
wait_ms(1);
break;
case CK_RATE:
{
char scan_rate[15];
snprintf(scan_rate, sizeof(scan_rate), " %lu", get_matrix_scan_rate());
send_string(scan_rate);
SEND_STRING(SS_TAP(X_ENTER));
}
return false;
case CK_9_0S:
case CK_6_0S:
case CK_3_0S:
for (uint8_t i = (keycode - CK_3_0S) + 1; i > 0; i--) {
SEND_STRING("000");
}
return false;
}
}
return true;
}
void housekeeping_task_user(void) {
usb_event_check();
}
void raw_hid_receive(uint8_t *data, uint8_t length) {
raw_hid_receive_identify(data, length);
}