oled.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include QMK_KEYBOARD_H
  2. #include <stdio.h>
  3. #include "ninjonas.h"
  4. #ifdef OLED_DRIVER_ENABLE
  5. static uint32_t oled_timer = 0;
  6. extern uint8_t is_master;
  7. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  8. if (is_master) {
  9. return OLED_ROTATION_0;
  10. }
  11. return OLED_ROTATION_180;
  12. }
  13. bool process_record_oled(uint16_t keycode, keyrecord_t *record) {
  14. if (record->event.pressed) {
  15. oled_timer = timer_read32();
  16. }
  17. return true;
  18. }
  19. void render_default_layer_state(void) {
  20. oled_write_P(PSTR("Layout: "), false);
  21. switch (biton32(default_layer_state)) {
  22. case _COLEMAK:
  23. oled_write_P(PSTR("Colemak"), false);
  24. break;
  25. case _DVORAK:
  26. oled_write_P(PSTR("Dvorak"), false);
  27. break;
  28. case _QWERTY:
  29. oled_write_P(PSTR("Qwerty"), false);
  30. break;
  31. default:
  32. oled_write_ln_P(PSTR("Undefined"), false);
  33. }
  34. }
  35. void render_layer_state(void) {
  36. oled_write_P(PSTR("\nLayer:"), false);
  37. oled_write_P(PSTR(" LOW"), layer_state_is(_LOWER));
  38. oled_write_P(PSTR(" RAI"), layer_state_is(_RAISE));
  39. oled_write_P(PSTR(" ADJ"), layer_state_is(_ADJUST));
  40. }
  41. void render_mod_status(uint8_t modifiers) {
  42. oled_write_P(PSTR("\nMods: "), false);
  43. oled_write_P(PSTR("SHF "), (modifiers & MOD_MASK_SHIFT));
  44. oled_write_P(PSTR("CTL "), (modifiers & MOD_MASK_CTRL));
  45. oled_write_P(PSTR("ALT "), (modifiers & MOD_MASK_ALT));
  46. oled_write_P(PSTR("GUI"), (modifiers & MOD_MASK_GUI));
  47. }
  48. void render_status(void){
  49. render_default_layer_state();
  50. oled_write_P(PSTR("\n"), false);
  51. render_layer_state();
  52. render_mod_status(get_mods()|get_oneshot_mods());
  53. }
  54. static void render_logo(void) {
  55. static const char PROGMEM qmk_logo[] = {
  56. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
  57. 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
  58. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
  59. 0};
  60. oled_write_P(qmk_logo, false);
  61. }
  62. void oled_task_user(void) {
  63. if (timer_elapsed32(oled_timer) > 30000) {
  64. oled_off();
  65. return;
  66. }
  67. #ifndef SPLIT_KEYBOARD
  68. else { oled_on(); }
  69. #endif
  70. if (is_master) {
  71. render_status();
  72. } else {
  73. render_logo();
  74. oled_write_P(PSTR("\n"), false);
  75. oled_scroll_left();
  76. }
  77. }
  78. #endif