ziyoulang_k3_mod.c (3585B)
1 // Copyright 2023 Coom (@coomstoolbox) 2 // SPDX-License-Identifier: GPL-2.0-or-later 3 4 #include "quantum.h" 5 #include <stdio.h> 6 7 void keyboard_post_init_kb(void) { 8 #ifdef CONSOLE_ENABLE 9 debug_enable=true; 10 debug_matrix=true; 11 #endif 12 keyboard_post_init_user(); 13 } 14 15 static uint16_t last_keycode = KC_NO; 16 static keypos_t last_key = {0, 0}; 17 18 bool process_record_kb(uint16_t keycode, keyrecord_t *record) { 19 if (!process_record_user(keycode, record)) { 20 return false; 21 } 22 // コンソールが有効化されている場合、マトリックス上の位置とキー押下状態を出力します 23 #ifdef CONSOLE_ENABLE 24 uprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed); 25 #endif 26 if (record->event.pressed) { 27 if (last_keycode != keycode) { 28 last_keycode = keycode; 29 last_key = record->event.key; 30 } 31 } 32 return true; 33 } 34 35 #ifdef OLED_ENABLE 36 oled_rotation_t oled_init_kb(oled_rotation_t rotation) { 37 return OLED_ROTATION_180; 38 } 39 40 static void render_logo(void) { 41 static const char PROGMEM qmk_logo[] = { 42 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 43 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 44 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0x00 45 }; 46 oled_write_P(qmk_logo, false); 47 #ifdef CONSOLE_ENABLE 48 uprintf("Ziyoulang K3 Mod\n"); 49 oled_set_cursor(3, 0); 50 oled_write_P(PSTR("Ziyoulang K3 Mod"), false); 51 #endif 52 } 53 54 bool oled_task_kb(void) { 55 if (!oled_task_user()) { 56 return false; 57 } 58 int uptime_seconds = (int)(timer_read32() / 1000); 59 if (uptime_seconds < 5) { 60 render_logo(); 61 return false; 62 } 63 64 // Host Keyboard Layer Status 65 oled_write_P(PSTR("Layer: "), false); 66 67 switch (get_highest_layer(layer_state | default_layer_state)) { 68 case 0: 69 oled_write_P(PSTR("Default\n"), false); 70 break; 71 case 1: 72 oled_write_P(PSTR("2\n"), false); 73 break; 74 case 2: 75 oled_write_P(PSTR("3\n"), false); 76 break; 77 default: 78 // Or use the write_ln shortcut over adding '\n' to the end of your string 79 oled_write_ln_P(PSTR("Undefined"), false); 80 } 81 82 // Host Keyboard LED Status 83 led_t led_state = host_keyboard_led_state(); 84 if (led_state.num_lock) { 85 oled_write_P(PSTR("NUM"), true); 86 oled_write_P(PSTR(" "), false); 87 } else { 88 oled_write_P(PSTR(" "), false); 89 } 90 if (led_state.caps_lock) { 91 oled_write_P(PSTR("CAP"), true); 92 oled_write_P(PSTR(" "), false); 93 } else { 94 oled_write_P(PSTR(" "), false); 95 } 96 if (led_state.scroll_lock) { 97 oled_write_P(PSTR("SCR"), true); 98 oled_write_ln_P(PSTR(" "), false); 99 } else { 100 oled_write_ln_P(PSTR(" "), false); 101 } 102 103 // Last Key pressed info 104 oled_write_P(PSTR("kc : "), false); 105 if (last_keycode > 21000) { 106 oled_write_ln_P(PSTR(" Fn"), false); 107 } else { 108 oled_write_ln_P(get_u16_str(last_keycode, ' '), false); 109 } 110 oled_write_P(PSTR("col: "), false); 111 oled_write_P(get_u8_str(last_key.col, ' '), false); 112 oled_write_P(PSTR(",row: "), false); 113 oled_write_P(get_u8_str(last_key.row, ' '), false); 114 115 return false; 116 } 117 #endif