logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

le_chiffre.c (4406B)


  1. // Copyright 2020 tominabox1 (@tominabox1)
  2. // Copyright 2019 @foostan
  3. // Copyright 2020 Drashna Jaelre <@drashna>
  4. // Copyright 2023 QMK Contributors <@qmk>
  5. // SPDX-License-Identifier: GPL-2.0-or-later
  6. #include "quantum.h"
  7. #include "le_chiffre.h"
  8. #if defined(OLED_ENABLE) // Special thanks to Sickbabies for this great OLED widget!
  9. /* CONSTANTS */
  10. const char PROGMEM code_to_name[53] = {
  11. 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  12. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
  13. 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4',
  14. '5', '6', '7', '8', '9', '0', 'R', 'E', 'B', 'T',
  15. '_', '-', '=', '[', ']', '\\', '#', ';', '\'', '`',
  16. ',', '.', '/'
  17. };
  18. const char PROGMEM lechiffre_logo[96] = {
  19. // 'lechiffre_logo', 32x20px
  20. 0x00, 0x3e, 0x20, 0x20, 0x00, 0x18, 0x2c, 0xa8, 0x80, 0x00, 0x1c, 0x22, 0x22, 0x00, 0x3e, 0x08,
  21. 0x30, 0x00, 0x34, 0x00, 0x3c, 0x0a, 0x00, 0xbc, 0x8a, 0x00, 0x38, 0x08, 0x00, 0x18, 0x2c, 0x28,
  22. 0x00, 0xb6, 0xb6, 0x00, 0xdb, 0xdb, 0x00, 0x6d, 0x6d, 0x00, 0xdb, 0xdb, 0x00, 0xdb, 0xdb, 0x00,
  23. 0x00, 0xdb, 0xdb, 0x00, 0xdb, 0xdb, 0x00, 0x6d, 0x6d, 0x00, 0xdb, 0xdb, 0x00, 0xb6, 0xb6, 0x00,
  24. 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00,
  25. 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00
  26. };
  27. const char PROGMEM oled_section_break[6] = OLED_SECTION_BREAK;
  28. /* END CONSTANTS */
  29. /* TRACKERS */
  30. static char keylog_str[KEYLOG_LEN] = {};
  31. static uint16_t log_timer = 0;
  32. /* END TRACKERS */
  33. /* BEGIN STANDARD QMK FUNCTIONS */
  34. oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
  35. return OLED_ROTATION_90;
  36. }
  37. bool oled_task_kb(void) {
  38. if (!oled_task_user()) {
  39. return false;
  40. }
  41. oled_write_raw_P(lechiffre_logo, sizeof(lechiffre_logo));
  42. oled_set_cursor(0, 3);
  43. oled_write_P(oled_section_break, false);
  44. render_layer_status(get_u8_str(get_highest_layer(layer_state | default_layer_state), ' '));
  45. oled_write_P(oled_section_break, false);
  46. render_mod_status(get_mods() | get_oneshot_mods());
  47. oled_write_P(oled_section_break, false);
  48. render_keylock_status(host_keyboard_led_state());
  49. return true;
  50. }
  51. /* END STANDARD QMK FUNCTIONS */
  52. /* BEGIN CUSTOM HELPER FUNCTIONS FOR OLED */
  53. /**
  54. * Sickbabies deserves credit for the original OLED implementation,
  55. * however most of the keylogging code appears to have been lifted from crkbd
  56. * -- which is why @foostan and @drashna are now credited here as well.
  57. *
  58. * Improvements were lifted from crkbd again in 2023, with gratitude.
  59. */
  60. void add_keylog(uint16_t keycode, keyrecord_t *record) {
  61. if (IS_QK_MOD_TAP(keycode) && record->tap.count) {
  62. keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode);
  63. } else if (IS_QK_LAYER_TAP(keycode) && record->tap.count) {
  64. keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode);
  65. } else if (IS_QK_MODS(keycode)) {
  66. keycode = QK_MODS_GET_BASIC_KEYCODE(keycode);
  67. }
  68. if (keycode >= KC_A && keycode < KC_CAPS) {
  69. keycode -= KC_A; // shift to first letter of alphabet
  70. for (uint8_t i = KEYLOG_LEN - 1; i > 0; i--) {
  71. keylog_str[i] = keylog_str[i - 1];
  72. }
  73. keylog_str[0] = pgm_read_byte(&(code_to_name[keycode]));
  74. keylog_str[KEYLOG_LEN - 1] = 0x00;
  75. }
  76. log_timer = timer_read();
  77. }
  78. void render_keylock_status(led_t led_state) {
  79. oled_write_P(PSTR("C"), led_state.caps_lock);
  80. oled_advance_char();
  81. oled_write_P(PSTR("N"), led_state.num_lock);
  82. oled_advance_char();
  83. oled_write_P(PSTR("S"), led_state.scroll_lock);
  84. }
  85. void render_keylogger_status(void) {
  86. // zero out log after 30s idle time
  87. if (strlen(keylog_str) > 0 && timer_elapsed(log_timer) > 30000) {
  88. keylog_str[0] = 0x00;
  89. oled_advance_page(true);
  90. oled_advance_page(true);
  91. }
  92. oled_write(keylog_str, false);
  93. }
  94. void render_layer_status(const char* layer_name) {
  95. oled_write(layer_name, false);
  96. if (strlen(layer_name) < oled_max_chars()) {
  97. oled_advance_page(true);
  98. }
  99. }
  100. void render_mod_status(uint8_t modifiers) {
  101. oled_write_ln_P(PSTR("SHFT"), (modifiers & MOD_MASK_SHIFT));
  102. oled_write_ln_P(PSTR("ALT"), (modifiers & MOD_MASK_ALT));
  103. oled_write_ln_P(PSTR("CTRL"), (modifiers & MOD_MASK_CTRL));
  104. oled_write_ln_P(PSTR("GUI"), (modifiers & MOD_MASK_GUI));
  105. }
  106. #endif // OLED_ENABLE