sharkropad.c (3003B)
1 /* Copyright 2025 @mawaeg 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 3 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 "quantum.h" 18 #include <ctype.h> 19 #include <lib/lib8tion/lib8tion.h> 20 #include <rgb_matrix.h> 21 22 static uint8_t effect_name_len = 0; 23 24 const char *rgb_matrix_get_effect_name(void) { 25 static char buf[32] = {0}; 26 27 snprintf(buf, sizeof(buf), "%s", rgb_matrix_get_mode_name(rgb_matrix_get_mode())); 28 for (uint8_t i = 1; i < sizeof(buf); ++i) { 29 if (buf[i] == 0) { 30 effect_name_len = i; 31 break; 32 } else if (buf[i] == '_') 33 buf[i] = ' '; 34 else if (buf[i - 1] == ' ') 35 buf[i] = toupper(buf[i]); 36 else if (buf[i - 1] != ' ') 37 buf[i] = tolower(buf[i]); 38 } 39 return buf; 40 } 41 42 bool oled_task_kb(void) { 43 if (!oled_task_user()) { 44 return false; 45 } 46 47 static uint8_t last_effect = 0; 48 static uint8_t last_speed = 0; 49 static uint16_t key_timer = 0; 50 static uint8_t start_index = 0; 51 52 uint8_t speedPercentage = scale8(rgb_matrix_get_speed(), 100); 53 bool is_timer_elapsed = timer_elapsed(key_timer) > 200; 54 55 if (last_effect != rgb_matrix_get_mode() || last_speed != speedPercentage || is_timer_elapsed) { 56 last_effect = rgb_matrix_get_mode(); 57 last_speed = speedPercentage; 58 59 oled_write_ln_P(PSTR("Mode: "), false); 60 const char *name = rgb_matrix_get_effect_name(); 61 if (effect_name_len > 21) { 62 if (!is_timer_elapsed && start_index != 0) { 63 start_index -= 1; 64 } else { 65 key_timer = timer_read(); 66 } 67 if (start_index > effect_name_len) { 68 start_index = 0; 69 } 70 for (uint8_t char_index = 0; char_index < 21; char_index++) { 71 if ((start_index + char_index) % effect_name_len == 0 && char_index != 0) { 72 oled_write_char(' ', false); 73 } else { 74 oled_write_char(name[(start_index + char_index) % (effect_name_len + 1)], false); 75 } 76 } 77 start_index += 1; 78 } else { 79 oled_write_ln(name, false); 80 start_index = 0; 81 } 82 83 oled_set_cursor(0, 2); 84 oled_write_ln_P(PSTR("RGB Speed: "), false); 85 oled_write(get_u8_str(speedPercentage, ' '), false); 86 oled_write("%", false); 87 } 88 89 return true; 90 }