diff options
Diffstat (limited to 'keyboards/splitkb/kyria/keymaps/john-ezra/oled.c')
| -rw-r--r-- | keyboards/splitkb/kyria/keymaps/john-ezra/oled.c | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/keyboards/splitkb/kyria/keymaps/john-ezra/oled.c b/keyboards/splitkb/kyria/keymaps/john-ezra/oled.c new file mode 100644 index 000000000..d98cd598b --- /dev/null +++ b/keyboards/splitkb/kyria/keymaps/john-ezra/oled.c | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | /* Copyright 2021 John Ezra | ||
| 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 | //Sets up what the OLED screens display. | ||
| 18 | |||
| 19 | #include QMK_KEYBOARD_H | ||
| 20 | |||
| 21 | int timer = 0; | ||
| 22 | char wpm_counter[5]; | ||
| 23 | int x = 31; | ||
| 24 | int currwpm = 0; | ||
| 25 | int vert_count = 0; | ||
| 26 | |||
| 27 | //============= USER CONFIG PARAMS =============== | ||
| 28 | float max_wpm = 150.0f; //WPM value at the top of the graph window | ||
| 29 | int graph_refresh_interval = 80; //in milliseconds | ||
| 30 | int graph_area_fill_interval = 3; //determines how dense the horizontal lines under the graph line are; lower = more dense | ||
| 31 | int vert_interval = 3; //determines frequency of vertical lines under the graph line | ||
| 32 | bool vert_line = false; //determines whether to draw vertical lines | ||
| 33 | int graph_line_thickness = 2; //determines thickness of graph line in pixels | ||
| 34 | //============= END USER PARAMS =============== | ||
| 35 | |||
| 36 | #ifdef OLED_ENABLE | ||
| 37 | oled_rotation_t oled_init_user(oled_rotation_t rotation) { | ||
| 38 | return OLED_ROTATION_180; | ||
| 39 | } | ||
| 40 | |||
| 41 | static void render_qmk_logo(void) { | ||
| 42 | static const char PROGMEM qmk_logo[] = { | ||
| 43 | 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94, | ||
| 44 | 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4, | ||
| 45 | 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0}; | ||
| 46 | |||
| 47 | oled_write_P(qmk_logo, false); | ||
| 48 | } | ||
| 49 | |||
| 50 | void render_bootmagic_status(void) { | ||
| 51 | oled_write_P((keymap_config.swap_lctl_lgui) ? PSTR("OS: Windows\n\n") : PSTR("OS: MacOS\n\n"), false); | ||
| 52 | oled_write_P((keymap_config.nkro) ? PSTR("NKRO ") : PSTR(" "), false); | ||
| 53 | } | ||
| 54 | |||
| 55 | void render_wpm(void) { | ||
| 56 | //get current WPM value | ||
| 57 | currwpm = get_current_wpm(); | ||
| 58 | //check if it's been long enough before refreshing graph | ||
| 59 | if(timer_elapsed(timer) > graph_refresh_interval){ | ||
| 60 | // main calculation to plot graph line | ||
| 61 | x = 64 - ((currwpm / max_wpm) * 64); | ||
| 62 | //first draw actual value line | ||
| 63 | for(int i = 0; i <= graph_line_thickness - 1; i++){ | ||
| 64 | oled_write_pixel(1, x + i, true); | ||
| 65 | } | ||
| 66 | //then fill in area below the value line | ||
| 67 | if(vert_line){ | ||
| 68 | if(vert_count == vert_interval){ | ||
| 69 | vert_count = 0; | ||
| 70 | while(x <= 64){ | ||
| 71 | oled_write_pixel(1, x, true); | ||
| 72 | x++; | ||
| 73 | } | ||
| 74 | } else { | ||
| 75 | for(int i = 64; i > x; i--){ | ||
| 76 | if(i % graph_area_fill_interval == 0){ | ||
| 77 | oled_write_pixel(1, i, true); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | vert_count++; | ||
| 81 | } | ||
| 82 | } else { | ||
| 83 | for(int i = 64; i > x; i--){ | ||
| 84 | if(i % graph_area_fill_interval == 0){ | ||
| 85 | oled_write_pixel(1, i, true); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | } | ||
| 89 | //then move the entire graph one pixel to the right | ||
| 90 | oled_pan(false); | ||
| 91 | //refresh the timer for the next iteration | ||
| 92 | timer = timer_read(); | ||
| 93 | } | ||
| 94 | //format current WPM value into a printable string | ||
| 95 | char buf[4]; | ||
| 96 | oled_set_cursor(14, 0); | ||
| 97 | oled_write("WPM:", false); | ||
| 98 | buf[0] = currwpm >= 100 ? ((currwpm/100) + '0') : ' '; | ||
| 99 | buf[1] = currwpm >= 10 ? (((currwpm/10) % 10) + '0') : ' '; | ||
| 100 | buf[2] = (currwpm % 10) + '0'; | ||
| 101 | buf[3] = 0; | ||
| 102 | oled_write(buf, false); | ||
| 103 | } | ||
| 104 | |||
| 105 | static void render_status(void) { | ||
| 106 | // QMK Logo and version information | ||
| 107 | render_qmk_logo(); | ||
| 108 | oled_write_P(PSTR("Kyria: Rev1.0\n"), false); | ||
| 109 | |||
| 110 | // Host Keyboard Layer Status | ||
| 111 | oled_write_P(PSTR("Layer: "), false); | ||
| 112 | switch (get_highest_layer(layer_state)) { | ||
| 113 | case 0: | ||
| 114 | oled_write_P(PSTR("Default\n"), false); | ||
| 115 | break; | ||
| 116 | case 2: | ||
| 117 | oled_write_P(PSTR("Lower\n"), false); | ||
| 118 | break; | ||
| 119 | case 3: | ||
| 120 | oled_write_P(PSTR("Raise\n"), false); | ||
| 121 | break; | ||
| 122 | case 4: | ||
| 123 | oled_write_P(PSTR("Adjust\n"), false); | ||
| 124 | break; | ||
| 125 | default: | ||
| 126 | oled_write_P(PSTR("Undefined\n"), false); | ||
| 127 | } | ||
| 128 | |||
| 129 | render_bootmagic_status(); | ||
| 130 | |||
| 131 | // Host Keyboard LED Status | ||
| 132 | led_t led_state = host_keyboard_led_state(); | ||
| 133 | oled_write_P(led_state.caps_lock ? PSTR("CAPLCK ") : PSTR(" "), false); | ||
| 134 | } | ||
| 135 | |||
| 136 | void oled_task_user(void) { | ||
| 137 | if (is_keyboard_master()) { | ||
| 138 | render_status(); | ||
| 139 | } else { | ||
| 140 | render_wpm(); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | #endif | ||
