From 7ad924bae5519e981c57495e481db62741aa4376 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 12 Sep 2017 00:43:10 -0400 Subject: Updates send_string functionality, adds terminal feature (#1657) * implement basic terminal stuff * modify send_string to read normal strings too * add files bc yeah. working pgm detected * pgm detection apparently not working * adds send string keycodes, additional keycode support in send string * implement arguments * [terminal] add help command * [terminal] adds keycode and keymap functions * [terminal] adds nop.h, documentation * update macro docs --- quantum/quantum.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 11 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 285e1e81e..1fccaa7d5 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -237,6 +237,9 @@ bool process_record_quantum(keyrecord_t *record) { #endif #ifdef UNICODEMAP_ENABLE process_unicode_map(keycode, record) && + #endif + #ifdef TERMINAL_ENABLE + process_terminal(keycode, record) && #endif true)) { return false; @@ -600,21 +603,55 @@ void send_string(const char *str) { send_string_with_delay(str, 0); } +void send_string_P(const char *str) { + send_string_with_delay_P(str, 0); +} + void send_string_with_delay(const char *str, uint8_t interval) { while (1) { - uint8_t keycode; - uint8_t ascii_code = pgm_read_byte(str); + char ascii_code = *str; if (!ascii_code) break; - keycode = pgm_read_byte(&ascii_to_keycode_lut[ascii_code]); - if (pgm_read_byte(&ascii_to_shift_lut[ascii_code])) { - register_code(KC_LSFT); - register_code(keycode); - unregister_code(keycode); - unregister_code(KC_LSFT); + if (ascii_code == 1) { + // tap + uint8_t keycode = *(++str); + register_code(keycode); + unregister_code(keycode); + } else if (ascii_code == 2) { + // down + uint8_t keycode = *(++str); + register_code(keycode); + } else if (ascii_code == 3) { + // up + uint8_t keycode = *(++str); + unregister_code(keycode); + } else { + send_char(ascii_code); } - else { - register_code(keycode); - unregister_code(keycode); + ++str; + // interval + { uint8_t ms = interval; while (ms--) wait_ms(1); } + } +} + +void send_string_with_delay_P(const char *str, uint8_t interval) { + while (1) { + char ascii_code = pgm_read_byte(str); + if (!ascii_code) break; + if (ascii_code == 1) { + // tap + uint8_t keycode = pgm_read_byte(++str); + register_code(keycode); + unregister_code(keycode); + } else if (ascii_code == 2) { + // down + uint8_t keycode = pgm_read_byte(++str); + register_code(keycode); + } else if (ascii_code == 3) { + // up + uint8_t keycode = pgm_read_byte(++str); + unregister_code(keycode); + } else { + send_char(ascii_code); } ++str; // interval @@ -622,6 +659,20 @@ void send_string_with_delay(const char *str, uint8_t interval) { } } +void send_char(char ascii_code) { + uint8_t keycode; + keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]); + if (pgm_read_byte(&ascii_to_shift_lut[(uint8_t)ascii_code])) { + register_code(KC_LSFT); + register_code(keycode); + unregister_code(keycode); + unregister_code(KC_LSFT); + } else { + register_code(keycode); + unregister_code(keycode); + } +} + void set_single_persistent_default_layer(uint8_t default_layer) { #if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS) PLAY_SONG(default_layer_songs[default_layer]); -- cgit v1.2.3-24-g4f1b