You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

830 lines
28 KiB

[Keymap] Cleanup and updating of drashna keymap code (#11516) * Update other keyboards for rgb matrix changes * Remove customized bootmagic code * Fix corne layout compilation error * Fix compiler errors with all keymaps * Add Simple Visualizer for ergodox infinity * Fix compile issue with Corne * Fix keymap stuff * Add alias for mouse layer * Add Halmak Keyboard layout * Updates for Kyria * Add support for oled interval * Change RGB stuff [CHANGE] Fix coexistence issues * Fix rgb_stuff * Add custom ploopyco mouse keymap * Decrease default dwell time * Updates based on last breaking changes update * Disable command on dactyl * Update ergodox to use proper commands for rgb matrix indicators * Update all rgb matrix indicator functions * Update rules for dactyl-manuform * Reduce wait time for mouse layer off event * Add more info to logger * Add wrappers for get_tapping term * Move version.h include into only file that actually needs it * Update rgb sleep stuff * Update key print function * Change DM keymap settings * Change pin for DM Manuform * Add Proton C stuff for Corne keymap * more arm corne tinkering * Even more arm stuff for corne * Cleanup corne stuff * redirect default keymap to drashna because I am a very bad man * change corne rgb priority * Update tractyl manuform to not conflict * Add more secret stuff * more dactyl tweaks * Add more options to split transport * Changes of oled support * Change split settings * Improve keylogger formatting more * tweak oled stuff * Oled and such tweaks * Reduce brightness due to leds * Decrease brightness more * Only run layer code if master
3 years ago
[Keymap] Cleanup and updating of drashna keymap code (#11516) * Update other keyboards for rgb matrix changes * Remove customized bootmagic code * Fix corne layout compilation error * Fix compiler errors with all keymaps * Add Simple Visualizer for ergodox infinity * Fix compile issue with Corne * Fix keymap stuff * Add alias for mouse layer * Add Halmak Keyboard layout * Updates for Kyria * Add support for oled interval * Change RGB stuff [CHANGE] Fix coexistence issues * Fix rgb_stuff * Add custom ploopyco mouse keymap * Decrease default dwell time * Updates based on last breaking changes update * Disable command on dactyl * Update ergodox to use proper commands for rgb matrix indicators * Update all rgb matrix indicator functions * Update rules for dactyl-manuform * Reduce wait time for mouse layer off event * Add more info to logger * Add wrappers for get_tapping term * Move version.h include into only file that actually needs it * Update rgb sleep stuff * Update key print function * Change DM keymap settings * Change pin for DM Manuform * Add Proton C stuff for Corne keymap * more arm corne tinkering * Even more arm stuff for corne * Cleanup corne stuff * redirect default keymap to drashna because I am a very bad man * change corne rgb priority * Update tractyl manuform to not conflict * Add more secret stuff * more dactyl tweaks * Add more options to split transport * Changes of oled support * Change split settings * Improve keylogger formatting more * tweak oled stuff * Oled and such tweaks * Reduce brightness due to leds * Decrease brightness more * Only run layer code if master
3 years ago
  1. /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  2. * Copyright 2021 John Ezra - wpm graph
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "drashna.h"
  18. #include <ctype.h>
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include "lib/lib8tion/lib8tion.h"
  22. #ifdef UNICODE_COMMON_ENABLE
  23. # include "process_unicode_common.h"
  24. # include "keyrecords/unicode.h"
  25. #endif
  26. #ifdef AUDIO_CLICKY
  27. # include "process_clicky.h"
  28. #endif
  29. #ifndef OLED_BRIGHTNESS_STEP
  30. # define OLED_BRIGHTNESS_STEP 32
  31. #endif
  32. bool is_oled_enabled = true, is_oled_locked = false, is_oled_force_off = false;
  33. uint32_t oled_timer = 0;
  34. char oled_keylog_str[OLED_KEYLOGGER_LENGTH + 1] = {0};
  35. deferred_token kittoken;
  36. extern uint8_t oled_buffer[OLED_MATRIX_SIZE];
  37. extern OLED_BLOCK_TYPE oled_dirty;
  38. void oled_pan_section(bool left, uint16_t y_start, uint16_t y_end, uint16_t x_start, uint16_t x_end) {
  39. uint16_t i = 0;
  40. for (uint16_t y = y_start; y < y_end; y++) {
  41. if (left) {
  42. for (uint16_t x = x_start; x < x_end - 1; x++) {
  43. i = y * OLED_DISPLAY_WIDTH + x;
  44. oled_buffer[i] = oled_buffer[i + 1];
  45. oled_dirty |= ((OLED_BLOCK_TYPE)1 << (i / OLED_BLOCK_SIZE));
  46. }
  47. } else {
  48. for (uint16_t x = x_end - 1; x > 0; x--) {
  49. i = y * OLED_DISPLAY_WIDTH + x;
  50. oled_buffer[i] = oled_buffer[i - 1];
  51. oled_dirty |= ((OLED_BLOCK_TYPE)1 << (i / OLED_BLOCK_SIZE));
  52. }
  53. }
  54. }
  55. }
  56. /**
  57. * @brief parses pressed keycodes and saves to buffer
  58. *
  59. * @param keycode Keycode pressed from switch matrix
  60. * @param record keyrecord_t data structure
  61. */
  62. void add_keylog(uint16_t keycode, keyrecord_t *record) {
  63. if (IS_QK_MOD_TAP(keycode)) {
  64. if (record->tap.count) {
  65. keycode = keycode_config(QK_MOD_TAP_GET_TAP_KEYCODE(keycode));
  66. } else {
  67. keycode = keycode_config(0xE0 + biton(QK_MOD_TAP_GET_MODS(keycode) & 0xF) + biton(QK_MOD_TAP_GET_MODS(keycode) & 0x10));
  68. }
  69. } else if (IS_QK_LAYER_TAP(keycode) && record->tap.count) {
  70. keycode = keycode_config(QK_LAYER_TAP_GET_TAP_KEYCODE(keycode));
  71. } else if (IS_QK_MODS(keycode)) {
  72. keycode = keycode_config(QK_MODS_GET_BASIC_KEYCODE(keycode));
  73. } else if (IS_QK_ONE_SHOT_MOD(keycode)) {
  74. keycode = keycode_config(0xE0 + biton(QK_ONE_SHOT_MOD_GET_MODS(keycode) & 0xF) + biton(QK_ONE_SHOT_MOD_GET_MODS(keycode) & 0x10));
  75. } else if (IS_QK_BASIC(keycode)) {
  76. keycode = keycode_config(keycode);
  77. }
  78. if ((keycode == KC_BSPC) && mod_config(get_mods() | get_oneshot_mods()) & MOD_MASK_CTRL) {
  79. memset(oled_keylog_str, ' ', OLED_KEYLOGGER_LENGTH);
  80. oled_keylog_str[OLED_KEYLOGGER_LENGTH] = 0x00;
  81. return;
  82. }
  83. if (keycode > ARRAY_SIZE(code_to_name)) {
  84. return;
  85. }
  86. memmove(oled_keylog_str, oled_keylog_str + 1, OLED_KEYLOGGER_LENGTH - 1);
  87. oled_keylog_str[(OLED_KEYLOGGER_LENGTH - 1)] = pgm_read_byte(&code_to_name[keycode]);
  88. }
  89. /**
  90. * @brief Keycode handler for oled display.
  91. *
  92. * This adds pressed keys to buffer, but also resets the oled timer
  93. *
  94. * @param keycode Keycode from matrix
  95. * @param record keyrecord data struture
  96. * @return true
  97. * @return false
  98. */
  99. bool process_record_user_oled(uint16_t keycode, keyrecord_t *record) {
  100. if (record->event.pressed) {
  101. add_keylog(keycode, record);
  102. if (keycode == OLED_BRIGHTNESS_INC) {
  103. userspace_config.oled_brightness = qadd8(userspace_config.oled_brightness, OLED_BRIGHTNESS_STEP);
  104. oled_set_brightness(userspace_config.oled_brightness);
  105. eeconfig_update_user_config(&userspace_config.raw);
  106. } else if (keycode == OLED_BRIGHTNESS_DEC) {
  107. userspace_config.oled_brightness = qsub8(userspace_config.oled_brightness, OLED_BRIGHTNESS_STEP);
  108. oled_set_brightness(userspace_config.oled_brightness);
  109. eeconfig_update_user_config(&userspace_config.raw);
  110. } else if (keycode == OLED_LOCK) {
  111. is_oled_locked = !is_oled_locked;
  112. if (is_oled_locked) {
  113. oled_on();
  114. }
  115. }
  116. }
  117. return true;
  118. }
  119. /**
  120. * @brief Renders keylogger buffer to oled
  121. *
  122. */
  123. void render_keylogger_status(uint8_t col, uint8_t line) {
  124. #ifdef OLED_DISPLAY_VERBOSE
  125. oled_set_cursor(col, line);
  126. #endif
  127. oled_write_P(PSTR(OLED_RENDER_KEYLOGGER), false);
  128. oled_write(oled_keylog_str, false);
  129. #ifdef OLED_DISPLAY_VERBOSE
  130. oled_advance_page(true);
  131. #endif
  132. }
  133. /**
  134. * @brief Renders default layer state (aka layout) to oled
  135. *
  136. */
  137. void render_default_layer_state(uint8_t col, uint8_t line) {
  138. #ifdef OLED_DISPLAY_VERBOSE
  139. oled_set_cursor(col, line);
  140. oled_write_P(PSTR(OLED_RENDER_LAYOUT_NAME), false);
  141. static char layer_state_buffer[11] = {0};
  142. static layer_state_t old_state = 0;
  143. if (old_state != default_layer_state) {
  144. snprintf(layer_state_buffer, sizeof(layer_state_buffer), "%-10s", get_layer_name_string(default_layer_state, false));
  145. old_state = default_layer_state;
  146. }
  147. oled_write(layer_state_buffer, false);
  148. oled_advance_page(true);
  149. #else
  150. oled_write_P(PSTR(OLED_RENDER_LAYOUT_NAME), false);
  151. switch (get_highest_layer(default_layer_state)) {
  152. case _QWERTY:
  153. oled_write_P(PSTR(OLED_RENDER_LAYOUT_QWERTY), false);
  154. break;
  155. case _COLEMAK_DH:
  156. oled_write_P(PSTR(OLED_RENDER_LAYOUT_COLEMAK_DH), false);
  157. break;
  158. case _COLEMAK:
  159. oled_write_P(PSTR(OLED_RENDER_LAYOUT_COLEMAK), false);
  160. break;
  161. case _DVORAK:
  162. oled_write_P(PSTR(OLED_RENDER_LAYOUT_DVORAK), false);
  163. break;
  164. }
  165. #endif
  166. }
  167. /**
  168. * @brief Renders the active layers to the OLED
  169. *
  170. */
  171. void render_layer_state(uint8_t col, uint8_t line) {
  172. #ifdef OLED_DISPLAY_VERBOSE
  173. uint8_t layer_is[4] = {0, 4, 4, 4};
  174. if (layer_state_is(_ADJUST)) {
  175. layer_is[0] = 3;
  176. } else if (layer_state_is(_RAISE)) {
  177. layer_is[0] = 1;
  178. } else if (layer_state_is(_LOWER)) {
  179. layer_is[0] = 2;
  180. }
  181. if (layer_state_is(_MOUSE)) {
  182. layer_is[1] = 6;
  183. }
  184. if (layer_state_is(_GAMEPAD)) {
  185. layer_is[2] = 5;
  186. }
  187. oled_set_cursor(col, line);
  188. oled_write_raw_P(tri_layer_image[layer_is[0]][0], sizeof(tri_layer_image[0][0]));
  189. oled_set_cursor(col + 4, line);
  190. oled_write_raw_P(tri_layer_image[layer_is[1]][0], sizeof(tri_layer_image[0][0]));
  191. oled_set_cursor(col + 8, line);
  192. oled_write_raw_P(tri_layer_image[layer_is[2]][0], sizeof(tri_layer_image[0][0]));
  193. oled_set_cursor(col + 13, line);
  194. oled_write_P(PSTR("Diablo2"), layer_state_is(_DIABLOII));
  195. oled_advance_page(true);
  196. oled_set_cursor(col, line + 1);
  197. oled_write_raw_P(tri_layer_image[layer_is[0]][1], sizeof(tri_layer_image[0][0]));
  198. oled_set_cursor(col + 4, line + 1);
  199. oled_write_raw_P(tri_layer_image[layer_is[1]][1], sizeof(tri_layer_image[0][0]));
  200. oled_set_cursor(col + 8, line + 1);
  201. oled_write_raw_P(tri_layer_image[layer_is[2]][1], sizeof(tri_layer_image[0][0]));
  202. oled_set_cursor(col + 13, line + 1);
  203. oled_write_P(PSTR("Diablo3"), layer_state_is(_DIABLO));
  204. oled_advance_page(true);
  205. oled_set_cursor(col, line + 2);
  206. oled_write_raw_P(tri_layer_image[layer_is[0]][2], sizeof(tri_layer_image[0][0]));
  207. oled_set_cursor(col + 4, line + 2);
  208. oled_write_raw_P(tri_layer_image[layer_is[1]][2], sizeof(tri_layer_image[0][0]));
  209. oled_set_cursor(col + 8, line + 2);
  210. oled_write_raw_P(tri_layer_image[layer_is[2]][2], sizeof(tri_layer_image[0][0]));
  211. oled_set_cursor(col + 13, line + 2);
  212. oled_write_P(PSTR("Media"), layer_state_is(_MEDIA));
  213. #else
  214. oled_write_P(PSTR(OLED_RENDER_LAYER_NAME), false);
  215. oled_write_P(PSTR(OLED_RENDER_LAYER_LOWER), layer_state_is(_LOWER));
  216. oled_write_P(PSTR(OLED_RENDER_LAYER_RAISE), layer_state_is(_RAISE));
  217. #endif
  218. oled_advance_page(true);
  219. }
  220. /**
  221. * @brief Renders the current lock status to oled
  222. *
  223. * @param led_usb_state Current keyboard led state
  224. */
  225. void render_keylock_status(led_t led_usb_state, uint8_t col, uint8_t line) {
  226. #if defined(OLED_DISPLAY_VERBOSE)
  227. oled_set_cursor(col, line);
  228. #endif
  229. #ifdef CAPS_WORD_ENABLE
  230. led_usb_state.caps_lock |= is_caps_word_on();
  231. #endif
  232. oled_write_P(PSTR(OLED_RENDER_LOCK_NAME), false);
  233. #if !defined(OLED_DISPLAY_VERBOSE)
  234. oled_write_P(PSTR(" "), false);
  235. #endif
  236. oled_write_P(PSTR(OLED_RENDER_LOCK_NUML), led_usb_state.num_lock);
  237. oled_write_P(PSTR(" "), false);
  238. oled_write_P(PSTR(OLED_RENDER_LOCK_CAPS), led_usb_state.caps_lock);
  239. #if defined(OLED_DISPLAY_VERBOSE)
  240. oled_write_P(PSTR(" "), false);
  241. oled_write_P(PSTR(OLED_RENDER_LOCK_SCLK), led_usb_state.scroll_lock);
  242. #endif
  243. }
  244. /**
  245. * @brief Renders the matrix scan rate to the host system
  246. *
  247. */
  248. void render_matrix_scan_rate(uint8_t padding, uint8_t col, uint8_t line) {
  249. #ifdef DEBUG_MATRIX_SCAN_RATE
  250. oled_set_cursor(col, line);
  251. oled_write_P(PSTR("MS:"), false);
  252. if (padding) {
  253. for (uint8_t n = padding; n > 0; n--) {
  254. oled_write_P(PSTR(" "), false);
  255. }
  256. }
  257. oled_write(get_u16_str(get_matrix_scan_rate(), ' '), false);
  258. #endif
  259. }
  260. /**
  261. * @brief Renders the modifier state
  262. *
  263. * @param modifiers Modifiers to check against (real, weak, onesheot, etc;)
  264. */
  265. void render_mod_status(uint8_t modifiers, uint8_t col, uint8_t line) {
  266. static const char PROGMEM mod_status[5][3] = {{0xE8, 0xE9, 0}, {0xE4, 0xE5, 0}, {0xE6, 0xE7, 0}, {0xEA, 0xEB, 0}, {0xEC, 0xED, 0}};
  267. #if defined(OLED_DISPLAY_VERBOSE)
  268. oled_set_cursor(col, line);
  269. #endif
  270. bool is_caps = host_keyboard_led_state().caps_lock;
  271. #ifdef CAPS_WORD_ENABLE
  272. is_caps |= is_caps_word_on();
  273. #endif
  274. oled_write_P(PSTR(OLED_RENDER_MODS_NAME), false);
  275. #if defined(OLED_DISPLAY_VERBOSE)
  276. oled_write_P(mod_status[0], (modifiers & MOD_BIT(KC_LSFT)) || is_caps);
  277. oled_write_P(mod_status[!keymap_config.swap_lctl_lgui ? 3 : 4], (modifiers & MOD_BIT(KC_LGUI)));
  278. oled_write_P(mod_status[2], (modifiers & MOD_BIT(KC_LALT)));
  279. oled_write_P(mod_status[1], (modifiers & MOD_BIT(KC_LCTL)));
  280. oled_write_P(mod_status[1], (modifiers & MOD_BIT(KC_RCTL)));
  281. oled_write_P(mod_status[2], (modifiers & MOD_BIT(KC_RALT)));
  282. oled_write_P(mod_status[!keymap_config.swap_lctl_lgui ? 3 : 4], (modifiers & MOD_BIT(KC_RGUI)));
  283. oled_write_P(mod_status[0], (modifiers & MOD_BIT(KC_RSFT)) || is_caps);
  284. #else
  285. oled_write_P(mod_status[0], (modifiers & MOD_MASK_SHIFT) || is_caps);
  286. oled_write_P(mod_status[!keymap_config.swap_lctl_lgui ? 3 : 4], (modifiers & MOD_MASK_GUI));
  287. oled_write_P(PSTR(" "), false);
  288. oled_write_P(mod_status[2], (modifiers & MOD_MASK_ALT));
  289. oled_write_P(mod_status[1], (modifiers & MOD_MASK_CTRL));
  290. #endif
  291. }
  292. #ifdef SWAP_HANDS_ENABLE
  293. extern bool swap_hands;
  294. #endif
  295. void render_bootmagic_status(uint8_t col, uint8_t line) {
  296. /* Show Ctrl-Gui Swap options */
  297. static const char PROGMEM logo[][2][3] = {
  298. {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  299. {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  300. };
  301. bool is_bootmagic_on;
  302. #ifdef OLED_DISPLAY_VERBOSE
  303. oled_set_cursor(col, line);
  304. // oled_set_cursor(7, 3);
  305. is_bootmagic_on = !keymap_config.swap_lctl_lgui;
  306. #else
  307. is_bootmagic_on = keymap_config.swap_lctl_lgui;
  308. #endif
  309. #ifdef OLED_DISPLAY_VERBOSE
  310. if (keymap_config.swap_lctl_lgui)
  311. #else
  312. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_NAME), false);
  313. oled_write_P(PSTR(" "), false);
  314. #endif
  315. {
  316. oled_write_P(logo[1][0], is_bootmagic_on);
  317. #ifdef OLED_DISPLAY_VERBOSE
  318. } else {
  319. #endif
  320. oled_write_P(logo[0][0], !is_bootmagic_on);
  321. }
  322. #ifndef OLED_DISPLAY_VERBOSE
  323. oled_write_P(PSTR(" "), false);
  324. oled_write_P(logo[1][1], is_bootmagic_on);
  325. oled_write_P(logo[0][1], !is_bootmagic_on);
  326. #endif
  327. oled_write_P(PSTR(" "), false);
  328. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_NKRO), keymap_config.nkro);
  329. oled_write_P(PSTR(" "), false);
  330. #if defined(AUTOCORRECT_ENABLE)
  331. oled_write_P(PSTR("CRCT"), autocorrect_is_enabled());
  332. oled_write_P(PSTR(" "), false);
  333. #else
  334. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_NOGUI), keymap_config.no_gui);
  335. #endif
  336. #ifdef OLED_DISPLAY_VERBOSE
  337. oled_set_cursor(col, line + 1);
  338. if (keymap_config.swap_lctl_lgui) {
  339. oled_write_P(logo[1][1], is_bootmagic_on);
  340. } else {
  341. oled_write_P(logo[0][1], !is_bootmagic_on);
  342. }
  343. #endif
  344. oled_write_P(PSTR(" "), false);
  345. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_ONESHOT), is_oneshot_enabled());
  346. #ifdef SWAP_HANDS_ENABLE
  347. oled_write_P(PSTR(" "), false);
  348. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_SWAP), swap_hands);
  349. oled_write_P(PSTR(" "), false);
  350. #endif
  351. }
  352. void render_user_status(uint8_t col, uint8_t line) {
  353. #ifdef AUDIO_ENABLE
  354. bool is_audio_on = false, l_is_clicky_on = false;
  355. # ifdef SPLIT_KEYBOARD
  356. is_audio_on = user_state.audio_enable;
  357. # ifdef AUDIO_CLICKY
  358. l_is_clicky_on = user_state.audio_clicky_enable;
  359. # endif
  360. # else
  361. is_audio_on = is_audio_on();
  362. # ifdef AUDIO_CLICKY
  363. l_is_clicky_on = is_clicky_on();
  364. # endif
  365. # endif
  366. #endif
  367. #if defined(OLED_DISPLAY_VERBOSE)
  368. oled_set_cursor(col, line);
  369. #endif
  370. oled_write_P(PSTR(OLED_RENDER_USER_NAME), false);
  371. #if !defined(OLED_DISPLAY_VERBOSE)
  372. oled_write_P(PSTR(" "), false);
  373. #endif
  374. #if defined(RGB_MATRIX_ENABLE)
  375. oled_write_P(PSTR(OLED_RENDER_USER_ANIM), userspace_config.rgb_matrix_idle_anim);
  376. # if !defined(OLED_DISPLAY_VERBOSE)
  377. oled_write_P(PSTR(" "), false);
  378. # endif
  379. #elif defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
  380. static const char PROGMEM mouse_lock[3] = {0xF2, 0xF3, 0};
  381. oled_write_P(mouse_lock, get_auto_mouse_toggle());
  382. #endif
  383. #ifdef AUDIO_ENABLE
  384. static const char PROGMEM audio_status[2][3] = {{0xE0, 0xE1, 0}, {0xE2, 0xE3, 0}};
  385. oled_write_P(audio_status[is_audio_on], false);
  386. # ifdef AUDIO_CLICKY
  387. static const char PROGMEM audio_clicky_status[2][3] = {{0xF4, 0xF5, 0}, {0xF6, 0xF7, 0}};
  388. oled_write_P(audio_clicky_status[l_is_clicky_on && is_audio_on], false);
  389. # if !defined(OLED_DISPLAY_VERBOSE)
  390. oled_write_P(PSTR(" "), false);
  391. # endif
  392. # endif
  393. #endif
  394. static const char PROGMEM rgb_layer_status[2][3] = {{0xEE, 0xEF, 0}, {0xF0, 0xF1, 0}};
  395. oled_write_P(rgb_layer_status[userspace_config.rgb_layer_change], false);
  396. static const char PROGMEM cat_mode[2][3] = {{0xF8, 0xF9, 0}, {0xF6, 0xF7, 0}};
  397. oled_write_P(cat_mode[0], get_keyboard_lock());
  398. #if defined(UNICODE_COMMON_ENABLE)
  399. static const char PROGMEM uc_mod_status[5][3] = {{0xEC, 0xED, 0}, {0x20, 0x20, 0}, {0x20, 0x20, 0}, {0x20, 0x20, 0}, {0xEA, 0xEB, 0}};
  400. oled_write_P(uc_mod_status[get_unicode_input_mode()], false);
  401. #endif
  402. if (userspace_config.nuke_switch) {
  403. #if !defined(OLED_DISPLAY_VERBOSE)
  404. oled_write_P(PSTR(" "), false);
  405. #endif
  406. static const char PROGMEM nukem_good[2] = {0xFA, 0};
  407. oled_write_P(nukem_good, false);
  408. #if !defined(OLED_DISPLAY_VERBOSE)
  409. oled_advance_page(true);
  410. #endif
  411. }
  412. #if defined(OLED_DISPLAY_VERBOSE)
  413. oled_advance_page(true);
  414. #endif
  415. }
  416. void render_rgb_hsv(uint8_t col, uint8_t line) {
  417. oled_set_cursor(col, line);
  418. oled_write_P(PSTR("HSV: "), false);
  419. #ifdef RGB_MATRIX_ENABLE
  420. oled_write(get_u8_str(rgb_matrix_get_hue(), ' '), false);
  421. oled_write_P(PSTR(", "), false);
  422. oled_write(get_u8_str(rgb_matrix_get_sat(), ' '), false);
  423. oled_write_P(PSTR(", "), false);
  424. oled_write(get_u8_str(rgb_matrix_get_val(), ' '), false);
  425. #elif RGBLIGHT_ENABLE
  426. if (is_rgblight_startup_running()) {
  427. oled_write_P(PSTR("Start Animation"), false);
  428. } else {
  429. oled_write(get_u8_str(rgblight_get_hue(), ' '), false);
  430. oled_write_P(PSTR(", "), false);
  431. oled_write(get_u8_str(rgblight_get_sat(), ' '), false);
  432. oled_write_P(PSTR(", "), false);
  433. oled_write(get_u8_str(rgblight_get_val(), ' '), false);
  434. }
  435. #endif
  436. }
  437. void render_rgb_mode(uint8_t col, uint8_t line) {
  438. oled_set_cursor(col, line);
  439. __attribute__((unused)) static uint8_t mode;
  440. bool need_update = false;
  441. static char buf[21] = {0};
  442. #ifdef RGB_MATRIX_ENABLE
  443. if (mode != rgb_matrix_get_mode()) {
  444. snprintf(buf, sizeof(buf), "%-20s", rgb_matrix_name(rgb_matrix_get_mode()));
  445. mode = rgb_matrix_get_mode();
  446. need_update = true;
  447. }
  448. #elif RGBLIGHT_ENABLE
  449. if (mode != rgblight_get_mode()) {
  450. snprintf(buf, sizeof(buf), "%-20s", rgblight_name(rgblight_get_mode()));
  451. mode = rgblight_get_mode();
  452. need_update = true;
  453. }
  454. #endif
  455. if (need_update) {
  456. for (uint8_t i = 1; i < sizeof(buf); ++i) {
  457. if (buf[i] == 0)
  458. break;
  459. else if (buf[i] == '_')
  460. buf[i] = ' ';
  461. else if (buf[i - 1] == ' ')
  462. buf[i] = toupper(buf[i]);
  463. else if (buf[i - 1] != ' ')
  464. buf[i] = tolower(buf[i]);
  465. }
  466. }
  467. oled_write(buf, false);
  468. }
  469. void render_wpm(uint8_t padding, uint8_t col, uint8_t line) {
  470. #ifdef WPM_ENABLE
  471. oled_set_cursor(col, line);
  472. oled_write_P(PSTR(OLED_RENDER_WPM_COUNTER), false);
  473. if (padding) {
  474. for (uint8_t n = padding; n > 0; n--) {
  475. oled_write_P(PSTR(" "), false);
  476. }
  477. }
  478. oled_write(get_u8_str(get_current_wpm(), ' '), false);
  479. #endif
  480. }
  481. //============= USER CONFIG PARAMS ===============
  482. // wpm graph originally designed by john-ezra
  483. // for 128x128:
  484. // max_lines_graph = 54;
  485. // vertical_offset = 64;
  486. // for 128x64:
  487. // max_lines_graph = 64;
  488. // vertical_offset = 0;
  489. void render_wpm_graph(uint8_t max_lines_graph, uint8_t vertical_offset) {
  490. #ifdef WPM_ENABLE
  491. static uint16_t timer = 0;
  492. static uint8_t x = OLED_DISPLAY_HEIGHT - 1;
  493. uint8_t currwpm = get_current_wpm();
  494. float max_wpm = OLED_WPM_GRAPH_MAX_WPM;
  495. if (timer_elapsed(timer) > OLED_WPM_GRAPH_REFRESH_INTERVAL) { // check if it's been long enough before refreshing graph
  496. x = (max_lines_graph - 1) - ((currwpm / max_wpm) * (max_lines_graph - 1)); // main calculation to plot graph line
  497. for (uint8_t i = 0; i <= OLED_WPM_GRAPH_GRAPH_LINE_THICKNESS - 1; i++) { // first draw actual value line
  498. oled_write_pixel(3, x + i + vertical_offset, true);
  499. }
  500. # ifdef OLED_WPM_GRAPH_VERTICAL_LINE
  501. static uint8_t vert_count = 0;
  502. if (vert_count == OLED_WPM_GRAPH_VERTCAL_LINE_INTERVAL) {
  503. vert_count = 0;
  504. while (x <= (max_lines_graph - 1)) {
  505. oled_write_pixel(3, x + vertical_offset, true);
  506. x++;
  507. }
  508. } else {
  509. for (uint8_t i = (max_lines_graph - 1); i > x; i--) {
  510. if (i % OLED_WPM_GRAPH_AREA_FILL_INTERVAL == 0) {
  511. oled_write_pixel(3, i + vertical_offset, true);
  512. }
  513. }
  514. vert_count++;
  515. }
  516. # else
  517. for (int i = (max_lines_graph - 1); i > x; i--) {
  518. if (i % OLED_WPM_GRAPH_AREA_FILL_INTERVAL == 0) {
  519. oled_write_pixel(3, i + vertical_offset, true);
  520. }
  521. }
  522. # endif
  523. # include <math.h>
  524. uint8_t y_start = ceil(vertical_offset / 8);
  525. uint8_t y_length = y_start + ceil(max_lines_graph / 8);
  526. oled_pan_section(false, y_start, y_length, 3, 125); // then move the entire graph one pixel to the right
  527. timer = timer_read(); // refresh the timer for the next iteration
  528. }
  529. #endif
  530. }
  531. #if defined(POINTING_DEVICE_ENABLE)
  532. void render_pointing_dpi_status(uint16_t cpi, uint8_t padding, uint8_t col, uint8_t line) {
  533. oled_set_cursor(col, line);
  534. oled_write_P(PSTR("CPI:"), false);
  535. if (padding) {
  536. for (uint8_t n = padding - 1; n > 0; n--) {
  537. oled_write_P(PSTR(" "), false);
  538. }
  539. }
  540. oled_write(get_u16_str(cpi, ' '), false);
  541. }
  542. #endif
  543. // WPM-responsive animation stuff here
  544. #define OLED_SLEEP_FRAMES 2
  545. #define OLED_SLEEP_SPEED 10 // below this wpm value your animation will idle
  546. #define OLED_WAKE_FRAMES 2 // uncomment if >1
  547. #define OLED_WAKE_SPEED OLED_SLEEP_SPEED // below this wpm value your animation will idle
  548. #define OLED_KAKI_FRAMES 3
  549. #define OLED_KAKI_SPEED 40 // above this wpm value typing animation to triggere
  550. #define OLED_RTOGI_FRAMES 2
  551. // #define OLED_LTOGI_FRAMES 2
  552. // #define ANIM_FRAME_DURATION 500 // how long each frame lasts in ms
  553. // #define SLEEP_TIMER 60000 // should sleep after this period of 0 wpm, needs fixing
  554. #if (OLED_SLEEP_FRAMES > OLED_ANIM_MAX_FRAMES) || (OLED_WAKE_FRAMES > OLED_ANIM_MAX_FRAMES) || (OLED_KAKI_FRAMES > OLED_ANIM_MAX_FRAMES) || (OLED_RTOGI_FRAMES > OLED_ANIM_MAX_FRAMES)
  555. # error frame size too large
  556. #endif
  557. static uint8_t animation_frame = 0;
  558. static uint8_t animation_type = 0;
  559. void render_kitty(uint8_t col, uint8_t line) {
  560. for (uint8_t i = 0; i < 4; i++) {
  561. oled_set_cursor(col, line + i);
  562. oled_write_raw_P(animation[animation_type][animation_frame][i], OLED_ANIM_SIZE);
  563. }
  564. }
  565. void render_unicode_mode(uint8_t col, uint8_t line) {
  566. #if defined(CUSTOM_UNICODE_ENABLE) && defined(UNICODE_COMMON_ENABLE)
  567. oled_set_cursor(col, line);
  568. oled_write_P(PSTR("Unicode:"), false);
  569. oled_write_P(unicode_mode_str[unicode_typing_mode], false);
  570. #endif
  571. }
  572. uint32_t kitty_animation_phases(uint32_t triger_time, void *cb_arg) {
  573. static uint32_t anim_frame_duration = 500;
  574. #if defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
  575. if (get_auto_mouse_toggle()) {
  576. animation_frame = (animation_frame + 1) % OLED_RTOGI_FRAMES;
  577. animation_type = 3;
  578. anim_frame_duration = 300;
  579. } else
  580. #endif
  581. {
  582. #ifdef WPM_ENABLE
  583. if (get_current_wpm() <= OLED_SLEEP_SPEED) {
  584. #endif
  585. animation_frame = (animation_frame + 1) % OLED_SLEEP_FRAMES;
  586. animation_type = 0;
  587. anim_frame_duration = 500;
  588. #ifdef WPM_ENABLE
  589. } else if (get_current_wpm() > OLED_WAKE_SPEED) {
  590. animation_frame = (animation_frame + 1) % OLED_WAKE_FRAMES;
  591. animation_type = 1;
  592. anim_frame_duration = 800;
  593. } else if (get_current_wpm() >= OLED_KAKI_SPEED) {
  594. animation_frame = (animation_frame + 1) % OLED_KAKI_FRAMES;
  595. animation_type = 2;
  596. anim_frame_duration = 500;
  597. }
  598. #endif
  599. }
  600. return anim_frame_duration;
  601. }
  602. void render_mouse_mode(uint8_t col, uint8_t line) {
  603. #if (defined(KEYBOARD_bastardkb_charybdis) || defined(KEYBOARD_handwired_tractyl_manuform)) && defined(POINTING_DEVICE_ENABLE)
  604. // credit and thanks to jaspertandy on discord for these images
  605. uint8_t image_index = 0;
  606. # ifdef OLED_DISPLAY_TEST
  607. image_index = animation_frame;
  608. # else
  609. if (charybdis_get_pointer_sniping_enabled()) {
  610. image_index = 1;
  611. } else if (charybdis_get_pointer_dragscroll_enabled()) {
  612. image_index = 2;
  613. }
  614. # endif
  615. oled_set_cursor(col, line);
  616. oled_write_raw_P(mouse_logo[image_index][0], 16);
  617. oled_set_cursor(col, line + 1);
  618. oled_write_raw_P(mouse_logo[image_index][1], 16);
  619. #endif
  620. }
  621. void render_status_right(void) {
  622. #if defined(OLED_DISPLAY_VERBOSE)
  623. render_default_layer_state(1, 1);
  624. #else
  625. render_default_layer_state(0, 0);
  626. #endif
  627. /* Show Keyboard Layout */
  628. render_layer_state(1, 2);
  629. render_mod_status(get_mods() | get_oneshot_mods(), 1, 5);
  630. #if !defined(OLED_DISPLAY_VERBOSE) && defined(WPM_ENABLE) && !defined(STM32F303xC)
  631. render_wpm(2, 7, 1);
  632. #endif
  633. render_keylock_status(host_keyboard_led_state(), 1, 6);
  634. }
  635. void render_status_left(void) {
  636. #if defined(OLED_DISPLAY_VERBOSE)
  637. render_kitty(0, 1);
  638. # if defined(WPM_ENABLE)
  639. render_wpm(1, 7, 1);
  640. # elif defined(DEBUG_MATRIX_SCAN_RATE)
  641. render_matrix_scan_rate(1, 7, 1);
  642. # endif
  643. # if (defined(KEYBOARD_bastardkb_charybdis) || defined(KEYBOARD_handwired_tractyl_manuform)) && defined(POINTING_DEVICE_ENABLE)
  644. render_pointing_dpi_status(charybdis_get_pointer_sniping_enabled() ? charybdis_get_pointer_sniping_dpi() : charybdis_get_pointer_default_dpi(), 1, 7, 2);
  645. render_mouse_mode(17, 1);
  646. # elif defined(WPM_ENABLE) && defined(DEBUG_MATRIX_SCAN_RATE)
  647. render_matrix_scan_rate(1, 7, 2);
  648. # endif
  649. /* Show Keyboard Layout */
  650. render_bootmagic_status(7, 3);
  651. render_user_status(1, 5);
  652. render_keylogger_status(1, 6);
  653. #else
  654. render_default_layer_state(0, 0);
  655. /* Show Keyboard Layout */
  656. render_bootmagic_status(7, 3);
  657. render_user_status(1, 5);
  658. render_keylogger_status(1, 6);
  659. #endif
  660. }
  661. __attribute__((weak)) void oled_render_large_display(bool side) {
  662. if (side) {
  663. render_rgb_hsv(1, 7);
  664. render_rgb_mode(1, 8);
  665. render_wpm_graph(48, 72);
  666. } else {
  667. oled_advance_page(true);
  668. oled_advance_page(true);
  669. oled_set_cursor(0, 9);
  670. oled_write_raw_P(qmk_logo, 384); // is 3 rows of 128 pixels, so 384 bytes.
  671. render_unicode_mode(1, 14);
  672. }
  673. }
  674. __attribute__((weak)) void render_oled_title(bool side) {
  675. oled_write_P(side ? PSTR(" Left ") : PSTR(" Right "), true);
  676. // oled_write_P(PSTR( "1234567890123" "1234567890123"), true);
  677. }
  678. __attribute__((weak)) oled_rotation_t oled_init_keymap(oled_rotation_t rotation) {
  679. return rotation;
  680. }
  681. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  682. if (is_keyboard_master()) {
  683. memset(oled_keylog_str, ' ', OLED_KEYLOGGER_LENGTH);
  684. }
  685. kittoken = defer_exec(3000, kitty_animation_phases, NULL);
  686. oled_clear();
  687. oled_render();
  688. return oled_init_keymap(rotation);
  689. }
  690. __attribute__((weak)) bool oled_task_keymap(void) {
  691. return true;
  692. }
  693. bool oled_task_user(void) {
  694. #ifndef OLED_DISPLAY_TEST
  695. if (!is_oled_enabled) {
  696. oled_off();
  697. return false;
  698. } else
  699. #endif
  700. {
  701. oled_on();
  702. }
  703. if (!oled_task_keymap()) {
  704. return false;
  705. }
  706. #if defined(OLED_DISPLAY_VERBOSE)
  707. oled_write_raw_P(header_image, sizeof(header_image));
  708. oled_set_cursor(4, 0);
  709. render_oled_title(is_keyboard_left());
  710. #endif
  711. #ifndef OLED_DISPLAY_TEST
  712. if (is_keyboard_left()) {
  713. #endif
  714. render_status_left();
  715. #if defined(OLED_DISPLAY_128X128)
  716. oled_render_large_display(true);
  717. #endif
  718. #ifndef OLED_DISPLAY_TEST
  719. } else {
  720. render_status_right();
  721. # if defined(OLED_DISPLAY_128X128)
  722. oled_render_large_display(false);
  723. # endif
  724. }
  725. #endif
  726. #if defined(OLED_DISPLAY_VERBOSE)
  727. uint8_t num_of_rows;
  728. # if defined(OLED_DISPLAY_128X128)
  729. num_of_rows = 15;
  730. # else
  731. num_of_rows = 7;
  732. # endif
  733. for (uint8_t i = 1; i < num_of_rows; i++) {
  734. oled_set_cursor(0, i);
  735. oled_write_raw_P(display_border, sizeof(display_border));
  736. oled_set_cursor(21, i);
  737. oled_write_raw_P(display_border, sizeof(display_border));
  738. }
  739. oled_set_cursor(0, num_of_rows);
  740. oled_write_raw_P(footer_image, sizeof(footer_image));
  741. #endif
  742. return false;
  743. }
  744. void housekeeping_task_oled(void) {
  745. is_oled_enabled = false;
  746. if ((is_oled_locked || (last_input_activity_elapsed() < 60000)) && !is_oled_force_off) {
  747. is_oled_enabled = true;
  748. }
  749. if (oled_get_brightness() != userspace_config.oled_brightness) {
  750. oled_set_brightness(userspace_config.oled_brightness);
  751. }
  752. }