Improve string sending (#376)

example_keyboards
Eric Tang 9 years ago committed by Jack Humbert
parent cc3972e7d6
commit 794aed37a0

@ -473,56 +473,105 @@ bool process_record_quantum(keyrecord_t *record) {
return process_action_kb(record); return process_action_kb(record);
} }
bool shift_us_qwerty[0x80] = { const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 31 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, // 32 - 63 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, // 64 - 95 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 // 96 - 127 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 1, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 1, 1, 0
}; };
uint8_t ascii_us_qwerty[0x80] = { const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
0, 0, 0, 0, 0, 0, 0, 0, KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KC_ESC, 0, 0, 0, 0, // 0 - 31 0, 0, 0, 0, 0, 0, 0, 0,
KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT, KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, // 32 - 46 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
KC_SLSH, KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, // 47 - 61 0, 0, 0, 0, 0, 0, 0, 0,
KC_DOT, KC_SLSH, KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, // 62 - 78 0, 0, 0, KC_ESC, 0, 0, 0, 0,
KC_O, KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, // 79 - 94 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
KC_MINS, KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, // 95 - 111 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL // 112 - 127 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
}; };
// This is how you'd add OS colemak support /* for users whose OSes are set to Colemak */
#if 0
// bool shift_us_colemak[0x80] = { #include "keymap_colemak.h"
// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 31
// 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, // 32 - 63 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, // 64 - 95 0, 0, 0, 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 // 96 - 127 0, 0, 0, 0, 0, 0, 0, 0,
// }; 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
// #include "keymap_colemak.h" 0, 1, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 0, 0, 0, 0,
// uint8_t ascii_us_colemak[0x80] = { 0, 0, 0, 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0, 0, 0, 0, KC_BSPC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KC_ESC, 0, 0, 0, 0, // 0 - 31 0, 0, 1, 0, 1, 0, 1, 1,
// KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT, KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, // 32 - 46 1, 1, 1, 1, 1, 1, 1, 1,
// KC_SLSH, KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, // 47 - 61 1, 1, 1, 1, 1, 1, 1, 1,
// KC_DOT, KC_SLSH, KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G, CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, // 62 - 78 1, 1, 1, 1, 1, 1, 1, 1,
// CM_O, CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W, CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, // 79 - 94 1, 1, 1, 0, 0, 0, 1, 1,
// KC_MINS, KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G, CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O, // 95 - 111 0, 0, 0, 0, 0, 0, 0, 0,
// CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W, CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL // 112 - 127 0, 0, 0, 0, 0, 0, 0, 0,
// }; 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 1, 1, 0
void send_string(char str[]) { };
for (int i = 0; str[i] != 0; i++) {
uint8_t keycode = ascii_us_qwerty[str[i]]; const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
if (shift_us_qwerty[str[i]]) { 0, 0, 0, 0, 0, 0, 0, 0,
KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, KC_ESC, 0, 0, 0, 0,
KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
};
#endif
void send_string(const char *str) {
while (1) {
uint8_t keycode;
uint8_t ascii_code = pgm_read_byte(str);
if (!ascii_code) break;
keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
register_code(KC_LSFT); register_code(KC_LSFT);
register_code(keycode); register_code(keycode);
unregister_code(keycode); unregister_code(keycode);
unregister_code(KC_LSFT); unregister_code(KC_LSFT);
} else { }
else {
register_code(keycode); register_code(keycode);
unregister_code(keycode); unregister_code(keycode);
} }
++str;
} }
} }

@ -1,6 +1,7 @@
#ifndef QUANTUM_H #ifndef QUANTUM_H
#define QUANTUM_H #define QUANTUM_H
#include <avr/pgmspace.h>
#include "matrix.h" #include "matrix.h"
#include "keymap_common.h" #include "keymap_common.h"
#ifdef BACKLIGHT_ENABLE #ifdef BACKLIGHT_ENABLE
@ -25,6 +26,8 @@
#include <avr/io.h> #include <avr/io.h>
#include <util/delay.h> #include <util/delay.h>
#define SEND_STRING(str) send_string(PSTR(str))
extern uint32_t default_layer_state; extern uint32_t default_layer_state;
#ifndef NO_ACTION_LAYER #ifndef NO_ACTION_LAYER
@ -59,7 +62,7 @@ extern uint32_t default_layer_state;
#define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT) #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT)
#endif #endif
void send_string(char str[]); void send_string(const char *str);
void matrix_init_kb(void); void matrix_init_kb(void);
void matrix_scan_kb(void); void matrix_scan_kb(void);

Loading…
Cancel
Save