keymap.c (4922B)
1 /* Copyright 2019 monksoffunk 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 #include QMK_KEYBOARD_H 17 18 #include "common/oled_helper.h" 19 20 // Defines the keycodes used by our macros in process_record_user 21 enum custom_keycodes { 22 RGBRST = SAFE_RANGE, 23 WRTROM, 24 }; 25 26 enum layer_number { 27 _AUDIO = 0, 28 _HUE, 29 _SAT, 30 _VAL, 31 _MODE, 32 }; 33 34 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 35 // LAYOUT(LeftEncoder, RightEncoder, LeftSwitch, CenterLeftSwitch, CenterRightSwitch, RightSwitch) 36 [_AUDIO] = LAYOUT(KC_MUTE, KC_ENT, LT(_HUE, KC_MPRV), LT(_SAT, KC_MPLY), LT(_VAL, KC_MNXT), LT(_MODE, KC_SPC)), 37 [_HUE] = LAYOUT(UG_TOGG, RGBRST, _______, _______, UG_HUED, UG_HUEU), 38 [_SAT] = LAYOUT(_______, _______, _______, _______, UG_SATD, UG_SATU), 39 [_VAL] = LAYOUT(_______, _______, UG_VALD, UG_VALU, _______, UG_VALU), 40 [_MODE] = LAYOUT(_______, WRTROM, UG_PREV, UG_NEXT, UG_NEXT, _______), 41 }; 42 43 bool process_record_user(uint16_t keycode, keyrecord_t *record) { 44 switch (keycode) { 45 case WRTROM: 46 #ifdef RGBLIGHT_ENABLE 47 if (record->event.pressed) { 48 eeconfig_update_rgblight_current(); 49 } 50 #endif 51 return false; 52 break; 53 54 case RGBRST: 55 #ifdef RGBLIGHT_ENABLE 56 if (record->event.pressed) { 57 eeconfig_update_rgblight_default(); 58 rgblight_enable(); 59 } 60 #endif 61 return false; 62 break; 63 } 64 return true; 65 } 66 67 #ifdef OLED_ENABLE 68 # include <stdio.h> 69 # include <string.h> 70 71 // assign the right code to your layers for OLED display 72 # define L_AUDIO 0 73 # define L_HUE (1 << _HUE) 74 # define L_SAT (1 << _SAT) 75 # define L_VAL (1 << _VAL) 76 # define L_MODE (1 << _MODE) 77 78 void render_status(void) { 79 render_logo(); 80 // Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below 81 switch (layer_state) { 82 case L_AUDIO: 83 oled_write_P(PSTR("audio control\n"), false); 84 break; 85 case L_HUE: 86 oled_write_P(PSTR("rgb HUE control\n"), false); 87 break; 88 case L_SAT: 89 oled_write_P(PSTR("rgb SAT control\n"), false); 90 break; 91 case L_VAL: 92 oled_write_P(PSTR("rgb VAL control\n"), false); 93 break; 94 case L_MODE: 95 oled_write_P(PSTR("rgb MODE control\n"), false); 96 break; 97 default: 98 break; 99 } 100 UPDATE_LED_STATUS(); 101 RENDER_LED_STATUS(); 102 } 103 104 bool oled_task_user(void) { 105 if (is_keyboard_master()) { 106 render_status(); 107 } else { 108 render_logo(); 109 } 110 return false; 111 } 112 #endif 113 114 bool encoder_update_user(uint8_t index, bool clockwise) { 115 oled_on(); 116 if (index == 0) { /* left encoder */ 117 switch (layer_state) { 118 case L_AUDIO: 119 if (clockwise) { 120 tap_code(KC_VOLU); 121 } else { 122 tap_code(KC_VOLD); 123 } 124 break; 125 126 case L_HUE: 127 #ifdef RGBLIGHT_ENABLE 128 if (clockwise) { 129 rgblight_increase_hue_noeeprom(); 130 } else { 131 rgblight_decrease_hue_noeeprom(); 132 } 133 #endif 134 break; 135 136 case L_SAT: 137 #ifdef RGBLIGHT_ENABLE 138 if (clockwise) { 139 rgblight_increase_sat_noeeprom(); 140 } else { 141 rgblight_decrease_sat_noeeprom(); 142 } 143 #endif 144 break; 145 146 case L_VAL: 147 #ifdef RGBLIGHT_ENABLE 148 if (clockwise) { 149 rgblight_increase_val_noeeprom(); 150 } else { 151 rgblight_decrease_val_noeeprom(); 152 } 153 #endif 154 break; 155 156 case L_MODE: 157 #ifdef RGBLIGHT_ENABLE 158 if (clockwise) { 159 rgblight_step_noeeprom(); 160 } else { 161 rgblight_step_reverse_noeeprom(); 162 } 163 #endif 164 break; 165 } 166 } else if (index == 1) { /* right encoder */ 167 if (clockwise) { 168 tap_code(KC_DOWN); 169 } else { 170 tap_code(KC_UP); 171 } 172 } 173 return true; 174 }