summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2020-02-27 20:38:19 +1100
committerGitHub <noreply@github.com>2020-02-27 20:38:19 +1100
commit444fd3b1cc07d7f68aa37cbc9e38f2e4ed4d3ea7 (patch)
tree9198deb31eb8b79b3416f3806ef5d6b9da340829 /quantum
parente18be6910493c132fa84be1f21a579fa9b9e12a9 (diff)
downloadqmk_firmware-444fd3b1cc07d7f68aa37cbc9e38f2e4ed4d3ea7.tar.gz
qmk_firmware-444fd3b1cc07d7f68aa37cbc9e38f2e4ed4d3ea7.zip
Add support for delays in send_string. (#8244)
Diffstat (limited to 'quantum')
-rw-r--r--quantum/quantum.c79
-rw-r--r--quantum/send_string_keycodes.h10
2 files changed, 60 insertions, 29 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 52062bb174..1b5ce3292c 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -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);
}
diff --git a/quantum/send_string_keycodes.h b/quantum/send_string_keycodes.h
index b4a50f84d3..86dc8bf00c 100644
--- a/quantum/send_string_keycodes.h
+++ b/quantum/send_string_keycodes.h
@@ -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)