process_steno.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "process_steno.h"
  2. #include "quantum_keycodes.h"
  3. #include "keymap_steno.h"
  4. #include "virtser.h"
  5. uint8_t state[4] = {0};
  6. uint8_t pressed = 0;
  7. // TxBolt Codes
  8. #define TXB_NUL 0
  9. #define TXB_S_L 0b00000001
  10. #define TXB_T_L 0b00000010
  11. #define TXB_K_L 0b00000100
  12. #define TXB_P_L 0b00001000
  13. #define TXB_W_L 0b00010000
  14. #define TXB_H_L 0b00100000
  15. #define TXB_R_L 0b01000001
  16. #define TXB_A_L 0b01000010
  17. #define TXB_O_L 0b01000100
  18. #define TXB_STR 0b01001000
  19. #define TXB_E_R 0b01010000
  20. #define TXB_U_R 0b01100000
  21. #define TXB_F_R 0b10000001
  22. #define TXB_R_R 0b10000010
  23. #define TXB_P_R 0b10000100
  24. #define TXB_B_R 0b10001000
  25. #define TXB_L_R 0b10010000
  26. #define TXB_G_R 0b10100000
  27. #define TXB_T_R 0b11000001
  28. #define TXB_S_R 0b11000010
  29. #define TXB_D_R 0b11000100
  30. #define TXB_Z_R 0b11001000
  31. #define TXB_NUM 0b11010000
  32. #define TXB_GRP0 0b00000000
  33. #define TXB_GRP1 0b01000000
  34. #define TXB_GRP2 0b10000000
  35. #define TXB_GRP3 0b11000000
  36. #define TXB_GRPMASK 0b11000000
  37. #define TXB_GET_GROUP(code) ((code & TXB_GRPMASK) >> 6)
  38. uint8_t boltmap[64] = {
  39. TXB_NUL, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM,
  40. TXB_S_L, TXB_S_L, TXB_T_L, TXB_K_L, TXB_P_L, TXB_W_L, TXB_H_L,
  41. TXB_R_L, TXB_A_L, TXB_O_L, TXB_STR, TXB_STR, TXB_NUL, TXB_NUL,
  42. TXB_NUL, TXB_STR, TXB_STR, TXB_E_R, TXB_U_R, TXB_F_R, TXB_R_R,
  43. TXB_P_R, TXB_B_R, TXB_L_R, TXB_G_R, TXB_T_R, TXB_S_R, TXB_D_R,
  44. TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_Z_R
  45. };
  46. #define BOLTMAP_MASK (sizeof(boltmap) - 1)
  47. void send_steno_state(void) {
  48. for (uint8_t i = 0; i < 4; ++i) {
  49. if (state[i]) {
  50. virtser_send(state[i]);
  51. state[i] = 0;
  52. }
  53. }
  54. virtser_send(0);
  55. }
  56. bool process_steno(uint16_t keycode, keyrecord_t *record) {
  57. if(keycode >= QK_STENO && keycode <= QK_STENO_MAX) {
  58. if(IS_PRESSED(record->event)) {
  59. uint8_t boltcode = boltmap[keycode & BOLTMAP_MASK];
  60. ++pressed;
  61. state[TXB_GET_GROUP(boltcode)] |= boltcode;
  62. } else {
  63. --pressed;
  64. if (pressed <= 0) {
  65. pressed = 0; // protect against spurious up keys
  66. send_steno_state();
  67. }
  68. }
  69. return false;
  70. }
  71. return true;
  72. }