Updates send_string functionality, adds terminal feature (#1657)
* implement basic terminal stuff * modify send_string to read normal strings too * add files bc yeah. working pgm detected * pgm detection apparently not working * adds send string keycodes, additional keycode support in send string * implement arguments * [terminal] add help command * [terminal] adds keycode and keymap functions * [terminal] adds nop.h, documentation * update macro docsdz_support 0.5.124
parent
a4ff8b91f7
commit
7ad924bae5
@ -0,0 +1,80 @@
|
||||
# Terminal
|
||||
|
||||
> This feature is currently *huge* at 4400 bytes, and should probably only be put on boards with a lot of memory, or for fun.
|
||||
|
||||
The terminal feature is a command-line-like interface designed to communicate through a text editor with keystrokes. It's beneficial to turn off auto-indent features in your editor.
|
||||
|
||||
To enable, stick this in your `rules.mk` or `Makefile`:
|
||||
|
||||
TERMINAL_ENABLE = yes
|
||||
|
||||
And use the `TERM_ON` and `TERM_OFF` keycodes to turn it on or off.
|
||||
|
||||
When enabled, a `> ` prompt will appear, where you'll be able to type, backspace (a bell will ding if you reach the beginning and audio is enabled), and hit enter to send the command. Arrow keys are currently disabled so it doesn't get confused. Moving your cursor around with the mouse is discouraged.
|
||||
|
||||
`#define TERMINAL_HELP` enables some other output helpers that aren't really needed with this page.
|
||||
|
||||
## Future ideas
|
||||
|
||||
* Keyboard/user-extendable commands
|
||||
* Smaller footprint
|
||||
* Arrow key support
|
||||
* Command history
|
||||
* SD card support
|
||||
* LCD support for buffer display
|
||||
* Keycode -> name string LUT
|
||||
* Layer status
|
||||
* *Analog/digital port read/write*
|
||||
* RGB mode stuff
|
||||
* Macro definitions
|
||||
* EEPROM read/write
|
||||
* Audio control
|
||||
|
||||
## Current commands
|
||||
|
||||
### `about`
|
||||
|
||||
Prints out the current version of QMK with a build date:
|
||||
|
||||
```
|
||||
> about
|
||||
QMK Firmware
|
||||
v0.5.115-7-g80ed73-dirty
|
||||
Built: 2017-08-29-20:24:44
|
||||
```
|
||||
|
||||
### `help`
|
||||
|
||||
Prints out the available commands:
|
||||
|
||||
```
|
||||
> help
|
||||
commands available:
|
||||
about help keycode keymap exit
|
||||
```
|
||||
|
||||
### `keycode <layer> <row> <col>`
|
||||
|
||||
Prints out the keycode value of a certain layer, row, and column:
|
||||
|
||||
```
|
||||
> keycode 0 1 0
|
||||
0x29 (41)
|
||||
```
|
||||
|
||||
### `keymap <layer>`
|
||||
|
||||
Prints out the entire keymap for a certain layer
|
||||
|
||||
```
|
||||
> keymap 0
|
||||
0x002b, 0x0014, 0x001a, 0x0008, 0x0015, 0x0017, 0x001c, 0x0018, 0x000c, 0x0012, 0x0013, 0x002a,
|
||||
0x0029, 0x0004, 0x0016, 0x0007, 0x0009, 0x000a, 0x000b, 0x000d, 0x000e, 0x000f, 0x0033, 0x0034,
|
||||
0x00e1, 0x001d, 0x001b, 0x0006, 0x0019, 0x0005, 0x0011, 0x0010, 0x0036, 0x0037, 0x0038, 0x0028,
|
||||
0x5cd6, 0x00e0, 0x00e2, 0x00e3, 0x5cd4, 0x002c, 0x002c, 0x5cd5, 0x0050, 0x0051, 0x0052, 0x004f,
|
||||
>
|
||||
```
|
||||
|
||||
### `exit`
|
||||
|
||||
Exits the terminal - same as `TERM_OFF`.
|
@ -0,0 +1,252 @@
|
||||
/* Copyright 2017 Jack Humbert
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "process_terminal.h"
|
||||
#include <string.h>
|
||||
#include "version.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
bool terminal_enabled = false;
|
||||
char buffer[80] = "";
|
||||
char newline[2] = "\n";
|
||||
char arguments[6][20];
|
||||
|
||||
__attribute__ ((weak))
|
||||
const char terminal_prompt[8] = "> ";
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
#ifndef TERMINAL_SONG
|
||||
#define TERMINAL_SONG SONG(TERMINAL_SOUND)
|
||||
#endif
|
||||
float terminal_song[][2] = TERMINAL_SONG;
|
||||
#define TERMINAL_BELL() PLAY_SONG(terminal_song)
|
||||
#else
|
||||
#define TERMINAL_BELL()
|
||||
#endif
|
||||
|
||||
__attribute__ ((weak))
|
||||
const char keycode_to_ascii_lut[58] = {
|
||||
0, 0, 0, 0,
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0, 0, 0, '\t',
|
||||
' ', '-', '=', '[', ']', '\\', 0, ';', '\'', '`', ',', '.', '/'
|
||||
};
|
||||
|
||||
__attribute__ ((weak))
|
||||
const char shifted_keycode_to_ascii_lut[58] = {
|
||||
0, 0, 0, 0,
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', 0, 0, 0, '\t',
|
||||
' ', '_', '+', '{', '}', '|', 0, ':', '\'', '~', '<', '>', '?'
|
||||
};
|
||||
|
||||
struct stringcase {
|
||||
char* string;
|
||||
void (*func)(void);
|
||||
} typedef stringcase;
|
||||
|
||||
void enable_terminal(void) {
|
||||
terminal_enabled = true;
|
||||
strcpy(buffer, "");
|
||||
for (int i = 0; i < 6; i++)
|
||||
strcpy(arguments[i], "");
|
||||
// select all text to start over
|
||||
// SEND_STRING(SS_LCTRL("a"));
|
||||
send_string(terminal_prompt);
|
||||
}
|
||||
|
||||
void disable_terminal(void) {
|
||||
terminal_enabled = false;
|
||||
}
|
||||
|
||||
void terminal_about(void) {
|
||||
SEND_STRING("QMK Firmware\n");
|
||||
SEND_STRING(" v");
|
||||
SEND_STRING(QMK_VERSION);
|
||||
SEND_STRING("\n"SS_TAP(X_HOME)" Built: ");
|
||||
SEND_STRING(QMK_BUILDDATE);
|
||||
send_string(newline);
|
||||
#ifdef TERMINAL_HELP
|
||||
if (strlen(arguments[1]) != 0) {
|
||||
SEND_STRING("You entered: ");
|
||||
send_string(arguments[1]);
|
||||
send_string(newline);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void terminal_help(void);
|
||||
|
||||
extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
|
||||
|
||||
void terminal_keycode(void) {
|
||||
if (strlen(arguments[1]) != 0 && strlen(arguments[2]) != 0 && strlen(arguments[3]) != 0) {
|
||||
char keycode_dec[5];
|
||||
char keycode_hex[5];
|
||||
uint16_t layer = strtol(arguments[1], (char **)NULL, 10);
|
||||
uint16_t row = strtol(arguments[2], (char **)NULL, 10);
|
||||
uint16_t col = strtol(arguments[3], (char **)NULL, 10);
|
||||
uint16_t keycode = pgm_read_word(&keymaps[layer][row][col]);
|
||||
itoa(keycode, keycode_dec, 10);
|
||||
itoa(keycode, keycode_hex, 16);
|
||||
SEND_STRING("0x");
|
||||
send_string(keycode_hex);
|
||||
SEND_STRING(" (");
|
||||
send_string(keycode_dec);
|
||||
SEND_STRING(")\n");
|
||||
} else {
|
||||
#ifdef TERMINAL_HELP
|
||||
SEND_STRING("usage: keycode <layer> <row> <col>\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void terminal_keymap(void) {
|
||||
if (strlen(arguments[1]) != 0) {
|
||||
uint16_t layer = strtol(arguments[1], (char **)NULL, 10);
|
||||
for (int r = 0; r < MATRIX_ROWS; r++) {
|
||||
for (int c = 0; c < MATRIX_COLS; c++) {
|
||||
uint16_t keycode = pgm_read_word(&keymaps[layer][r][c]);
|
||||
char keycode_s[8];
|
||||
sprintf(keycode_s, "0x%04x, ", keycode);
|
||||
send_string(keycode_s);
|
||||
}
|
||||
send_string(newline);
|
||||
}
|
||||
} else {
|
||||
#ifdef TERMINAL_HELP
|
||||
SEND_STRING("usage: keymap <layer>\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
stringcase terminal_cases[] = {
|
||||
{ "about", terminal_about },
|
||||
{ "help", terminal_help },
|
||||
{ "keycode", terminal_keycode },
|
||||
{ "keymap", terminal_keymap },
|
||||
{ "exit", disable_terminal }
|
||||
};
|
||||
|
||||
void terminal_help(void) {
|
||||
SEND_STRING("commands available:\n ");
|
||||
for( stringcase* case_p = terminal_cases; case_p != terminal_cases + sizeof( terminal_cases ) / sizeof( terminal_cases[0] ); case_p++ ) {
|
||||
send_string(case_p->string);
|
||||
SEND_STRING(" ");
|
||||
}
|
||||
send_string(newline);
|
||||
}
|
||||
|
||||
void command_not_found(void) {
|
||||
SEND_STRING("command \"");
|
||||
send_string(buffer);
|
||||
SEND_STRING("\" not found\n");
|
||||
}
|
||||
|
||||
void process_terminal_command(void) {
|
||||
// we capture return bc of the order of events, so we need to manually send a newline
|
||||
send_string(newline);
|
||||
|
||||
char * pch;
|
||||
uint8_t i = 0;
|
||||
pch = strtok(buffer, " ");
|
||||
while (pch != NULL) {
|
||||
strcpy(arguments[i], pch);
|
||||
pch = strtok(NULL, " ");
|
||||
i++;
|
||||
}
|
||||
|
||||
bool command_found = false;
|
||||
for( stringcase* case_p = terminal_cases; case_p != terminal_cases + sizeof( terminal_cases ) / sizeof( terminal_cases[0] ); case_p++ ) {
|
||||
if( 0 == strcmp( case_p->string, buffer ) ) {
|
||||
command_found = true;
|
||||
(*case_p->func)();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!command_found)
|
||||
command_not_found();
|
||||
|
||||
if (terminal_enabled) {
|
||||
strcpy(buffer, "");
|
||||
for (int i = 0; i < 6; i++)
|
||||
strcpy(arguments[i], "");
|
||||
SEND_STRING(SS_TAP(X_HOME));
|
||||
send_string(terminal_prompt);
|
||||
}
|
||||
}
|
||||
|
||||
bool process_terminal(uint16_t keycode, keyrecord_t *record) {
|
||||
|
||||
if (keycode == TERM_ON && record->event.pressed) {
|
||||
enable_terminal();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (terminal_enabled && record->event.pressed) {
|
||||
if (keycode == TERM_OFF && record->event.pressed) {
|
||||
disable_terminal();
|
||||
return false;
|
||||
}
|
||||
if (keycode < 256) {
|
||||
uint8_t str_len;
|
||||
char char_to_add;
|
||||
switch (keycode) {
|
||||
case KC_ENTER:
|
||||
process_terminal_command();
|
||||
return false; break;
|
||||
case KC_ESC:
|
||||
SEND_STRING("\n");
|
||||
enable_terminal();
|
||||
return false; break;
|
||||
case KC_BSPC:
|
||||
str_len = strlen(buffer);
|
||||
if (str_len > 0) {
|
||||
buffer[str_len-1] = 0;
|
||||
return true;
|
||||
} else {
|
||||
TERMINAL_BELL();
|
||||
return false;
|
||||
} break;
|
||||
case KC_LEFT:
|
||||
case KC_RIGHT:
|
||||
case KC_UP:
|
||||
case KC_DOWN:
|
||||
return false; break;
|
||||
default:
|
||||
if (keycode <= 58) {
|
||||
char_to_add = 0;
|
||||
if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) {
|
||||
char_to_add = shifted_keycode_to_ascii_lut[keycode];
|
||||
} else if (get_mods() == 0) {
|
||||
char_to_add = keycode_to_ascii_lut[keycode];
|
||||
}
|
||||
if (char_to_add != 0) {
|
||||
strncat(buffer, &char_to_add, 1);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/* Copyright 2017 Jack Humbert
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROCESS_TERMINAL_H
|
||||
#define PROCESS_TERMINAL_H
|
||||
|
||||
#include "quantum.h"
|
||||
|
||||
extern const char keycode_to_ascii_lut[58];
|
||||
extern const char shifted_keycode_to_ascii_lut[58];
|
||||
extern const char terminal_prompt[8];
|
||||
bool process_terminal(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
#endif
|
@ -0,0 +1,25 @@
|
||||
/* Copyright 2017 Jack Humbert
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROCESS_TERMINAL_H
|
||||
#define PROCESS_TERMINAL_H
|
||||
|
||||
#include "quantum.h"
|
||||
|
||||
#define TERM_ON KC_NO
|
||||
#define TERM_OFF KC_NO
|
||||
|
||||
#endif
|
@ -0,0 +1,168 @@
|
||||
#ifndef SEND_STRING_KEYCODES
|
||||
#define SEND_STRING_KEYCODES
|
||||
|
||||
#define X_NO 00
|
||||
#define X_ROLL_OVER 01
|
||||
#define X_POST_FAIL 02
|
||||
#define X_UNDEFINED 03
|
||||
#define X_A 04
|
||||
#define X_B 05
|
||||
#define X_C 06
|
||||
#define X_D 07
|
||||
#define X_E 08
|
||||
#define X_F 09
|
||||
#define X_G 0A
|
||||
#define X_H 0B
|
||||
#define X_I 0C
|
||||
#define X_J 0D
|
||||
#define X_K 0E
|
||||
#define X_L 0F
|
||||
#define X_M 10
|
||||
#define X_N 11
|
||||
#define X_O 12
|
||||
#define X_P 13
|
||||
#define X_Q 14
|
||||
#define X_R 15
|
||||
#define X_S 16
|
||||
#define X_T 17
|
||||
#define X_U 18
|
||||
#define X_V 19
|
||||
#define X_W 1A
|
||||
#define X_X 1B
|
||||
#define X_Y 1C
|
||||
#define X_Z 1D
|
||||
#define X_1 1E
|
||||
#define X_2 1F
|
||||
#define X_3 20
|
||||
#define X_4 21
|
||||
#define X_5 22
|
||||
#define X_6 23
|
||||
#define X_7 24
|
||||
#define X_8 25
|
||||
#define X_9 26
|
||||
#define X_0 27
|
||||
#define X_ENTER 28
|
||||
#define X_ESCAPE 29
|
||||
#define X_BSPACE 2A
|
||||
#define X_TAB 2B
|
||||
#define X_SPACE 2C
|
||||
#define X_MINUS 2D
|
||||
#define X_EQUAL 2E
|
||||
#define X_LBRACKET 2F
|
||||
#define X_RBRACKET 30
|
||||
#define X_BSLASH 31
|
||||
#define X_NONUS_HASH 32
|
||||
#define X_SCOLON 33
|
||||
#define X_QUOTE 34
|
||||
#define X_GRAVE 35
|
||||
#define X_COMMA 36
|
||||
#define X_DOT 37
|
||||
#define X_SLASH 38
|
||||
#define X_CAPSLOCK 39
|
||||
#define X_F1 3A
|
||||
#define X_F2 3B
|
||||
#define X_F3 3C
|
||||
#define X_F4 3D
|
||||
#define X_F5 3E
|
||||
#define X_F6 3F
|
||||
#define X_F7 40
|
||||
#define X_F8 41
|
||||
#define X_F9 42
|
||||
#define X_F10 43
|
||||
#define X_F11 44
|
||||
#define X_F12 45
|
||||
#define X_PSCREEN 46
|
||||
#define X_SCROLLLOCK 47
|
||||
#define X_PAUSE 48
|
||||
#define X_INSERT 49
|
||||
#define X_HOME 4A
|
||||
#define X_PGUP 4B
|
||||
#define X_DELETE 4C
|
||||
#define X_END 4D
|
||||
#define X_PGDOWN 4E
|
||||
#define X_RIGHT 4F
|
||||
#define X_LEFT 50
|
||||
#define X_DOWN 51
|
||||
#define X_UP 52
|
||||
#define X_NUMLOCK 53
|
||||
#define X_KP_SLASH 54
|
||||
#define X_KP_ASTERISK 55
|
||||
#define X_KP_MINUS 56
|
||||
#define X_KP_PLUS 57
|
||||
#define X_KP_ENTER 58
|
||||
#define X_KP_1 59
|
||||
#define X_KP_2 5A
|
||||
#define X_KP_3 5B
|
||||
#define X_KP_4 5C
|
||||
#define X_KP_5 5D
|
||||
#define X_KP_6 5E
|
||||
#define X_KP_7 5F
|
||||
#define X_KP_8 60
|
||||
#define X_KP_9 61
|
||||
#define X_KP_0 62
|
||||
#define X_KP_DOT 63
|
||||
#define X_NONUS_BSLASH 64
|
||||
#define X_APPLICATION 65
|
||||
#define X_POWER 66
|
||||
#define X_KP_EQUAL 67
|
||||
#define X_F13 68
|
||||
#define X_F14 69
|
||||
#define X_F15 6A
|
||||
#define X_F16 6B
|
||||
#define X_F17 6C
|
||||
#define X_F18 6D
|
||||
#define X_F19 6E
|
||||
#define X_F20 6F
|
||||
#define X_F21 70
|
||||
#define X_F22 71
|
||||
#define X_F23 72
|
||||
#define X_F24 73
|
||||
#define X_EXECUTE 74
|
||||
#define X_HELP 75
|
||||
#define X_MENU 76
|
||||
#define X_SELECT 77
|
||||
#define X_STOP 78
|
||||
#define X_AGAIN 79
|
||||
#define X_UNDO 7A
|
||||
#define X_CUT 7B
|
||||
#define X_COPY 7C
|
||||
#define X_PASTE 7D
|
||||
#define X_FIND 7E
|
||||
#define X__MUTE 7F
|
||||
#define X__VOLUP 80
|
||||
#define X__VOLDOWN 81
|
||||
#define X_LOCKING_CAPS 82
|
||||
#define X_LOCKING_NUM 83
|
||||
#define X_LOCKING_SCROLL 84
|
||||
#define X_KP_COMMA 85
|
||||
#define X_KP_EQUAL_AS400 86
|
||||
#define X_INT1 87
|
||||
#define X_INT2 88
|
||||
#define X_INT3 89
|
||||
#define X_INT4 8A
|
||||
#define X_INT5 8B
|
||||
#define X_INT6 8C
|
||||
#define X_INT7 8D
|
||||
#define X_INT8 8E
|
||||
#define X_INT9 8F
|
||||
#define X_LANG1 90
|
||||
#define X_LANG2 91
|
||||
#define X_LANG3 92
|
||||
#define X_LANG4 93
|
||||
#define X_LANG5 94
|
||||
#define X_LANG6 95
|
||||
#define X_LANG7 96
|
||||
#define X_LANG8 97
|
||||
#define X_LANG9 98
|
||||
|
||||
/* Modifiers */
|
||||
#define X_LCTRL e0
|
||||
#define X_LSHIFT e1
|
||||
#define X_LALT e2
|
||||
#define X_LGUI e3
|
||||
#define X_RCTRL e4
|
||||
#define X_RSHIFT e5
|
||||
#define X_RALT e6
|
||||
#define X_RGUI e7
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue