From 113ab3f275e1777718da04b64bd950bc4ba2c52b Mon Sep 17 00:00:00 2001 From: Tero Paananen Date: Sun, 2 Aug 2020 22:40:31 -0400 Subject: [PATCH 1/8] Add keymap for DQM Design Spin macropad --- .../dmqdesign/spin/keymaps/gorbachev/config.h | 25 ++ .../dmqdesign/spin/keymaps/gorbachev/keymap.c | 252 ++++++++++++++++++ .../spin/keymaps/gorbachev/readme.md | 7 + .../dmqdesign/spin/keymaps/gorbachev/rules.mk | 3 + 4 files changed, 287 insertions(+) create mode 100644 keyboards/dmqdesign/spin/keymaps/gorbachev/config.h create mode 100644 keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c create mode 100644 keyboards/dmqdesign/spin/keymaps/gorbachev/readme.md create mode 100644 keyboards/dmqdesign/spin/keymaps/gorbachev/rules.mk diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/config.h b/keyboards/dmqdesign/spin/keymaps/gorbachev/config.h new file mode 100644 index 000000000000..10201015ee67 --- /dev/null +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/config.h @@ -0,0 +1,25 @@ +/* Copyright 2019-2020 DMQ Design + * + * 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 . + */ + +#pragma once + +#define RGBLIGHT_ANIMATIONS +#define RGBLIGHT_HUE_STEP 8 + +// Use one or the other, determines the orientation of +// the OLED display +// #define RIGHT_HAND +#define LEFT_HAND diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c new file mode 100644 index 000000000000..d0adf91aad94 --- /dev/null +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c @@ -0,0 +1,252 @@ +/* Copyright 2019-2020 DMQ Design + * + * 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 . + */ +#include QMK_KEYBOARD_H + +enum layers +{ + _NUMPAD, + _RGB, + _MACRO +}; + +enum custom_keycodes { + HELLO_WORLD = SAFE_RANGE, +}; + +uint8_t currentLayer; + +//The below layers are intentionally empty in order to give a good starting point for how to configure multiple layers. +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_NUMPAD] = LAYOUT(/* Base */ + KC_7, KC_8, KC_9, TO(_NUMPAD), + KC_4, KC_5, KC_6, TO(_RGB), + KC_1, KC_2, KC_3, TO(_MACRO), + KC_0, KC_DOT, KC_ENTER + ), + + [_RGB] = LAYOUT(/* Base */ + RGB_HUI, RGB_SAI, RGB_VAI, KC_TRNS, + RGB_HUD, RGB_SAD, RGB_VAD, KC_TRNS, + KC_NO, KC_NO, KC_NO, KC_TRNS, + RGB_RMOD, RGB_TOG, RGB_MOD + ), + + [_MACRO] = LAYOUT(/* Base */ + HELLO_WORLD, KC_NO, KC_NO, KC_TRNS, + KC_NO, KC_NO, KC_NO, KC_TRNS, + KC_NO, KC_NO, KC_NO, KC_TRNS, + KC_NO, KC_NO, KC_NO + ) +}; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case HELLO_WORLD: + if (record->event.pressed) { + SEND_STRING("Hello, world!"); + } + break; + } + + return true; +}; + +void encoder_update_user(uint8_t index, bool clockwise) { + if (index == 0) { /* First encoder */ + switch (currentLayer) { //break each encoder update into a switch statement for the current layer + case _NUMPAD: + if (clockwise) { + tap_code(KC_DOWN); + } else { + tap_code(KC_UP); + } + break; + case _RGB: + if (clockwise) { + rgblight_increase_hue(); + } else { + rgblight_decrease_hue(); + } + break; + case _MACRO: + if (clockwise) { + break; + } else { + break; + } + break; + } + } else if (index == 1) { /* Second encoder */ + switch (currentLayer) { + case _NUMPAD: + if (clockwise) { + tap_code(KC_PGDN); + } else { + tap_code(KC_PGUP); + } + break; + case _RGB: + if (clockwise) { + rgblight_increase_sat(); + } else { + rgblight_decrease_sat(); + } + break; + case _MACRO: + if (clockwise) { + break; + } else { + break; + } + break; + } + } else if (index == 2) { /* Third encoder */ + switch (currentLayer) { + case _NUMPAD: + if (clockwise) { + tap_code(KC_VOLU); + } else { + tap_code(KC_VOLD); + } + break; + case _RGB: + if (clockwise) { + rgblight_increase_val(); + } else { + rgblight_decrease_val(); + } + break; + case _MACRO: + if (clockwise) { + break; + } else { + break; + } + break; + } + } +} + +layer_state_t layer_state_set_user(layer_state_t state) { //This will run every time the layer is updated + currentLayer = get_highest_layer(state); + + switch (currentLayer) { + case _NUMPAD: + setrgb(RGB_WHITE, &led[0]); //Set the top LED to white for the bottom layer + setrgb(0, 0, 0, &led[1]); + setrgb(0, 0, 0, &led[2]); + break; + case _RGB: + setrgb(0, 0, 0, &led[0]); //Set the middle LED to white for the middle layer + setrgb(RGB_WHITE, &led[1]); + setrgb(0, 0, 0, &led[2]); + break; + case _MACRO: + setrgb(0, 0, 0, &led[0]); + setrgb(0, 0, 0, &led[1]); + setrgb(RGB_WHITE, &led[2]); //Set the bottom LED to white for the top layer + break; + } + rgblight_set(); + return state; +} + +#ifdef OLED_DRIVER_ENABLE + +static const char *ANIMATION_NAMES[] = { + "unknown", + "static", + "breathing I", + "breathing II", + "breathing III", + "breathing IV", + "rainbow mood I", + "rainbow mood II", + "rainbow mood III", + "rainbow swirl I", + "rainbow swirl II", + "rainbow swirl III", + "rainbow swirl IV", + "rainbow swirl V", + "rainbow swirl VI", + "snake I", + "snake II", + "snake III", + "snake IV", + "snake V", + "snake VI", + "knight I", + "knight II", + "knight III", + "christmas", + "static gradient I", + "static gradient II", + "static gradient III", + "static gradient IV", + "static gradient V", + "static gradient VI", + "static gradient VII", + "static gradient VIII", + "static gradient IX", + "static gradient X", + "rgb test", + "alternating", + "twinkle I", + "twinkle II", + "twinkle III", + "twinkle IV", + "twinkle V", + "twinkle VI" +}; + +void rgblight_get_mode_name(uint8_t mode, size_t bufsize, char *buf) { + snprintf(buf, bufsize, "%-25s", ANIMATION_NAMES[mode]); +} + +oled_rotation_t oled_init_user(oled_rotation_t rotation) { + #ifdef LEFT_HAND + return OLED_ROTATION_180; + #else + return OLED_ROTATION_0; + #endif +} + +void oled_task_user(void) { + // Host Keyboard Layer Status + oled_write_P(PSTR("Layer: "), false); + + switch (get_highest_layer(layer_state)) { + case _NUMPAD: + oled_write_P(PSTR("Numpad\n"), false); + break; + case _RGB: + oled_write_P(PSTR("RGB\n"), false); + break; + case _MACRO: + oled_write_P(PSTR("Macro\n"), false); + break; + default: + // Or use the write_ln shortcut over adding '\n' to the end of your string + oled_write_ln_P(PSTR("Undefined"), false); + } + + static char rgb_mode_name[30]; + rgblight_get_mode_name(rgblight_get_mode(), sizeof(rgb_mode_name), rgb_mode_name); + + oled_write_P(PSTR("Mode: "), false); + oled_write_ln(rgb_mode_name, false); +} +#endif \ No newline at end of file diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/readme.md b/keyboards/dmqdesign/spin/keymaps/gorbachev/readme.md new file mode 100644 index 000000000000..451dae7ef779 --- /dev/null +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/readme.md @@ -0,0 +1,7 @@ +# Keymap for Spin + +* Encoder button push changes layers +* First layer is a number pad +* Second layer is RGB control layer +* Third layer is macro layer +* OLED support diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/rules.mk b/keyboards/dmqdesign/spin/keymaps/gorbachev/rules.mk new file mode 100644 index 000000000000..553adac19325 --- /dev/null +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/rules.mk @@ -0,0 +1,3 @@ +OLED_DRIVER_ENABLE = yes +MOUSEKEY_ENABLE = no +MIDI_ENABLE = no From 22141f15c18aa18cfe828ee9d470d6e47dfa9959 Mon Sep 17 00:00:00 2001 From: Tero Paananen Date: Mon, 10 Aug 2020 17:21:10 -0400 Subject: [PATCH 2/8] changes from code review --- .../dmqdesign/spin/keymaps/gorbachev/keymap.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c index d0adf91aad94..ec21f15282f6 100644 --- a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c @@ -15,8 +15,7 @@ */ #include QMK_KEYBOARD_H -enum layers -{ +enum layers { _NUMPAD, _RGB, _MACRO @@ -26,8 +25,6 @@ enum custom_keycodes { HELLO_WORLD = SAFE_RANGE, }; -uint8_t currentLayer; - //The below layers are intentionally empty in order to give a good starting point for how to configure multiple layers. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [_NUMPAD] = LAYOUT(/* Base */ @@ -66,7 +63,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { void encoder_update_user(uint8_t index, bool clockwise) { if (index == 0) { /* First encoder */ - switch (currentLayer) { //break each encoder update into a switch statement for the current layer + switch (get_highest_layer(state)) { //break each encoder update into a switch statement for the current layer case _NUMPAD: if (clockwise) { tap_code(KC_DOWN); @@ -90,7 +87,7 @@ void encoder_update_user(uint8_t index, bool clockwise) { break; } } else if (index == 1) { /* Second encoder */ - switch (currentLayer) { + switch (get_highest_layer(state)) { case _NUMPAD: if (clockwise) { tap_code(KC_PGDN); @@ -114,7 +111,7 @@ void encoder_update_user(uint8_t index, bool clockwise) { break; } } else if (index == 2) { /* Third encoder */ - switch (currentLayer) { + switch (get_highest_layer(state)) { case _NUMPAD: if (clockwise) { tap_code(KC_VOLU); @@ -141,9 +138,7 @@ void encoder_update_user(uint8_t index, bool clockwise) { } layer_state_t layer_state_set_user(layer_state_t state) { //This will run every time the layer is updated - currentLayer = get_highest_layer(state); - - switch (currentLayer) { + switch (get_highest_layer(state)) { case _NUMPAD: setrgb(RGB_WHITE, &led[0]); //Set the top LED to white for the bottom layer setrgb(0, 0, 0, &led[1]); From 300f00fc012ce7662aa3fe1d5bbb9f71826282df Mon Sep 17 00:00:00 2001 From: Tero Paananen Date: Mon, 10 Aug 2020 17:32:21 -0400 Subject: [PATCH 3/8] state -> layer_state --- keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c index ec21f15282f6..3ce0ead26658 100644 --- a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c @@ -63,7 +63,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { void encoder_update_user(uint8_t index, bool clockwise) { if (index == 0) { /* First encoder */ - switch (get_highest_layer(state)) { //break each encoder update into a switch statement for the current layer + switch (get_highest_layer(layer_state)) { //break each encoder update into a switch statement for the current layer case _NUMPAD: if (clockwise) { tap_code(KC_DOWN); @@ -87,7 +87,7 @@ void encoder_update_user(uint8_t index, bool clockwise) { break; } } else if (index == 1) { /* Second encoder */ - switch (get_highest_layer(state)) { + switch (get_highest_layer(layer_state)) { case _NUMPAD: if (clockwise) { tap_code(KC_PGDN); @@ -111,7 +111,7 @@ void encoder_update_user(uint8_t index, bool clockwise) { break; } } else if (index == 2) { /* Third encoder */ - switch (get_highest_layer(state)) { + switch (get_highest_layer(layer_state)) { case _NUMPAD: if (clockwise) { tap_code(KC_VOLU); From c5d6311fc55249fbdf1ae5aaa58e229c96e3e07d Mon Sep 17 00:00:00 2001 From: gorbachev Date: Sun, 23 Aug 2020 15:40:43 -0400 Subject: [PATCH 4/8] Formatting fixes Co-authored-by: Drashna Jaelre --- keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c index 3ce0ead26658..5d8251396fe4 100644 --- a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c @@ -16,9 +16,9 @@ #include QMK_KEYBOARD_H enum layers { - _NUMPAD, - _RGB, - _MACRO + _NUMPAD, + _RGB, + _MACRO }; enum custom_keycodes { @@ -244,4 +244,4 @@ void oled_task_user(void) { oled_write_P(PSTR("Mode: "), false); oled_write_ln(rgb_mode_name, false); } -#endif \ No newline at end of file +#endif From 1cf6c6f2f1d0e5fd018e3e0ef89a2ada1019a6da Mon Sep 17 00:00:00 2001 From: gorbachev Date: Sun, 23 Aug 2020 15:41:01 -0400 Subject: [PATCH 5/8] Formatting fixes Co-authored-by: Drashna Jaelre --- keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c index 5d8251396fe4..786f33c7c748 100644 --- a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c @@ -51,11 +51,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { - case HELLO_WORLD: - if (record->event.pressed) { - SEND_STRING("Hello, world!"); - } - break; + case HELLO_WORLD: + if (record->event.pressed) { + SEND_STRING("Hello, world!"); + } + break; } return true; From 735813fc2c88610941dc6314f1334c9ef1eda0b3 Mon Sep 17 00:00:00 2001 From: gorbachev Date: Sun, 23 Aug 2020 15:41:12 -0400 Subject: [PATCH 6/8] Formatting fixes Co-authored-by: Drashna Jaelre --- keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c index 786f33c7c748..42bba9ce4900 100644 --- a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c @@ -208,7 +208,7 @@ static const char *ANIMATION_NAMES[] = { }; void rgblight_get_mode_name(uint8_t mode, size_t bufsize, char *buf) { - snprintf(buf, bufsize, "%-25s", ANIMATION_NAMES[mode]); + snprintf(buf, bufsize, "%-25s", ANIMATION_NAMES[mode]); } oled_rotation_t oled_init_user(oled_rotation_t rotation) { From c9b9534d9563d5495a01c14e5e6cf55d8d00e824 Mon Sep 17 00:00:00 2001 From: gorbachev Date: Sun, 23 Aug 2020 15:41:22 -0400 Subject: [PATCH 7/8] Formatting fixes Co-authored-by: Drashna Jaelre --- keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c index 42bba9ce4900..d1901104deaa 100644 --- a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c @@ -212,11 +212,11 @@ void rgblight_get_mode_name(uint8_t mode, size_t bufsize, char *buf) { } oled_rotation_t oled_init_user(oled_rotation_t rotation) { - #ifdef LEFT_HAND - return OLED_ROTATION_180; - #else - return OLED_ROTATION_0; - #endif +#ifdef LEFT_HAND + return OLED_ROTATION_180; +#else + return OLED_ROTATION_0; +#endif } void oled_task_user(void) { From afa30e2c3b09a66358dd2071ae18692422480197 Mon Sep 17 00:00:00 2001 From: gorbachev Date: Sun, 23 Aug 2020 15:41:32 -0400 Subject: [PATCH 8/8] Formatting fixes Co-authored-by: Drashna Jaelre --- keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c index d1901104deaa..b9ad17386c23 100644 --- a/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c +++ b/keyboards/dmqdesign/spin/keymaps/gorbachev/keymap.c @@ -238,10 +238,10 @@ void oled_task_user(void) { oled_write_ln_P(PSTR("Undefined"), false); } - static char rgb_mode_name[30]; - rgblight_get_mode_name(rgblight_get_mode(), sizeof(rgb_mode_name), rgb_mode_name); + static char rgb_mode_name[30]; + rgblight_get_mode_name(rgblight_get_mode(), sizeof(rgb_mode_name), rgb_mode_name); oled_write_P(PSTR("Mode: "), false); - oled_write_ln(rgb_mode_name, false); + oled_write_ln(rgb_mode_name, false); } #endif