~ruther/qmk_firmware

ref: 67d512e639806b24e68cb35170789f614e779638 qmk_firmware/keyboards/converter/xmk/xmk_shell.c -rw-r--r-- 2.0 KiB
67d512e6 — Lex Brugman Fix enter for two ANSI layouts on the TKD Cycle7 (#24070) 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2022 Manna Harbour (@manna-harbour)
// https://github.com/manna-harbour/xmk

// SPDX-License-Identifier: GPL-2.0-or-later

#include QMK_KEYBOARD_H
#include <stdio.h>
#include <string.h>

#include "xmk_matrix.h"

#define XMK_SHELL_LINE_LEN 64

#define XMK_SHELL_KEY "key "
#define XMK_SHELL_KEY_PRESS "press "
#define XMK_SHELL_KEY_RELEASE "release "
#define XMK_SHELL_BOOT "boot"
#define XMK_SHELL_RESET "reset"

void xmk_shell(char *line) {
  dprintf("xmk_shell: line: '%s'\n", line);
  if (strncmp(line, XMK_SHELL_KEY, strlen(XMK_SHELL_KEY)) == 0) {
    dprintf("xmk_shell: XMK_SHELL_KEY\n");
    if (strncmp(line + strlen(XMK_SHELL_KEY), XMK_SHELL_KEY_PRESS, strlen(XMK_SHELL_KEY_PRESS)) == 0) {
      uint8_t key = strtol(line + strlen(XMK_SHELL_KEY) + strlen(XMK_SHELL_KEY_PRESS), NULL, 10);
      dprintf("xmk_shell: XMK_SHELL_KEY_PRESS: key: %u\n", key);
      xmk_matrix_key(true, key);
    } else if (strncmp(line + strlen(XMK_SHELL_KEY), XMK_SHELL_KEY_RELEASE, strlen(XMK_SHELL_KEY_RELEASE)) == 0) {
      uint8_t key = strtol(line + strlen(XMK_SHELL_KEY) + strlen(XMK_SHELL_KEY_RELEASE), NULL, 10);
      dprintf("xmk_shell: XMK_SHELL_KEY_RELEASE: key: %u\n", key);
      xmk_matrix_key(false, key);
    }
  } else if (strcmp(line, XMK_SHELL_BOOT) == 0) {
    dprintf("xmk_shell: XMK_SHELL_BOOT\n");
    reset_keyboard();
  } else if (strcmp(line, XMK_SHELL_RESET) == 0) {
    dprintf("xmk_shell: XMK_SHELL_RESET\n");
    soft_reset_keyboard();
  }
}

void virtser_recv(const uint8_t ch) {
  static char line[XMK_SHELL_LINE_LEN];
  static uint8_t line_index = 0;
  if (ch == '\r') {
    dprintf("virtser_recv: i: %3u, ch: %3u '\\r' \n", line_index, ch);
    line[line_index] = '\0';
    xmk_shell(line);
    line_index = 0;
  } else if (ch == '\n') {
    dprintf("virtser_recv: i: %3u, ch: %3u '\\n' \n", line_index, ch);
  } else {
    dprintf("virtser_recv: i: %3u, ch: %3u '%c'\n", line_index, ch, ch);
    if (line_index < (XMK_SHELL_LINE_LEN - 1)) {
      line[line_index] = ch;
      line_index++;
    }
  }
}
Do not follow this link