logo

qmk_firmware

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

xmk_shell.c (2040B)


  1. // Copyright 2022 Manna Harbour (@manna-harbour)
  2. // https://github.com/manna-harbour/xmk
  3. // SPDX-License-Identifier: GPL-2.0-or-later
  4. #include QMK_KEYBOARD_H
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include "xmk_matrix.h"
  8. #define XMK_SHELL_LINE_LEN 64
  9. #define XMK_SHELL_KEY "key "
  10. #define XMK_SHELL_KEY_PRESS "press "
  11. #define XMK_SHELL_KEY_RELEASE "release "
  12. #define XMK_SHELL_BOOT "boot"
  13. #define XMK_SHELL_RESET "reset"
  14. void xmk_shell(char *line) {
  15. dprintf("xmk_shell: line: '%s'\n", line);
  16. if (strncmp(line, XMK_SHELL_KEY, strlen(XMK_SHELL_KEY)) == 0) {
  17. dprintf("xmk_shell: XMK_SHELL_KEY\n");
  18. if (strncmp(line + strlen(XMK_SHELL_KEY), XMK_SHELL_KEY_PRESS, strlen(XMK_SHELL_KEY_PRESS)) == 0) {
  19. uint8_t key = strtol(line + strlen(XMK_SHELL_KEY) + strlen(XMK_SHELL_KEY_PRESS), NULL, 10);
  20. dprintf("xmk_shell: XMK_SHELL_KEY_PRESS: key: %u\n", key);
  21. xmk_matrix_key(true, key);
  22. } else if (strncmp(line + strlen(XMK_SHELL_KEY), XMK_SHELL_KEY_RELEASE, strlen(XMK_SHELL_KEY_RELEASE)) == 0) {
  23. uint8_t key = strtol(line + strlen(XMK_SHELL_KEY) + strlen(XMK_SHELL_KEY_RELEASE), NULL, 10);
  24. dprintf("xmk_shell: XMK_SHELL_KEY_RELEASE: key: %u\n", key);
  25. xmk_matrix_key(false, key);
  26. }
  27. } else if (strcmp(line, XMK_SHELL_BOOT) == 0) {
  28. dprintf("xmk_shell: XMK_SHELL_BOOT\n");
  29. reset_keyboard();
  30. } else if (strcmp(line, XMK_SHELL_RESET) == 0) {
  31. dprintf("xmk_shell: XMK_SHELL_RESET\n");
  32. soft_reset_keyboard();
  33. }
  34. }
  35. void virtser_recv(const uint8_t ch) {
  36. static char line[XMK_SHELL_LINE_LEN];
  37. static uint8_t line_index = 0;
  38. if (ch == '\r') {
  39. dprintf("virtser_recv: i: %3u, ch: %3u '\\r' \n", line_index, ch);
  40. line[line_index] = '\0';
  41. xmk_shell(line);
  42. line_index = 0;
  43. } else if (ch == '\n') {
  44. dprintf("virtser_recv: i: %3u, ch: %3u '\\n' \n", line_index, ch);
  45. } else {
  46. dprintf("virtser_recv: i: %3u, ch: %3u '%c'\n", line_index, ch, ch);
  47. if (line_index < (XMK_SHELL_LINE_LEN - 1)) {
  48. line[line_index] = ch;
  49. line_index++;
  50. }
  51. }
  52. }