123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- #include "process_steno.h"
- #include "quantum_keycodes.h"
- #include "keymap_steno.h"
- #include <string.h>
- #ifdef VIRTSER_ENABLE
- # include "virtser.h"
- #endif
- #ifdef STENO_ENABLE_ALL
- # include "eeprom.h"
- #endif
- static uint8_t chord[MAX_STROKE_SIZE] = {0};
- static int8_t n_pressed_keys = 0;
- #ifdef STENO_ENABLE_ALL
- static steno_mode_t mode;
- #elif defined(STENO_ENABLE_GEMINI)
- static const steno_mode_t mode = STENO_MODE_GEMINI;
- #elif defined(STENO_ENABLE_BOLT)
- static const steno_mode_t mode = STENO_MODE_BOLT;
- #endif
- static inline void steno_clear_chord(void) {
- memset(chord, 0, sizeof(chord));
- }
- #ifdef STENO_ENABLE_GEMINI
- # ifdef VIRTSER_ENABLE
- void send_steno_chord_gemini(void) {
-
- chord[0] |= 0x80;
- for (uint8_t i = 0; i < GEMINI_STROKE_SIZE; ++i) {
- virtser_send(chord[i]);
- }
- }
- # else
- # pragma message "VIRTSER_ENABLE = yes is required for Gemini PR to work properly out of the box!"
- # endif
- bool add_gemini_key_to_chord(uint8_t key) {
-
-
-
-
-
- const int group_idx = key / 7;
- const int intra_group_idx = key - group_idx * 7;
-
- const uint8_t bit = 1 << (6 - intra_group_idx);
- chord[group_idx] |= bit;
- return false;
- }
- #endif
- #ifdef STENO_ENABLE_BOLT
- # define TXB_GRP0 0b00000000
- # define TXB_GRP1 0b01000000
- # define TXB_GRP2 0b10000000
- # define TXB_GRP3 0b11000000
- # define TXB_GRPMASK 0b11000000
- # define TXB_GET_GROUP(code) ((code & TXB_GRPMASK) >> 6)
- static const uint8_t boltmap[64] PROGMEM = {TXB_NUL, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_S_L, TXB_S_L, TXB_T_L, TXB_K_L, TXB_P_L, TXB_W_L, TXB_H_L, TXB_R_L, TXB_A_L, TXB_O_L, TXB_STR, TXB_STR, TXB_NUL, TXB_NUL, TXB_NUL, TXB_STR, TXB_STR, TXB_E_R, TXB_U_R, TXB_F_R, TXB_R_R, TXB_P_R, TXB_B_R, TXB_L_R, TXB_G_R, TXB_T_R, TXB_S_R, TXB_D_R, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_Z_R};
- # ifdef VIRTSER_ENABLE
- static void send_steno_chord_bolt(void) {
- for (uint8_t i = 0; i < BOLT_STROKE_SIZE; ++i) {
-
-
-
- if (chord[i]) {
- virtser_send(chord[i]);
- }
- }
-
-
-
- virtser_send(0);
- }
- # else
- # pragma message "VIRTSER_ENABLE = yes is required for TX Bolt to work properly out of the box!"
- # endif
- static bool add_bolt_key_to_chord(uint8_t key) {
- uint8_t boltcode = pgm_read_byte(boltmap + key);
- chord[TXB_GET_GROUP(boltcode)] |= boltcode;
- return false;
- }
- #endif
- #ifdef STENO_COMBINEDMAP
- static const uint16_t combinedmap_first[] PROGMEM = {STN_S1, STN_TL, STN_PL, STN_HL, STN_FR, STN_PR, STN_LR, STN_TR, STN_DR, STN_A, STN_E};
- static const uint16_t combinedmap_second[] PROGMEM = {STN_S2, STN_KL, STN_WL, STN_RL, STN_RR, STN_BR, STN_GR, STN_SR, STN_ZR, STN_O, STN_U};
- #endif
- #ifdef STENO_ENABLE_ALL
- void steno_init() {
- if (!eeconfig_is_enabled()) {
- eeconfig_init();
- }
- mode = eeprom_read_byte(EECONFIG_STENOMODE);
- }
- void steno_set_mode(steno_mode_t new_mode) {
- steno_clear_chord();
- mode = new_mode;
- eeprom_update_byte(EECONFIG_STENOMODE, mode);
- }
- #endif
- __attribute__((weak)) bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[MAX_STROKE_SIZE]) {
- return true;
- }
- __attribute__((weak)) bool post_process_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[MAX_STROKE_SIZE], int8_t n_pressed_keys) {
- return true;
- }
- __attribute__((weak)) bool process_steno_user(uint16_t keycode, keyrecord_t *record) {
- return true;
- }
- bool process_steno(uint16_t keycode, keyrecord_t *record) {
- if (keycode < QK_STENO || keycode > QK_STENO_MAX) {
- return true;
-
- }
- if (IS_NOEVENT(record->event)) {
- return true;
- }
- if (!process_steno_user(keycode, record)) {
- return false;
- }
- switch (keycode) {
- #ifdef STENO_ENABLE_ALL
- case QK_STENO_BOLT:
- if (IS_PRESSED(record->event)) {
- steno_set_mode(STENO_MODE_BOLT);
- }
- return false;
- case QK_STENO_GEMINI:
- if (IS_PRESSED(record->event)) {
- steno_set_mode(STENO_MODE_GEMINI);
- }
- return false;
- #endif
- #ifdef STENO_COMBINEDMAP
- case QK_STENO_COMB ... QK_STENO_COMB_MAX: {
- bool first_result = process_steno(combinedmap_first[keycode - QK_STENO_COMB], record);
- bool second_result = process_steno(combinedmap_second[keycode - QK_STENO_COMB], record);
- return first_result && second_result;
- }
- #endif
- case STN__MIN ... STN__MAX:
- if (IS_PRESSED(record->event)) {
- n_pressed_keys++;
- switch (mode) {
- #ifdef STENO_ENABLE_BOLT
- case STENO_MODE_BOLT:
- add_bolt_key_to_chord(keycode - QK_STENO);
- break;
- #endif
- #ifdef STENO_ENABLE_GEMINI
- case STENO_MODE_GEMINI:
- add_gemini_key_to_chord(keycode - QK_STENO);
- break;
- #endif
- default:
- return false;
- }
- if (!post_process_steno_user(keycode, record, mode, chord, n_pressed_keys)) {
- return false;
- }
- } else {
- n_pressed_keys--;
- if (!post_process_steno_user(keycode, record, mode, chord, n_pressed_keys)) {
- return false;
- }
- if (n_pressed_keys > 0) {
-
-
- return false;
- }
- n_pressed_keys = 0;
- if (!send_steno_chord_user(mode, chord)) {
- steno_clear_chord();
- return false;
- }
- switch (mode) {
- #if defined(STENO_ENABLE_BOLT) && defined(VIRTSER_ENABLE)
- case STENO_MODE_BOLT:
- send_steno_chord_bolt();
- break;
- #endif
- #if defined(STENO_ENABLE_GEMINI) && defined(VIRTSER_ENABLE)
- case STENO_MODE_GEMINI:
- send_steno_chord_gemini();
- break;
- #endif
- default:
- break;
- }
- steno_clear_chord();
- }
- break;
- }
- return false;
- }
|