forked from mirrors/qmk_userspace
		
	Add support for delays in send_string. (#8244)
This commit is contained in:
		
					parent
					
						
							
								e18be69104
							
						
					
				
			
			
				commit
				
					
						444fd3b1cc
					
				
			
		
					 3 changed files with 75 additions and 34 deletions
				
			
		| 
						 | 
				
			
			@ -107,6 +107,16 @@ Would tap `KC_HOME` - note how the prefix is now `X_`, and not `KC_`. You can al
 | 
			
		|||
 | 
			
		||||
Which would send "VE" followed by a `KC_HOME` tap, and "LO" (spelling "LOVE" if on a newline).
 | 
			
		||||
 | 
			
		||||
Delays can be also added to the string:
 | 
			
		||||
 | 
			
		||||
* `SS_DELAY(msecs)` will delay for the specified number of milliseconds.
 | 
			
		||||
 | 
			
		||||
For example:
 | 
			
		||||
 | 
			
		||||
    SEND_STRING("VE" SS_DELAY(1000) SS_TAP(X_HOME) "LO");
 | 
			
		||||
 | 
			
		||||
Which would send "VE" followed by a 1-second delay, then a `KC_HOME` tap, and "LO" (spelling "LOVE" if on a newline, but delayed in the middle).
 | 
			
		||||
 | 
			
		||||
There's also a couple of mod shortcuts you can use:
 | 
			
		||||
 | 
			
		||||
* `SS_LCTL(string)`
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@
 | 
			
		|||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#include "quantum.h"
 | 
			
		||||
 | 
			
		||||
#ifdef PROTOCOL_LUFA
 | 
			
		||||
| 
						 | 
				
			
			@ -374,19 +375,32 @@ void send_string_with_delay(const char *str, uint8_t interval) {
 | 
			
		|||
    while (1) {
 | 
			
		||||
        char ascii_code = *str;
 | 
			
		||||
        if (!ascii_code) break;
 | 
			
		||||
        if (ascii_code == SS_TAP_CODE) {
 | 
			
		||||
            // tap
 | 
			
		||||
            uint8_t keycode = *(++str);
 | 
			
		||||
            register_code(keycode);
 | 
			
		||||
            unregister_code(keycode);
 | 
			
		||||
        } else if (ascii_code == SS_DOWN_CODE) {
 | 
			
		||||
            // down
 | 
			
		||||
            uint8_t keycode = *(++str);
 | 
			
		||||
            register_code(keycode);
 | 
			
		||||
        } else if (ascii_code == SS_UP_CODE) {
 | 
			
		||||
            // up
 | 
			
		||||
            uint8_t keycode = *(++str);
 | 
			
		||||
            unregister_code(keycode);
 | 
			
		||||
        if (ascii_code == SS_QMK_PREFIX) {
 | 
			
		||||
            ascii_code = *(++str);
 | 
			
		||||
            if (ascii_code == SS_TAP_CODE) {
 | 
			
		||||
                // tap
 | 
			
		||||
                uint8_t keycode = *(++str);
 | 
			
		||||
                register_code(keycode);
 | 
			
		||||
                unregister_code(keycode);
 | 
			
		||||
            } else if (ascii_code == SS_DOWN_CODE) {
 | 
			
		||||
                // down
 | 
			
		||||
                uint8_t keycode = *(++str);
 | 
			
		||||
                register_code(keycode);
 | 
			
		||||
            } else if (ascii_code == SS_UP_CODE) {
 | 
			
		||||
                // up
 | 
			
		||||
                uint8_t keycode = *(++str);
 | 
			
		||||
                unregister_code(keycode);
 | 
			
		||||
            } else if (ascii_code == SS_DELAY_CODE) {
 | 
			
		||||
                // delay
 | 
			
		||||
                int     ms      = 0;
 | 
			
		||||
                uint8_t keycode = *(++str);
 | 
			
		||||
                while (isdigit(keycode)) {
 | 
			
		||||
                    ms *= 10;
 | 
			
		||||
                    ms += keycode - '0';
 | 
			
		||||
                    keycode = *(++str);
 | 
			
		||||
                }
 | 
			
		||||
                while (ms--) wait_ms(1);
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            send_char(ascii_code);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -403,19 +417,32 @@ 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 == SS_TAP_CODE) {
 | 
			
		||||
            // tap
 | 
			
		||||
            uint8_t keycode = pgm_read_byte(++str);
 | 
			
		||||
            register_code(keycode);
 | 
			
		||||
            unregister_code(keycode);
 | 
			
		||||
        } else if (ascii_code == SS_DOWN_CODE) {
 | 
			
		||||
            // down
 | 
			
		||||
            uint8_t keycode = pgm_read_byte(++str);
 | 
			
		||||
            register_code(keycode);
 | 
			
		||||
        } else if (ascii_code == SS_UP_CODE) {
 | 
			
		||||
            // up
 | 
			
		||||
            uint8_t keycode = pgm_read_byte(++str);
 | 
			
		||||
            unregister_code(keycode);
 | 
			
		||||
        if (ascii_code == SS_QMK_PREFIX) {
 | 
			
		||||
            ascii_code = pgm_read_byte(++str);
 | 
			
		||||
            if (ascii_code == SS_TAP_CODE) {
 | 
			
		||||
                // tap
 | 
			
		||||
                uint8_t keycode = pgm_read_byte(++str);
 | 
			
		||||
                register_code(keycode);
 | 
			
		||||
                unregister_code(keycode);
 | 
			
		||||
            } else if (ascii_code == SS_DOWN_CODE) {
 | 
			
		||||
                // down
 | 
			
		||||
                uint8_t keycode = pgm_read_byte(++str);
 | 
			
		||||
                register_code(keycode);
 | 
			
		||||
            } else if (ascii_code == SS_UP_CODE) {
 | 
			
		||||
                // up
 | 
			
		||||
                uint8_t keycode = pgm_read_byte(++str);
 | 
			
		||||
                unregister_code(keycode);
 | 
			
		||||
            } else if (ascii_code == SS_DELAY_CODE) {
 | 
			
		||||
                // delay
 | 
			
		||||
                int     ms      = 0;
 | 
			
		||||
                uint8_t keycode = pgm_read_byte(++str);
 | 
			
		||||
                while (isdigit(keycode)) {
 | 
			
		||||
                    ms *= 10;
 | 
			
		||||
                    ms += keycode - '0';
 | 
			
		||||
                    keycode = pgm_read_byte(++str);
 | 
			
		||||
                }
 | 
			
		||||
                while (ms--) wait_ms(1);
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            send_char(ascii_code);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -382,13 +382,17 @@
 | 
			
		|||
#define ADD_SLASH_X(y) STRINGIZE(\x##y)
 | 
			
		||||
#define SYMBOL_STR(x) ADD_SLASH_X(x)
 | 
			
		||||
 | 
			
		||||
#define SS_QMK_PREFIX 1
 | 
			
		||||
 | 
			
		||||
#define SS_TAP_CODE 1
 | 
			
		||||
#define SS_DOWN_CODE 2
 | 
			
		||||
#define SS_UP_CODE 3
 | 
			
		||||
#define SS_DELAY_CODE 4
 | 
			
		||||
 | 
			
		||||
#define SS_TAP(keycode) "\1" SYMBOL_STR(keycode)
 | 
			
		||||
#define SS_DOWN(keycode) "\2" SYMBOL_STR(keycode)
 | 
			
		||||
#define SS_UP(keycode) "\3" SYMBOL_STR(keycode)
 | 
			
		||||
#define SS_TAP(keycode) "\1\1" SYMBOL_STR(keycode)
 | 
			
		||||
#define SS_DOWN(keycode) "\1\2" SYMBOL_STR(keycode)
 | 
			
		||||
#define SS_UP(keycode) "\1\3" SYMBOL_STR(keycode)
 | 
			
		||||
#define SS_DELAY(msecs) "\1\4" STRINGIZE(msecs) "|"
 | 
			
		||||
 | 
			
		||||
// `string` arguments must not be parenthesized
 | 
			
		||||
#define SS_LCTL(string) SS_DOWN(X_LCTL) string SS_UP(X_LCTL)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue