keymap.c (11004B)
1 /* Copyright 2020 sendyyeah 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 17 #include QMK_KEYBOARD_H 18 19 #define LAYERNUM 3 20 21 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 22 [0] = LAYOUT(KC_MUTE, KC_MPLY, KC_MPRV, KC_MNXT, TO(1)), 23 [1] = LAYOUT(KC_TRNS, KC_MSTP, KC_MRWD, KC_MFFD, TO(2)), 24 [2] = LAYOUT(KC_LSFT, UG_NEXT, UG_HUEU, UG_SATU, TO(0)) 25 }; 26 27 int get_icon_start_position(int key_position) { 28 if (key_position == 1) { 29 return 0; 30 } else { 31 return (key_position - 1) * 3; 32 } 33 } 34 35 bool encoder_update_user(uint8_t index, bool clockwise) { 36 static const char PROGMEM UP_ICON[] = {0x1E,0}; 37 static const char PROGMEM DOWN_ICON[] = {0x1F,0}; 38 if (index == 0) { 39 if (layer_state_is(0)) { 40 if (clockwise) { 41 tap_code(KC_VOLU); 42 oled_set_cursor(get_icon_start_position(7), 3); 43 oled_write_P(PSTR(" "), false); 44 oled_set_cursor(get_icon_start_position(7), 2); 45 oled_write_P(UP_ICON, false); 46 } else { 47 tap_code(KC_VOLD); 48 oled_set_cursor(get_icon_start_position(7), 2); 49 oled_write_P(PSTR(" "), false); 50 oled_set_cursor(get_icon_start_position(7), 3); 51 oled_write_P(DOWN_ICON, false); 52 } 53 } else if (layer_state_is(1)) { 54 if (clockwise) { 55 tap_code(KC_BRIU); 56 oled_set_cursor(get_icon_start_position(7), 3); 57 oled_write_P(PSTR(" "), false); 58 oled_set_cursor(get_icon_start_position(7), 2); 59 oled_write_P(UP_ICON, false); 60 } else { 61 tap_code(KC_BRID); 62 oled_set_cursor(get_icon_start_position(7), 2); 63 oled_write_P(PSTR(" "), false); 64 oled_set_cursor(get_icon_start_position(7), 3); 65 oled_write_P(DOWN_ICON, false); 66 } 67 } else if (layer_state_is(2)) { 68 if (clockwise) { 69 rgblight_increase_val(); 70 oled_set_cursor(get_icon_start_position(7), 3); 71 oled_write_P(PSTR(" "), false); 72 oled_set_cursor(get_icon_start_position(7), 2); 73 oled_write_P(UP_ICON, false); 74 } else { 75 rgblight_decrease_val(); 76 oled_set_cursor(get_icon_start_position(7), 2); 77 oled_write_P(PSTR(" "), false); 78 oled_set_cursor(get_icon_start_position(7), 3); 79 oled_write_P(DOWN_ICON, false); 80 } 81 } 82 } 83 return true; 84 } 85 86 #ifdef OLED_ENABLE 87 88 oled_rotation_t oled_init_user(oled_rotation_t rotation) { 89 return OLED_ROTATION_180; 90 } 91 92 void draw_mute_icon(int key_position, int row) { 93 static const char PROGMEM ICON_MUTE_0[] = {0x88, 0x89, 0}; 94 static const char PROGMEM ICON_MUTE_1[] = {0xA8, 0xA9, 0}; 95 oled_set_cursor(get_icon_start_position(key_position), row); 96 oled_write_P(ICON_MUTE_0, false); 97 oled_set_cursor(get_icon_start_position(key_position), row + 1); 98 oled_write_P(ICON_MUTE_1, false); 99 } 100 101 void draw_play_icon(int key_position, int row) { 102 static const char PROGMEM ICON_PLAY_0[] = {0x8A, 0x8B, 0}; 103 static const char PROGMEM ICON_PLAY_1[] = {0xAA, 0xAB, 0}; 104 oled_set_cursor(get_icon_start_position(key_position), row); 105 oled_write_P(ICON_PLAY_0, false); 106 oled_set_cursor(get_icon_start_position(key_position), row + 1); 107 oled_write_P(ICON_PLAY_1, false); 108 } 109 110 void draw_rewind_icon(int key_position, int row) { 111 static const char PROGMEM ICON_REWIND_0[] = {0x8C, 0x8D, 0}; 112 static const char PROGMEM ICON_REWIND_1[] = {0xAC, 0xAD, 0}; 113 oled_set_cursor(get_icon_start_position(key_position), row); 114 oled_write_P(ICON_REWIND_0, false); 115 oled_set_cursor(get_icon_start_position(key_position), row + 1); 116 oled_write_P(ICON_REWIND_1, false); 117 } 118 119 void draw_fast_forward_icon(int key_position, int row) { 120 static const char PROGMEM ICON_FAST_FORWARD_0[] = {0x8E, 0x8F, 0}; 121 static const char PROGMEM ICON_FAST_FORWARD_1[] = {0xAE, 0xAF, 0}; 122 oled_set_cursor(get_icon_start_position(key_position), row); 123 oled_write_P(ICON_FAST_FORWARD_0, false); 124 oled_set_cursor(get_icon_start_position(key_position), row + 1); 125 oled_write_P(ICON_FAST_FORWARD_1, false); 126 } 127 128 void draw_prev_icon(int key_position, int row) { 129 static const char PROGMEM ICON_PREV_0[] = {0x90, 0x91, 0}; 130 static const char PROGMEM ICON_PREV_1[] = {0xB0, 0xB1, 0}; 131 oled_set_cursor(get_icon_start_position(key_position), row); 132 oled_write_P(ICON_PREV_0, false); 133 oled_set_cursor(get_icon_start_position(key_position), row + 1); 134 oled_write_P(ICON_PREV_1, false); 135 } 136 137 void draw_next_icon(int key_position, int row) { 138 static const char PROGMEM ICON_NEXT_0[] = {0x92, 0x93, 0}; 139 static const char PROGMEM ICON_NEXT_1[] = {0xB2, 0xB3, 0}; 140 oled_set_cursor(get_icon_start_position(key_position), row); 141 oled_write_P(ICON_NEXT_0, false); 142 oled_set_cursor(get_icon_start_position(key_position), row + 1); 143 oled_write_P(ICON_NEXT_1, false); 144 } 145 146 void draw_stop_icon(int key_position, int row) { 147 static const char PROGMEM ICON_STOP_0[] = {0xA0, 0xA1, 0}; 148 static const char PROGMEM ICON_STOP_1[] = {0xC0, 0xC1, 0}; 149 oled_set_cursor(get_icon_start_position(key_position), row); 150 oled_write_P(ICON_STOP_0, false); 151 oled_set_cursor(get_icon_start_position(key_position), row + 1); 152 oled_write_P(ICON_STOP_1, false); 153 } 154 155 void draw_sound_icon(int key_position, int row) { 156 static const char PROGMEM ICON_SOUND_0[] = {0xA2, 0xA3, 0}; 157 static const char PROGMEM ICON_SOUND_1[] = {0xC2, 0xC3, 0}; 158 oled_set_cursor(get_icon_start_position(key_position), row); 159 oled_write_P(ICON_SOUND_0, false); 160 oled_set_cursor(get_icon_start_position(key_position), row + 1); 161 oled_write_P(ICON_SOUND_1, false); 162 } 163 164 void draw_raise_icon(int key_position, int row) { 165 static const char PROGMEM ICON_RAISE_0[] = {0xA4, 0xA5, 0}; 166 static const char PROGMEM ICON_RAISE_1[] = {0xC4, 0xC5, 0}; 167 oled_set_cursor(get_icon_start_position(key_position), row); 168 oled_write_P(ICON_RAISE_0, false); 169 oled_set_cursor(get_icon_start_position(key_position), row + 1); 170 oled_write_P(ICON_RAISE_1, false); 171 } 172 173 void draw_lower_icon(int key_position, int row) { 174 static const char PROGMEM ICON_LOWER_0[] = {0xA6, 0xA7, 0}; 175 static const char PROGMEM ICON_LOWER_1[] = {0xC6, 0xC7, 0}; 176 oled_set_cursor(get_icon_start_position(key_position), row); 177 oled_write_P(ICON_LOWER_0, false); 178 oled_set_cursor(get_icon_start_position(key_position), row + 1); 179 oled_write_P(ICON_LOWER_1, false); 180 } 181 182 void draw_brightness_icon(int key_position, int row) { 183 static const char PROGMEM ICON_BRIGHTNESS_0[] = {0xB9, 0xBA, 0}; 184 static const char PROGMEM ICON_BRIGHTNESS_1[] = {0xD9, 0xDA, 0}; 185 oled_set_cursor(get_icon_start_position(key_position), row); 186 oled_write_P(ICON_BRIGHTNESS_0, false); 187 oled_set_cursor(get_icon_start_position(key_position), row + 1); 188 oled_write_P(ICON_BRIGHTNESS_1, false); 189 } 190 191 void draw_mode_icon(int key_position, int row) { 192 static const char PROGMEM ICON_MODE_0[] = {0x94, 0x95, 0}; 193 static const char PROGMEM ICON_MODE_1[] = {0xB4, 0xB5, 0}; 194 oled_set_cursor(get_icon_start_position(key_position), row); 195 oled_write_P(ICON_MODE_0, false); 196 oled_set_cursor(get_icon_start_position(key_position), row + 1); 197 oled_write_P(ICON_MODE_1, false); 198 } 199 200 void draw_hue_icon(int key_position, int row) { 201 static const char PROGMEM ICON_HUE_0[] = {0x96, 0x97, 0}; 202 static const char PROGMEM ICON_HUE_1[] = {0xB6, 0xB7, 0}; 203 oled_set_cursor(get_icon_start_position(key_position), row); 204 oled_write_P(ICON_HUE_0, false); 205 oled_set_cursor(get_icon_start_position(key_position), row + 1); 206 oled_write_P(ICON_HUE_1, false); 207 } 208 209 void draw_sat_icon(int key_position, int row) { 210 static const char PROGMEM ICON_SAT_0[] = {0xBB, 0xBC, 0}; 211 static const char PROGMEM ICON_SAT_1[] = {0xDB, 0xDC, 0}; 212 oled_set_cursor(get_icon_start_position(key_position), row); 213 oled_write_P(ICON_SAT_0, false); 214 oled_set_cursor(get_icon_start_position(key_position), row + 1); 215 oled_write_P(ICON_SAT_1, false); 216 } 217 218 bool oled_task_user(void) { 219 // Host Keyboard Layer Status 220 static const char PROGMEM ICON_LAYER[] = {0x80, 0x81, 0x82, 0x83, 0}; 221 static const char PROGMEM ICON_ENCODER[] = {0x84, 0x85, 0x86, 0x87, 0}; 222 // static const char PROGMEM ICON_MUTE[] = {0x88, 0x89,0xA9, 0xAA}; 223 224 oled_write_P(ICON_LAYER, false); 225 226 switch (get_highest_layer(layer_state)) { 227 case 0: 228 oled_write_P(PSTR("1ST "), false); 229 break; 230 case 1: 231 oled_write_P(PSTR("2ND "), false); 232 break; 233 case 2: 234 oled_write_P(PSTR("3RD "), false); 235 break; 236 default: 237 // Or use the write_ln shortcut over adding '\n' to the end of your string 238 oled_write_P(PSTR("UNDF"), false); 239 } 240 241 oled_write_P(PSTR(" "), false); 242 243 oled_write_P(ICON_ENCODER, false); 244 switch(get_highest_layer(layer_state)) { 245 case 0: 246 oled_write_P(PSTR("VOL "), false); 247 break; 248 case 1: 249 oled_write_P(PSTR("BRGT"), false); 250 break; 251 case 2: 252 oled_write_P(PSTR("RGB "), false); 253 break; 254 default: 255 // Or use the write_ln shortcut over adding '\n' to the end of your string 256 oled_write_P(PSTR("UNDF"), false); 257 } 258 259 switch(get_highest_layer(layer_state)) { 260 default: 261 case 0: 262 draw_mute_icon(1, 2); 263 draw_play_icon(2, 2); 264 draw_prev_icon(3, 2); 265 draw_next_icon(4, 2); 266 draw_raise_icon(5, 2); 267 draw_sound_icon(6, 2); 268 break; 269 case 1: 270 draw_mute_icon(1, 2); 271 draw_stop_icon(2, 2); 272 draw_rewind_icon(3, 2); 273 draw_fast_forward_icon(4, 2); 274 draw_lower_icon(5, 2); 275 draw_brightness_icon(6, 2); 276 break; 277 case 2: 278 draw_raise_icon(1, 2); 279 draw_mode_icon(2, 2); 280 draw_hue_icon(3, 2); 281 draw_sat_icon(4, 2); 282 draw_lower_icon(5, 2); 283 draw_brightness_icon(6, 2); 284 break; 285 } 286 287 return false; 288 } 289 290 #endif