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.

303 lines
9.0 KiB

  1. /*
  2. Copyright 2018 Eric Gebhart <e.a.gebhart@gmail.com>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "ericgebhart.h"
  15. #include <string.h>
  16. #include <stdio.h>
  17. void oled_render_default_layer_state(void) {
  18. oled_write_P(PSTR("Layout: "), false);
  19. switch (get_highest_layer(default_layer_state)) {
  20. case _QWERTY:
  21. oled_write_ln_P(PSTR("Qwerty"), false);
  22. break;
  23. case _COLEMAK:
  24. oled_write_ln_P(PSTR("Colemak"), false);
  25. break;
  26. case _DVORAK_BP:
  27. case _DVORAK:
  28. oled_write_ln_P(PSTR("Dvorak"), false);
  29. break;
  30. /* case _WORKMAN: */
  31. // oled_write_ln_P(PSTR("Workman\n"), false);
  32. /* break; */
  33. /* case _NORMAN: */
  34. // oled_write_ln_P(PSTR("Norman\n"), false);
  35. /* break; */
  36. /* case _MALTRON: */
  37. // oled_write_ln_P(PSTR("Maltron\n"), false);
  38. /* break; */
  39. /* case _EUCALYN: */
  40. // oled_write_ln_P(PSTR("Eucalyn\n"), false);
  41. /* break; */
  42. /* case _CARPLAX: */
  43. // oled_write_ln_P(PSTR("Carplax\n"), false);
  44. /* break; */
  45. case _BEAKL:
  46. case _BEAKL_BP:
  47. oled_write_ln_P(PSTR("Beakl"), false);
  48. break;
  49. case _BEPO:
  50. oled_write_ln_P(PSTR("Bepo"), false);
  51. break;
  52. }
  53. }
  54. void oled_render_layer_state(void) {
  55. oled_write_P(PSTR("Layer: "), false);
  56. switch (get_highest_layer(layer_state)) {
  57. case _NAV:
  58. oled_write_P(PSTR("Navigation"), false);
  59. break;
  60. case _LAYERS:
  61. oled_write_P(PSTR("Layers"), false);
  62. break;
  63. case _RGB:
  64. oled_write_P(PSTR("RGB"), false);
  65. break;
  66. case _TOPROWS:
  67. case _TOPROWS_BP:
  68. oled_write_P(PSTR("TopRows"), false);
  69. break;
  70. case _SYMB:
  71. case _SYMB_BP:
  72. oled_write_P(PSTR("Symbols"), false);
  73. break;
  74. case _KEYPAD:
  75. case _KEYPAD_BP:
  76. oled_write_P(PSTR("Keypad"), false);
  77. break;
  78. case _ADJUST:
  79. oled_write_P(PSTR("Adjust"), false);
  80. break;
  81. }
  82. oled_write_ln_P(PSTR(" "), false);
  83. }
  84. // this is part of my answer to a challenge.
  85. // My friend Ross thinks that the only use of an oled
  86. // is to say which layer.
  87. // I think there is more. this is just a beginning.
  88. void oled_render_layer_map(void) {
  89. uint8_t lyr = get_highest_layer(layer_state);
  90. if (lyr <= _BEPO) {
  91. switch (get_highest_layer(default_layer_state)) {
  92. case _QWERTY:
  93. oled_write_ln_P(PSTR(" qwert yuiop"), false);
  94. oled_write_ln_P(PSTR(" asdfg hjkl;"), false);
  95. oled_write_ln_P(PSTR(" zxcvb nm,./"), false);
  96. break;
  97. case _COLEMAK:
  98. oled_write_ln_P(PSTR(" qwfpb jluy;"), false);
  99. oled_write_ln_P(PSTR(" arstg mneio"), false);
  100. oled_write_ln_P(PSTR(" zxcdv kh,./"), false);
  101. break;
  102. case _DVORAK_BP:
  103. case _DVORAK:
  104. oled_write_ln_P(PSTR(" \",.py fgcrl"), false);
  105. oled_write_ln_P(PSTR(" aoeui dhtns"), false);
  106. oled_write_ln_P(PSTR(" ;qjkx bmwvz "), false);
  107. break;
  108. case _BEAKL:
  109. case _BEAKL_BP:
  110. oled_write_ln_P(PSTR(" qhoux gcrfz"), false);
  111. oled_write_ln_P(PSTR(" yiea. dstnb"), false);
  112. oled_write_ln_P(PSTR(" j/,k' wmlpv"), false);
  113. break;
  114. case _BEPO:
  115. oled_write_P(PSTR(" cbe'po`e vdljz %"), false);
  116. oled_write_P(PSTR(" auie, tsrnmc"), false);
  117. oled_write_P(PSTR(" e^a'yx.k 'qghfw"), false);
  118. break;
  119. }
  120. } else {
  121. switch (lyr) {
  122. case _TOPROWS:
  123. case _TOPROWS_BP:
  124. oled_write_ln_P(PSTR(" !@#$% ^&*()"), false);
  125. oled_write_ln_P(PSTR(" 40123 76598"), false);
  126. oled_write_ln_P(PSTR(" F1- -- -F12"), false);
  127. break;
  128. case _SYMB:
  129. case _SYMB_BP:
  130. oled_write_ln_P(PSTR(" `<$>' ?[_]-"), false);
  131. oled_write_ln_P(PSTR(" -\\(\")# !{:}/;"), false);
  132. oled_write_ln_P(PSTR(" @=*+; %&^~|"), false);
  133. break;
  134. case _NAV:
  135. oled_write_ln_P(PSTR("54321 0 ctn 12345"), false);
  136. oled_write_ln_P(PSTR(" ldur 1 ccv ldur"), false);
  137. oled_write_ln_P(PSTR(" ldur 2 cwq hdue"), false);
  138. break;
  139. case _KEYPAD:
  140. oled_write_ln_P(PSTR(" 523: F9-F12"), false);
  141. oled_write_ln_P(PSTR(" -7.104 F5-F8"), false);
  142. oled_write_ln_P(PSTR(" /698, F1-F4"), false);
  143. break;
  144. case _LAYERS:
  145. oled_write_ln_P(PSTR(" Bp Dv Bk|Nv S K TR"), false);
  146. oled_write_ln_P(PSTR("Q Cl Dv Bk|Nv S K TR"), false);
  147. oled_write_P(PSTR(" "), false);
  148. //oled_write_ln_P(PSTR("Ctrls?-> RGB ___ ___ Adjust"), false);
  149. break;
  150. }
  151. }
  152. }
  153. void oled_render_keylock_status(uint8_t led_usb_state) {
  154. oled_write_P(PSTR(" Lock:"), false);
  155. oled_write_P(PSTR(" "), false);
  156. oled_write_P(PSTR("N"), led_usb_state & (1 << USB_LED_NUM_LOCK));
  157. oled_write_P(PSTR("C"), led_usb_state & (1 << USB_LED_CAPS_LOCK));
  158. oled_write_ln_P(PSTR("S"), led_usb_state & (1 << USB_LED_SCROLL_LOCK));
  159. }
  160. void oled_render_mod_status(uint8_t modifiers) {
  161. oled_write_P(PSTR("Mods:"), false);
  162. oled_write_P(PSTR("S"), (modifiers & MOD_MASK_SHIFT));
  163. oled_write_P(PSTR("C"), (modifiers & MOD_MASK_CTRL));
  164. oled_write_P(PSTR("A"), (modifiers & MOD_MASK_ALT));
  165. oled_write_P(PSTR("G"), (modifiers & MOD_MASK_GUI));
  166. }
  167. void oled_render_mod_lock_status(){
  168. oled_render_mod_status(get_mods() | get_oneshot_mods());
  169. oled_render_keylock_status(host_keyboard_leds());
  170. }
  171. char mkeylog_str[22] = {};
  172. const char mcode_to_name[60] = {
  173. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
  174. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  175. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  176. '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
  177. 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
  178. '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
  179. void oled_render_keylog(void) {
  180. oled_write_ln(mkeylog_str, false);
  181. // sometimes there's an extra row. this is because sometimes it drops
  182. // to the last line. and this clears it.
  183. oled_write_ln_P(PSTR(" "), false);
  184. }
  185. void add_keylog(uint16_t keycode, keyrecord_t *record) {
  186. char name = ' ';
  187. if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) ||
  188. (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
  189. keycode = keycode & 0xFF;
  190. }
  191. if (keycode < 60) {
  192. name = mcode_to_name[keycode];
  193. }
  194. // update keylog
  195. memset(mkeylog_str, ' ', sizeof(mkeylog_str) - 1);
  196. snprintf(mkeylog_str, sizeof(mkeylog_str), "%dx%d, k%2d : %c",
  197. record->event.key.row, record->event.key.col,
  198. keycode, name);
  199. }
  200. __attribute__((weak)) oled_rotation_t oled_init_keymap(oled_rotation_t rotation) { return rotation; }
  201. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  202. // for the big screen.
  203. #ifdef OLED_DISPLAY_128X64
  204. return OLED_ROTATION_180;
  205. #endif
  206. return oled_init_keymap(rotation);
  207. }
  208. /* oled_rotation_t oled_init_user(oled_rotation_t rotation) { */
  209. /* memset(mkeylog_str, ' ', sizeof(mkeylog_str) - 1); */
  210. /* if (is_keyboard_master()) { */
  211. /* return OLED_ROTATION_270; */
  212. /* } else { */
  213. /* return OLED_ROTATION_180; */
  214. /* } */
  215. /* } */
  216. bool process_record_user_oled(uint16_t keycode, keyrecord_t *record) {
  217. if (record->event.pressed) {
  218. //oled_timer = timer_read32();
  219. add_keylog(keycode, record);
  220. //add_keylog(keycode);
  221. }
  222. return true;
  223. }
  224. void render_bootmagic_status(bool status) {
  225. /* Show Ctrl-Gui Swap options */
  226. static const char PROGMEM logo[][2][3] = {
  227. {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  228. {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  229. };
  230. if (status) {
  231. oled_write_ln_P(logo[0][0], false);
  232. oled_write_ln_P(logo[0][1], false);
  233. } else {
  234. oled_write_ln_P(logo[1][0], false);
  235. oled_write_ln_P(logo[1][1], false);
  236. }
  237. }
  238. __attribute__((weak)) void oled_render_logo(void) {
  239. // clang-format off
  240. static const char PROGMEM qmk_logo[] = {
  241. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  242. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  243. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  244. // clang-format on
  245. oled_write_P(qmk_logo, false);
  246. }
  247. bool oled_task_user(void) {
  248. if (is_keyboard_master()) {
  249. oled_render_mod_lock_status();
  250. oled_render_default_layer_state();
  251. oled_render_layer_state();
  252. #ifdef OLED_DISPLAY_128X64
  253. oled_render_layer_map();
  254. #endif
  255. oled_render_keylog();
  256. } else {
  257. oled_render_logo();
  258. oled_render_default_layer_state();
  259. }
  260. return(true);
  261. }
  262. /* oled_render_keylock_status(host_keyboard_leds()); */
  263. /* oled_render_mod_status(get_mods() | get_oneshot_mods()); */