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.

46 lines
1.1 KiB

  1. #include <stdio.h>
  2. #include "action.h"
  3. #include "lily58.h"
  4. char keylog_str[24] = {};
  5. char keylogs_str[21] = {};
  6. int keylogs_str_idx = 0;
  7. const char code_to_name[60] = {
  8. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
  9. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  10. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  11. '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
  12. 'R', 'E', 'B', 'T', ' ', ' ', ' ', ' ', ' ', ' ',
  13. ' ', ';', '\'', ' ', ',', '.', '/', ' ', ' ', ' '};
  14. void set_keylog(uint16_t keycode, keyrecord_t *record) {
  15. char name = ' ';
  16. if (keycode < 60) {
  17. name = code_to_name[keycode];
  18. }
  19. // update keylog
  20. snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c",
  21. record->event.key.row, record->event.key.col,
  22. keycode, name);
  23. // update keylogs
  24. if (keylogs_str_idx == sizeof(keylogs_str) - 1) {
  25. keylogs_str_idx = 0;
  26. for (int i = 0; i < sizeof(keylogs_str) - 1; i++) {
  27. keylogs_str[i] = ' ';
  28. }
  29. }
  30. keylogs_str[keylogs_str_idx] = name;
  31. keylogs_str_idx++;
  32. }
  33. const char *read_keylog(void) {
  34. return keylog_str;
  35. }
  36. const char *read_keylogs(void) {
  37. return keylogs_str;
  38. }