diff options
author | elmo-space <lorwel@mailbox.org> | 2020-06-10 23:33:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-10 14:33:26 -0700 |
commit | 7e8dc2e570e21a018b3cfdf860ef03dd8d2a20f3 (patch) | |
tree | 5a1776535dcd4441b5ba2f21302acb7332255535 /keyboards/xd002/keymaps | |
parent | 263536586daebcf09d31ab78a623da9366ebf7f7 (diff) | |
download | qmk_firmware-7e8dc2e570e21a018b3cfdf860ef03dd8d2a20f3.tar.gz qmk_firmware-7e8dc2e570e21a018b3cfdf860ef03dd8d2a20f3.zip |
[Keymap] Add dual layer keymap for xd002 macropad (#9222)
Co-authored-by: Joel Challis <git@zvecr.com>
Co-authored-by: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'keyboards/xd002/keymaps')
-rw-r--r-- | keyboards/xd002/keymaps/multilayer_rgb/config.h | 22 | ||||
-rw-r--r-- | keyboards/xd002/keymaps/multilayer_rgb/keymap.c | 173 | ||||
-rw-r--r-- | keyboards/xd002/keymaps/multilayer_rgb/rgblite.h | 9 | ||||
-rw-r--r-- | keyboards/xd002/keymaps/multilayer_rgb/rules.mk | 2 |
4 files changed, 206 insertions, 0 deletions
diff --git a/keyboards/xd002/keymaps/multilayer_rgb/config.h b/keyboards/xd002/keymaps/multilayer_rgb/config.h new file mode 100644 index 0000000000..f478baf3b3 --- /dev/null +++ b/keyboards/xd002/keymaps/multilayer_rgb/config.h @@ -0,0 +1,22 @@ +/* Copyright 2020 elmo-space<mail@elmo.space> + * + * 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/>. + */ +#pragma once + +/*enable layers*/ +#undef NO_ACTION_LAYER + +/* increase tap duration (spotify doesn't like very short taps)*/ +#define TAP_CODE_DELAY 100 diff --git a/keyboards/xd002/keymaps/multilayer_rgb/keymap.c b/keyboards/xd002/keymaps/multilayer_rgb/keymap.c new file mode 100644 index 0000000000..01a96119e5 --- /dev/null +++ b/keyboards/xd002/keymaps/multilayer_rgb/keymap.c @@ -0,0 +1,173 @@ +/* Copyright 2020 elmo-space<mail@elmo.space> + * + * 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 "rgblite.h" + +// Defines names for use in layer keycodes and the keymap +enum layer_names { + _BASE, + _FUNC, +}; + +// set your keycodes here +#define layer1_left KC_PAUS +#define layer1_right KC_MPLY +#define layer2_left KC_MPRV +#define layer2_right KC_MNXT + + +enum custom_keycodes { + LEFT1 = SAFE_RANGE, + RIGHT1, + LEFT2, + RIGHT2 +}; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_BASE] = LAYOUT( + LEFT1, RIGHT1 + ), + [_FUNC] = LAYOUT( + LEFT2, RIGHT2 + ) +}; + +static bool key1_down = false; +static bool key2_down = false; +static char layer_switched = 0; // this prevents the individual keys getting triggered after a layerchange + +bool process_record_user(uint16_t keycode, keyrecord_t *record) +{ + switch (keycode) + { + case LEFT1: + if (record->event.pressed) + { + if (key2_down) + { + layer_on(1); + layer_switched = 2; + return false; + break; + } + key1_down = true; + } + else { + if (layer_switched > 0) { + --layer_switched; + key1_down = false; + } + else { + tap_code(layer1_left); + key1_down = false; + } + } + return false; + break; + case RIGHT1: + if (record->event.pressed) + { + if (key1_down) + { + layer_on(1); + layer_switched = 2; + return false; + break; + } + key2_down = true; + } + else { + if (layer_switched > 0) { + --layer_switched; + key2_down = false; + } + else { + tap_code(layer1_right); + key2_down = false; + } + } + return false; + break; + case LEFT2: + if (record->event.pressed) + { + if (key2_down) + { + layer_off(1); + layer_switched = 2; + return false; + break; + } + key1_down = true; + } + else { + if (layer_switched > 0) { + --layer_switched; + key1_down = false; + } + else { + tap_code(layer2_left); + key1_down = false; + } + } + return false; + break; + case RIGHT2: + if (record->event.pressed) + { + if (key1_down) + { + layer_off(1); + layer_switched = 2; + return false; + break; + } + key2_down = true; + } + else { + if (layer_switched > 0) { + --layer_switched; + key2_down = false; + } + else { + tap_code(layer2_right); + key2_down = false; + } + } + return false; + break; + } + return true; +}; + +// layer colors +layer_state_t layer_state_set_user(layer_state_t state) { + switch (get_highest_layer(state)) { + case _FUNC: + rgblight_setrgb_red(); + break; + default: // for any other layers, or the default layer + rgblight_setrgb_green(); + break; + } + return state; +} + +// default color +void keyboard_post_init_user(void) { + rgblight_setrgb_green(); +} diff --git a/keyboards/xd002/keymaps/multilayer_rgb/rgblite.h b/keyboards/xd002/keymaps/multilayer_rgb/rgblite.h new file mode 100644 index 0000000000..ddc61d5f43 --- /dev/null +++ b/keyboards/xd002/keymaps/multilayer_rgb/rgblite.h @@ -0,0 +1,9 @@ +#pragma once + +#include "ws2812.h" +#include "rgblight_list.h" + +static inline void rgblight_setrgb(uint8_t _r, uint8_t _g, uint8_t _b) { + LED_TYPE leds[RGBLED_NUM] = {{.r = _r, .g = _g, .b = _b}, {.r = _r, .g = _g, .b = _b}}; + ws2812_setleds(leds, RGBLED_NUM); +} diff --git a/keyboards/xd002/keymaps/multilayer_rgb/rules.mk b/keyboards/xd002/keymaps/multilayer_rgb/rules.mk new file mode 100644 index 0000000000..69d592aa4b --- /dev/null +++ b/keyboards/xd002/keymaps/multilayer_rgb/rules.mk @@ -0,0 +1,2 @@ +SRC += ws2812.c +EXTRAKEY_ENABLE = yes |