diff options
Diffstat (limited to 'waffle/oled.c')
-rw-r--r-- | waffle/oled.c | 353 |
1 files changed, 173 insertions, 180 deletions
diff --git a/waffle/oled.c b/waffle/oled.c index cef22ad..f6734e5 100644 --- a/waffle/oled.c +++ b/waffle/oled.c @@ -1,123 +1,25 @@ // Copyright 2024 [email protected] // SPDX-License-Identifier: GPL-2.0-or-later +#include "oled.h" #include "waffle.h" -uint32_t oled_timer = 0; -void render_wpm(void) { - oled_write(PSTR("WPM: "), false); - oled_write_ln(get_u8_str(get_current_wpm(), ' '), false); -} - -#ifdef DEBUG_MATRIX_SCAN_RATE -void render_scan_rate(void) { - oled_write(get_u16_str(get_matrix_scan_rate(), ' '), false); - oled_write_ln(PSTR("/s"), false); -} -#endif - -#ifdef RAW_ENABLE -void host_info(uint8_t data) { - char buffer[3]; - oled_write_ln((char *)itoa(data, buffer, 10), false); -} - -void render_time(void) { - if (user_state.hour < 10) - oled_write(PSTR("0"), false); - host_info(user_state.hour); - oled_write(PSTR(":"), false); - if (user_state.min < 10) - oled_write(PSTR("0"), false); - host_info(user_state.min); -} -#endif +uint32_t oled_timer = 0; +char keylog_str[KEYLOG_LEN + 1] = {0}; -void qmk_logo(void) { - static const char PROGMEM qmk_logo[16] = {0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0xaa, - 0xab, 0xac, 0xad, 0xae, 0xca, 0xcb, - 0xcc, 0xcd, 0xce, 0}; - oled_write(qmk_logo, false); -}; +void oled_timer_reset(void) { oled_timer = timer_read32(); } -void render_keyboard(void) { - static const char PROGMEM keyboard[16] = {0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xda, - 0xdb, 0xdc, 0xdd, 0xde, 0}; - oled_write(keyboard, false); -}; +__attribute__((weak)) bool oled_task_keymap(void) { return true; } -void layer_status(void) { - bool blink = (timer_read() % 1000) < 500; - switch (get_highest_layer(layer_state)) { - case _RAISE: - oled_write_ln(PSTR("> hi"), false); - break; - case _LOWER: - oled_write_ln(PSTR("> lo"), false); - break; - case _ADJUST: - oled_write_ln(PSTR("> ad"), false); - break; - default: - oled_write_ln(blink ? PSTR("> _") : PSTR("> "), false); +bool oled_task_user(void) { + if (is_keyboard_master()) { + if (timer_elapsed32(oled_timer) > 300000) { + oled_off(); + return false; + } else + oled_on(); } -}; - -void mod_status(uint8_t mods) { - static const char PROGMEM status[4][3] = { - {0xd3, 0xd4, 0}, {0x93, 0x94, 0}, {0xb3, 0xb4, 0}, {0x95, 0x96, 0}}; - bool blink = (timer_read() % 1000) < 500; - if (mods & MOD_MASK_CTRL) { - oled_set_cursor(2, 11); - oled_write(status[0], false); - } else if (mods & MOD_MASK_SHIFT) { - oled_set_cursor(2, 11); - oled_write(status[1], false); - } else if (mods & MOD_MASK_ALT) { - oled_set_cursor(2, 11); - oled_write(status[2], false); - } else if (mods & MOD_MASK_GUI) { - oled_set_cursor(2, 11); - oled_write(status[3], false); - } else - oled_write_ln(blink ? PSTR("$ _") : PSTR("$ "), false); -} - -void keylock_status(led_t led_usb_state) { - bool blink = (timer_read() % 1000) < 500; - if (led_usb_state.caps_lock) - oled_write_ln(PSTR("% cap"), false); - else if (led_usb_state.num_lock) - oled_write_ln(PSTR("% num"), false); - else if (led_usb_state.scroll_lock) - oled_write_ln(PSTR("% scr"), false); - else - oled_write_ln(blink ? PSTR("% _") : PSTR("% "), false); -} - -char keylog_str[5] = {}; -static uint16_t keylog_timer = 0; -const char code_to_name[60] = { - ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', - 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', - '7', '8', '9', '0', 'R', 'E', 'B', 'T', '_', '-', '=', '[', - ']', '\\', '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '}; - -void add_keylog(uint16_t keycode) { - for (uint8_t i = ARRAY_SIZE(keylog_str) - 1; i > 0; i--) - keylog_str[i] = keylog_str[i - 1]; - if (keycode < ARRAY_SIZE(code_to_name)) - keylog_str[0] = code_to_name[keycode & 0xFF]; - keylog_timer = timer_read(); -} - -void render_keylog(void) { oled_write(keylog_str, false); } - -void render_keylogger(void) { oled_write(keylog_str, false); } - -void keylogger_status(void) { - bool blink = (timer_read() % 1000) < 500; - oled_write_ln(blink ? PSTR("~ _") : PSTR("~ "), false); + oled_task_keymap(); + return false; } void anim_frame(uint16_t size, char const action[][size]) { @@ -126,52 +28,7 @@ void anim_frame(uint16_t size, char const action[][size]) { oled_write_raw(action[current_frame], size); } -#ifdef FELIX_DOG -void felix(void) { - static uint16_t felix_anim_timer = 0; - bool shifted = get_mods() & MOD_MASK_SHIFT || - host_keyboard_led_state().caps_lock || is_caps_word_on(); - void animate(void) { - if (shifted) - anim_frame(96, felix_bark); - else if (get_mods() & MOD_MASK_CAG) - anim_frame(96, felix_sneak); - else if (get_current_wpm() > 40) - anim_frame(96, felix_run); - else if (get_current_wpm() > 30 && get_current_wpm() <= 40) - anim_frame(96, felix_walk); - else - anim_frame(96, felix_sit); - } - if (timer_elapsed(felix_anim_timer) > 200) { - felix_anim_timer = timer_read(); - animate(); - } -} -#endif - -#ifdef BONGO_CAT -void bongo(void) { - static uint16_t bongo_anim_timer = 0; - void animate(void) { - if (get_current_wpm() <= 30) { - anim_frame(512, bongo_idle); - } - if (get_current_wpm() > 30 && get_current_wpm() <= 40) { - anim_frame(512, bongo_prep); - } - if (get_current_wpm() > 40) { - anim_frame(512, bongo_tap); - } - } - if (timer_elapsed(bongo_anim_timer) > 200) { - bongo_anim_timer = timer_read(); - animate(); - } -} -#endif - -#ifdef WPM_GRAPH +#ifdef OLED_DISPLAY_128X64 void wpm_graph(void) { static uint8_t height = OLED_DISPLAY_HEIGHT - 1, vert_count = 0, max_wpm = 160; @@ -204,41 +61,177 @@ void wpm_graph(void) { } #endif -#ifdef LAYER_ANIM +void felix_dog(void) { + static uint16_t felix_anim_timer = 0; + bool shifted = + get_mods() & MOD_MASK_SHIFT || host_keyboard_led_state().caps_lock; + if (timer_elapsed(felix_anim_timer) > 200) { + felix_anim_timer = timer_read(); + if (shifted || is_caps_word_on()) + anim_frame(96, felix_bark); + else if (get_mods() & MOD_MASK_CAG) + anim_frame(96, felix_sneak); + else if (get_current_wpm() > 60) + anim_frame(96, felix_run); + else if (get_current_wpm() && get_current_wpm() <= 60) + anim_frame(96, felix_walk); + else + anim_frame(96, felix_sit); + } +} + void layer_anim(void) { static uint16_t layer_anim_timer = 0; - void animate(void) { + if (timer_elapsed(layer_anim_timer) > 200) { + layer_anim_timer = timer_read(); switch (get_highest_layer(layer_state)) { - case _RAISE: - anim_frame(650, tap_sym); + case _BASE: + anim_frame(520, tap_num); break; case _LOWER: - anim_frame(520, tap_num); + anim_frame(650, tap_sym); break; - case _ADJUST: + case _RAISE: anim_frame(520, tap_sys); break; - default: - bongo(); } } - if (timer_elapsed(layer_anim_timer) > 200) { - layer_anim_timer = timer_read(); - animate(); +} + +void layer_status(void) { + static const char PROGMEM base[] = {0x20, 0x94, 0x95, 0x96, 0x20, + 0x20, 0xb4, 0xb5, 0xb6, 0x20, + 0x20, 0xd4, 0xd5, 0xd6, 0x20}; + static const char PROGMEM lower[] = {0x20, 0x9a, 0x9b, 0x9c, 0x20, + 0x20, 0xba, 0xbb, 0xbc, 0x20, + 0x20, 0xda, 0xdb, 0xdc, 0x20}; + static const char PROGMEM raise[] = {0x20, 0x97, 0x98, 0x99, 0x20, + 0x20, 0xb7, 0xb8, 0xb9, 0x20, + 0x20, 0xd7, 0xd8, 0xd9, 0x20}; + switch (get_highest_layer(layer_state)) { + case _LOWER: + oled_write(lower, false); + break; + case _RAISE: + oled_write(raise, false); + break; + default: + oled_write(base, false); } } -#endif -bool oled_task_user(void) { - if (is_keyboard_master()) { - if (timer_elapsed32(oled_timer) > 180000) { - oled_off(); - return false; - } else - oled_on(); +void render_mod_status(void) { + const uint8_t mods = get_mods(); + static const char PROGMEM + gui_off_1[] = {0x85, 0x86}, + gui_off_2[] = {0xa5, 0xa6}, gui_on_1[] = {0x8d, 0x8e}, + gui_on_2[] = {0xad, 0xae}, alt_off_1[] = {0x87, 0x88}, + alt_off_2[] = {0xa7, 0xa8}, alt_on_1[] = {0x8f, 0x90}, + alt_on_2[] = {0xaf, 0xb0}, ctrl_off_1[] = {0x89, 0x8a}, + ctrl_off_2[] = {0xa9, 0xaa}, ctrl_on_1[] = {0x91, 0x92}, + ctrl_on_2[] = {0xb1, 0xb2}, shift_off_1[] = {0x8b, 0x8c}, + shift_off_2[] = {0xab, 0xac}, shift_on_1[] = {0xcd, 0xce}, + shift_on_2[] = {0xcf, 0xd0}, off_off_1[] = {0xc5}, off_off_2[] = {0xc6}, + on_off_1[] = {0xc7}, on_off_2[] = {0xc8}, off_on_1[] = {0xc9}, + off_on_2[] = {0xca}, on_on_1[] = {0xcb}, on_on_2[] = {0xcc}; + + oled_write(mods & MOD_MASK_GUI ? gui_on_1 : gui_off_1, false); + if ((mods & MOD_MASK_GUI) && (mods & MOD_MASK_ALT)) + oled_write(on_on_1, false); + else if (mods & MOD_MASK_GUI) + oled_write(on_off_1, false); + else if (mods & MOD_MASK_ALT) + oled_write(off_on_1, false); + else + oled_write(off_off_1, false); + oled_write(mods & MOD_MASK_ALT ? alt_on_1 : alt_off_1, false); + oled_write(mods & MOD_MASK_GUI ? gui_on_2 : gui_off_2, false); + if (mods & MOD_MASK_GUI & MOD_MASK_ALT) + oled_write(on_on_2, false); + else if (mods & MOD_MASK_GUI) + oled_write(on_off_2, false); + else if (mods & MOD_MASK_ALT) + oled_write(off_on_2, false); + else + oled_write(off_off_2, false); + oled_write(mods & MOD_MASK_ALT ? alt_on_2 : alt_off_2, false); + oled_write(mods & MOD_MASK_CTRL ? ctrl_on_1 : ctrl_off_1, false); + if ((mods & MOD_MASK_CTRL) && (mods & MOD_MASK_SHIFT)) + oled_write(on_on_1, false); + else if (mods & MOD_MASK_CTRL) + oled_write(on_off_1, false); + else if (mods & MOD_MASK_SHIFT) + oled_write(off_on_1, false); + else + oled_write(off_off_1, false); + oled_write(mods & MOD_MASK_SHIFT ? shift_on_1 : shift_off_1, false); + oled_write(mods & MOD_MASK_CTRL ? ctrl_on_2 : ctrl_off_2, false); + if (mods & MOD_MASK_CTRL & MOD_MASK_SHIFT) + oled_write(on_on_2, false); + else if (mods & MOD_MASK_CTRL) + oled_write(on_off_2, false); + else if (mods & MOD_MASK_SHIFT) + oled_write(off_on_2, false); + else + oled_write(off_off_2, false); + oled_write(mods & MOD_MASK_SHIFT ? shift_on_2 : shift_off_2, false); +} + +void add_keylog(uint16_t keycode, keyrecord_t *record) { + if (IS_QK_MOD_TAP(keycode)) + keycode = + record->tap.count + ? keycode_config(QK_MOD_TAP_GET_TAP_KEYCODE(keycode)) + : keycode_config(0xE0 + biton(QK_MOD_TAP_GET_MODS(keycode) & 0xF) + + biton(QK_MOD_TAP_GET_MODS(keycode) & 0x10)); + else if (IS_QK_LAYER_TAP(keycode) && (record->tap.count)) + keycode = keycode_config(QK_LAYER_TAP_GET_TAP_KEYCODE(keycode)); + else if (IS_QK_MODS(keycode)) + keycode = keycode_config(QK_MODS_GET_BASIC_KEYCODE(keycode)); + else if (IS_QK_BASIC(keycode)) + keycode = keycode_config(keycode); + if ((keycode == KC_BSPC) && mod_config(get_mods()) & MOD_MASK_CTRL) { + memset(keylog_str, ' ', KEYLOG_LEN); + keylog_str[KEYLOG_LEN] = '\0'; + return; + } + char code = 0; + if (keycode < ARRAY_SIZE(code_to_name)) + code = pgm_read_byte(&code_to_name[keycode]); + if (code) { + memmove(keylog_str, keylog_str + 1, KEYLOG_LEN - 1); + keylog_str[KEYLOG_LEN - 1] = code; } - oled_task_keymap(); - return false; } -void oled_timer_reset(void) { oled_timer = timer_read32(); } +void render_keylog(void) { + oled_write(PSTR("KLG: "), false); + oled_write_ln(keylog_str, false); +} + +void render_wpm(void) { + oled_write(PSTR("WPM: "), false); + oled_write_ln(get_u8_str(get_current_wpm(), ' '), false); +} + +#ifdef DEBUG_MATRIX_SCAN_RATE +void render_scan_rate(void) { + oled_write(PSTR("MSR: "), false); + oled_write_ln(get_u16_str(get_matrix_scan_rate(), ' '), false); +} +#endif + +void oled_render_boot(bool jump_to_bootloader) { + oled_clear(); + static const char PROGMEM qmk_logo[16] = {0x80, 0x81, 0x82, 0x83, 0x84, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4}; + oled_write(qmk_logo, false); + oled_set_cursor(0, 4); + oled_write(qmk_logo, false); + oled_set_cursor(0, 8); + oled_write(qmk_logo, false); + oled_set_cursor(0, 12); + oled_write(qmk_logo, false); + oled_render_dirty(true); +} |