oled_stuff.h (2744B)
1 /* Copyright 2021 HorrorTroll <https://github.com/HorrorTroll> 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 // OLED animation 18 #include "lib/bongocat.h" 19 #include "lib/galaxy.h" 20 #include "lib/wave.c" 21 22 #ifdef OLED_ENABLE 23 bool oled_task_user(void) { 24 led_t led_usb_state = host_keyboard_led_state(); 25 static uint8_t old_layer; 26 uint8_t layer = get_highest_layer(layer_state | default_layer_state); 27 28 if (layer != old_layer) { 29 oled_clear(); 30 } 31 32 old_layer = layer; 33 34 switch (layer) { 35 case 0: 36 render_bongocat(); 37 oled_set_cursor(14, 0); // sets cursor to (column, row) using charactar spacing (4 rows on 128x32 screen, anything more will overflow back to the top) 38 oled_write_P(PSTR("WPM:"), false); 39 oled_write(get_u8_str(get_current_wpm(), '0'), false); // writes wpm on top right corner of string 40 oled_set_cursor(17, 2); 41 oled_write_P(led_usb_state.caps_lock ? PSTR("CAPS") : PSTR(" "), false); 42 oled_set_cursor(17, 3); 43 oled_write_P(led_usb_state.scroll_lock ? PSTR("SCRL") : PSTR(" "), false); 44 break; 45 case 1: 46 // sleep if it has been long enough since we last got a char 47 if (timer_elapsed32(wave_sleep) > OLED_TIMEOUT) { 48 oled_off(); 49 } else { 50 oled_on(); 51 } 52 // time for the next frame? 53 if (timer_elapsed(wave_timer) > FRAME_TIMEOUT) { 54 wave_timer = timer_read(); 55 render_frame(); 56 } 57 58 oled_set_cursor(0, 3); 59 oled_write_P(led_usb_state.caps_lock ? PSTR("CAPS") : PSTR(" "), false); 60 oled_set_cursor(17, 3); 61 oled_write_P(led_usb_state.scroll_lock ? PSTR("SCRL") : PSTR(" "), false); 62 break; 63 case 2: 64 render_galaxy(); 65 break; 66 } 67 return false; 68 } 69 #endif