aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_steno.c
diff options
context:
space:
mode:
authorJoe Wasson <jwasson+github@gmail.com>2017-07-26 14:41:39 -0700
committerJack Humbert <jack.humb@gmail.com>2017-07-27 16:10:36 -0400
commit5987f67989c1b8f5fbd108d4dae21a227bc2f99c (patch)
tree32bee84bf7265d0fce7c924db38021b08ea5cbb2 /quantum/process_keycode/process_steno.c
parentcefc09ae7dd88cd6b92412881888404da1abdfcb (diff)
downloadqmk_firmware-5987f67989c1b8f5fbd108d4dae21a227bc2f99c.tar.gz
qmk_firmware-5987f67989c1b8f5fbd108d4dae21a227bc2f99c.zip
Add TX Bolt protocol support for Stenography
Requires virtser; Allows QMK to speak the TX BOlt protocol used by stenography machines and software (such as Plover). The upside is that Plover can be configured to listen only to TX Bolt allow the keyboard to switch layers without need to enable/disable the Plover software, or to have a second non-Steno keyboard work concurrently.
Diffstat (limited to 'quantum/process_keycode/process_steno.c')
-rw-r--r--quantum/process_keycode/process_steno.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_steno.c b/quantum/process_keycode/process_steno.c
new file mode 100644
index 000000000..211f00a5a
--- /dev/null
+++ b/quantum/process_keycode/process_steno.c
@@ -0,0 +1,82 @@
1#include "process_steno.h"
2#include "quantum_keycodes.h"
3#include "keymap_steno.h"
4#include "virtser.h"
5
6uint8_t state[4] = {0};
7uint8_t pressed = 0;
8
9
10// TxBolt Codes
11#define TXB_NUL 0
12#define TXB_S_L 0b00000001
13#define TXB_T_L 0b00000010
14#define TXB_K_L 0b00000100
15#define TXB_P_L 0b00001000
16#define TXB_W_L 0b00010000
17#define TXB_H_L 0b00100000
18#define TXB_R_L 0b01000001
19#define TXB_A_L 0b01000010
20#define TXB_O_L 0b01000100
21#define TXB_STR 0b01001000
22#define TXB_E_R 0b01010000
23#define TXB_U_R 0b01100000
24#define TXB_F_R 0b10000001
25#define TXB_R_R 0b10000010
26#define TXB_P_R 0b10000100
27#define TXB_B_R 0b10001000
28#define TXB_L_R 0b10010000
29#define TXB_G_R 0b10100000
30#define TXB_T_R 0b11000001
31#define TXB_S_R 0b11000010
32#define TXB_D_R 0b11000100
33#define TXB_Z_R 0b11001000
34#define TXB_NUM 0b11010000
35
36#define TXB_GRP0 0b00000000
37#define TXB_GRP1 0b01000000
38#define TXB_GRP2 0b10000000
39#define TXB_GRP3 0b11000000
40#define TXB_GRPMASK 0b11000000
41
42#define TXB_GET_GROUP(code) ((code & TXB_GRPMASK) >> 6)
43
44uint8_t boltmap[64] = {
45 TXB_NUL, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM,
46 TXB_S_L, TXB_S_L, TXB_T_L, TXB_K_L, TXB_P_L, TXB_W_L, TXB_H_L,
47 TXB_R_L, TXB_A_L, TXB_O_L, TXB_STR, TXB_STR, TXB_NUL, TXB_NUL,
48 TXB_NUL, TXB_STR, TXB_STR, TXB_E_R, TXB_U_R, TXB_F_R, TXB_R_R,
49 TXB_P_R, TXB_B_R, TXB_L_R, TXB_G_R, TXB_T_R, TXB_S_R, TXB_D_R,
50 TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_Z_R
51};
52
53#define BOLTMAP_MASK (sizeof(boltmap) - 1)
54
55void send_steno_state(void) {
56 for (uint8_t i = 0; i < 4; ++i) {
57 if (state[i]) {
58 virtser_send(state[i]);
59 state[i] = 0;
60 }
61 }
62 virtser_send(0);
63}
64
65bool process_steno(uint16_t keycode, keyrecord_t *record) {
66 if(keycode >= QK_STENO && keycode <= QK_STENO_MAX) {
67 if(IS_PRESSED(record->event)) {
68 uint8_t boltcode = boltmap[keycode & BOLTMAP_MASK];
69 ++pressed;
70 state[TXB_GET_GROUP(boltcode)] |= boltcode;
71 } else {
72 --pressed;
73 if (pressed <= 0) {
74 pressed = 0; // protect against spurious up keys
75 send_steno_state();
76 }
77 }
78 return false;
79 }
80
81 return true;
82}