4 uint32_t cChord = 0; // Current Chord
5 int chordIndex = 0; // Keys in previousachord
6 int32_t chordState[32]; // Full Chord history
7 #define QWERBUF 24 // Size of chords to buffer for output
9 bool repeatFlag = false; // Should we repeat?
10 uint32_t pChord = 0; // Previous Chord
11 int pChordIndex = 0; // Keys in previousachord
12 uint32_t pChordState[32]; // Previous chord sate
13 uint32_t stickyBits = 0; // Or'd with every incoming press
16 enum MODE { STENO = 0, QWERTY, COMMAND };
18 bool QWERSTENO = false;
20 enum MODE cMode = QWERTY;
22 enum MODE cMode = STENO;
26 #define MAX_CMD_BUF 20
28 uint8_t CMDBUF[MAX_CMD_BUF];
32 bool repEngaged = false;
33 uint16_t repTimer = 0;
34 #define REP_INIT_DELAY 750
41 // All processing done at chordUp goes through here
42 // Note, this is a gutted version of the Georgi sten.h
43 bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[6]) {
44 // Check for mousekeys, this is release
45 #ifdef MOUSEKEY_ENABLE
48 mousekey_off(mousePress);
53 // handle command mode
54 if (cChord == (LSU | LSD | RD | RZ)) {
55 if (cMode != COMMAND) { // Entering Command Mode
59 } else { // Exiting Command Mode
62 // Press all and release all
63 for (int i = 0; i < CMDLEN; i++) {
64 register_code(CMDBUF[i]);
72 // Handle Gaming Toggle,
73 if (cChord == (LSU | LSD | LFT | LK | RT | RS | RD | RZ) && keymapsCount > 1) {
75 uprintf("Switching to QMK\n");
81 // Do QWERTY and Momentary QWERTY
82 if (cMode == QWERTY || (cMode == COMMAND)) {
93 for (int i = 0; i < 32; i++)
94 chordState[i] = 0xFFFF;
100 bool process_steno_user(uint16_t keycode, keyrecord_t *record) {
101 // Everything happens in here when steno keys come in.
103 if (!record->event.pressed) return true;
105 // Update key repeat timers
106 repTimer = timer_read();
109 // Switch on the press adding to chord
110 bool pr = record->event.pressed;
113 case STN_ST1: pr ? (cChord |= (ST1)): (cChord &= ~(ST1)); break;
114 case STN_ST2: pr ? (cChord |= (ST2)): (cChord &= ~(ST2)); break;
115 case STN_ST3: pr ? (cChord |= (ST3)): (cChord &= ~(ST3)); break;
116 case STN_ST4: pr ? (cChord |= (ST4)): (cChord &= ~(ST4)); break;
117 case STN_FN: pr ? (cChord |= (FN)) : (cChord &= ~(FN)); break;
118 case STN_PWR: pr ? (cChord |= (PWR)): (cChord &= ~(PWR)); break;
119 case STN_N1...STN_N6: pr ? (cChord |= (LNO)): (cChord &= ~(LNO)); break;
120 case STN_N7...STN_NC: pr ? (cChord |= (RNO)): (cChord &= ~(RNO)); break;
122 // All the letter keys
123 case STN_S1: pr ? (cChord |= (LSU)) : (cChord &= ~(LSU)); break;
124 case STN_S2: pr ? (cChord |= (LSD)) : (cChord &= ~(LSD)); break;
125 case STN_TL: pr ? (cChord |= (LFT)) : (cChord &= ~(LFT)); break;
126 case STN_KL: pr ? (cChord |= (LK)) : (cChord &= ~(LK)); break;
127 case STN_PL: pr ? (cChord |= (LP)) : (cChord &= ~(LP)); break;
128 case STN_WL: pr ? (cChord |= (LW)) : (cChord &= ~(LW)); break;
129 case STN_HL: pr ? (cChord |= (LH)) : (cChord &= ~(LH)); break;
130 case STN_RL: pr ? (cChord |= (LR)) : (cChord &= ~(LR)); break;
131 case STN_A: pr ? (cChord |= (LA)) : (cChord &= ~(LA)); break;
132 case STN_O: pr ? (cChord |= (LO)) : (cChord &= ~(LO)); break;
133 case STN_E: pr ? (cChord |= (RE)) : (cChord &= ~(RE)); break;
134 case STN_U: pr ? (cChord |= (RU)) : (cChord &= ~(RU)); break;
135 case STN_FR: pr ? (cChord |= (RF)) : (cChord &= ~(RF)); break;
136 case STN_RR: pr ? (cChord |= (RR)) : (cChord &= ~(RR)); break;
137 case STN_PR: pr ? (cChord |= (RP)) : (cChord &= ~(RP)); break;
138 case STN_BR: pr ? (cChord |= (RB)) : (cChord &= ~(RB)); break;
139 case STN_LR: pr ? (cChord |= (RL)) : (cChord &= ~(RL)); break;
140 case STN_GR: pr ? (cChord |= (RG)) : (cChord &= ~(RG)); break;
141 case STN_TR: pr ? (cChord |= (RT)) : (cChord &= ~(RT)); break;
142 case STN_SR: pr ? (cChord |= (RS)) : (cChord &= ~(RS)); break;
143 case STN_DR: pr ? (cChord |= (RD)) : (cChord &= ~(RD)); break;
144 case STN_ZR: pr ? (cChord |= (RZ)) : (cChord &= ~(RZ)); break;
147 // Store previous state for fastQWER
149 chordState[chordIndex] = cChord;
155 void matrix_scan_user(void) {
156 // We abuse this for early sending of key
157 // Key repeat only on QWER/SYMB layers
158 if (cMode != QWERTY || !inChord) return;
162 if (repEngaged && timer_elapsed(repTimer) > REP_DELAY) {
163 // Process Key for report
166 // Send report to host
167 send_keyboard_report();
169 repTimer = timer_read();
172 if (!repEngaged && timer_elapsed(repTimer) > REP_INIT_DELAY) {
179 uint32_t processFakeSteno(bool lookup) {
180 P( LSU, SEND(KC_Q););
181 P( LSD, SEND(KC_A););
182 P( LFT, SEND(KC_W););
188 P( ST1, SEND(KC_T););
189 P( ST2, SEND(KC_G););
194 P( ST3, SEND(KC_Y););
195 P( ST4, SEND(KC_H););
200 P( RD, SEND(KC_LBRC););
204 P( RS, SEND(KC_SCLN););
205 P( RZ, SEND(KC_COMM););
206 P( LNO, SEND(KC_1););
207 P( RNO, SEND(KC_1););
212 // Traverse the chord history to a given point
213 // Returns the mask to use
214 void processChord(bool useFakeSteno) {
215 // Save the clean chord state
216 uint32_t savedChord = cChord;
218 // Apply Stick Bits if needed
219 if (stickyBits != 0) {
220 cChord |= stickyBits;
221 for (int i = 0; i <= chordIndex; i++)
222 chordState[i] |= stickyBits;
226 if (cChord & FN) cChord ^= FN;
228 // First we test if a whole chord was passsed
229 // If so we just run it handling repeat logic
230 if (useFakeSteno && processFakeSteno(true) == cChord) {
231 processFakeSteno(false);
233 } else if (processQwerty(true) == cChord) {
234 processQwerty(false);
246 // Iterate through chord picking out the individual
247 // and longest chords
248 uint32_t bufChords[QWERBUF];
252 // We iterate over it multiple times to catch the longest
253 // chord. Then that gets addded to the mask and re run.
254 while (savedChord != mask) {
256 uint32_t longestChord = 0;
258 for (int i = 0; i <= chordIndex; i++) {
259 cChord = chordState[i] & ~mask;
263 // Assume mid parse Sym is new chord
264 if (i != 0 && test != 0 && (cChord ^ test) == PWR) {
269 // Lock SYM layer in once detected
274 // Testing for keycodes
276 test = processFakeSteno(true);
278 test = processQwerty(true);
286 mask |= longestChord;
287 bufChords[bufLen] = longestChord;
290 // That's a loop of sorts, halt processing
291 if (bufLen >= QWERBUF) {
296 // Now that the buffer is populated, we run it
297 for (int i = 0; i < bufLen ; i++) {
298 cChord = bufChords[i];
300 processFakeSteno(false);
302 processQwerty(false);
306 // Save state in case of repeat
308 saveState(savedChord);
311 // Restore cChord for held repeat
316 void saveState(uint32_t cleanChord) {
318 pChordIndex = chordIndex;
319 for (int i = 0; i < 32; i++)
320 pChordState[i] = chordState[i];
322 void restoreState() {
324 chordIndex = pChordIndex;
325 for (int i = 0; i < 32; i++)
326 chordState[i] = pChordState[i];
329 // Macros for calling from keymap.c
330 void SEND(uint8_t kc) {
331 // Send Keycode, Does not work for Quantum Codes
332 if (cMode == COMMAND && CMDLEN < MAX_CMD_BUF) {
334 uprintf("CMD LEN: %d BUF: %d\n", CMDLEN, MAX_CMD_BUF);
340 if (cMode != COMMAND) register_code(kc);
350 void SET_STICKY(uint32_t stick) {
354 void SWITCH_LAYER(int layer) {
355 if (keymapsCount >= layer)
358 void CLICK_MOUSE(uint8_t kc) {
359 #ifdef MOUSEKEY_ENABLE
363 // Store state for later use