From 4ff40a551a310e9b29a5838f87a9db58c0e5767e Mon Sep 17 00:00:00 2001 From: Weiyi Lou Date: Sat, 29 Apr 2017 22:02:01 +1000 Subject: Add `DYN_REC_STOP` to dynamic macros Dynamic macro functionality is modified to check for `DYN_REC_STOP`, so that macro recording can be stopped with a designated key combination (e.g. `qs` or anything) instead of mandating the use of a `_DYN` layer. `_DYN` layer stopping can still be done by passing `DYN_REC_STOP` within `process_record_user()`: bool process_record_user(uint16_t keycode, keyrecord_t *record) { uint16_t macro_kc = (keycode == MO(_DYN) ? DYN_REC_STOP : keycode); if (!process_record_dynamic_macro(macro_kc, record)) { return false; } return true; } --- quantum/dynamic_macro.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'quantum/dynamic_macro.h') diff --git a/quantum/dynamic_macro.h b/quantum/dynamic_macro.h index 64093f293..939816a59 100644 --- a/quantum/dynamic_macro.h +++ b/quantum/dynamic_macro.h @@ -40,6 +40,7 @@ enum dynamic_macro_keycodes { DYN_REC_START1 = DYNAMIC_MACRO_RANGE, DYN_REC_START2, + DYN_REC_STOP, DYN_MACRO_PLAY1, DYN_MACRO_PLAY2, }; @@ -209,9 +210,8 @@ bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record) } else { /* A macro is being recorded right now. */ switch (keycode) { - case MO(_DYN): - /* Use the layer key used to access the macro recording as - * a stop button. */ + case DYN_REC_STOP: + /* Stop the macro recording. */ if (record->event.pressed) { /* Ignore the initial release * just after the recoding * starts. */ -- cgit v1.2.3-24-g4f1b From 40fe30e4d6b521284fa3cb7ae217ebb6d013bcdf Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Wed, 3 May 2017 23:47:52 +0200 Subject: dynamic_macro.h: Ignore all the initial key releases Right after the user initiates the macro recording, they usually need to release some keys used to access the DYN_REC_START layers. It makes sense to ignore them. Note: The keys used to access the DYN_REC_STOP key are *not* ignored. --- quantum/dynamic_macro.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'quantum/dynamic_macro.h') diff --git a/quantum/dynamic_macro.h b/quantum/dynamic_macro.h index 939816a59..1a8ec4032 100644 --- a/quantum/dynamic_macro.h +++ b/quantum/dynamic_macro.h @@ -97,17 +97,24 @@ void dynamic_macro_play( /** * Record a single key in a dynamic macro. * + * @param macro_buffer[in] The start of the used macro buffer. * @param macro_pointer[in,out] The current buffer position. * @param macro_end2[in] The end of the other macro which shouldn't be overwritten. * @param direction[in] Either +1 or -1, which way to iterate the buffer. * @param record[in] The current keypress. */ void dynamic_macro_record_key( + keyrecord_t *macro_buffer, keyrecord_t **macro_pointer, keyrecord_t *macro_end2, int8_t direction, keyrecord_t *record) { + /* If we've just started recording, ignore all the key releases. */ + if (!record->event.pressed && *macro_pointer == macro_buffer) { + return; + } + if (*macro_pointer + direction != macro_end2) { **macro_pointer = *record; *macro_pointer += direction; @@ -230,10 +237,10 @@ bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record) /* Store the key in the macro buffer and process it normally. */ switch (macro_id) { case 1: - dynamic_macro_record_key(¯o_pointer, r_macro_end, +1, record); + dynamic_macro_record_key(macro_buffer, ¯o_pointer, r_macro_end, +1, record); break; case 2: - dynamic_macro_record_key(¯o_pointer, macro_end, -1, record); + dynamic_macro_record_key(r_macro_buffer, ¯o_pointer, macro_end, -1, record); break; } return true; -- cgit v1.2.3-24-g4f1b From 5e2a9992783e584f66dfeef16abf9d31c976311a Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Thu, 4 May 2017 00:58:01 +0200 Subject: dynamic_macro.h: Always toggle the backlight twice as a notification Apparently sometimes the backlight was toggled only once and it was left on. --- quantum/dynamic_macro.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'quantum/dynamic_macro.h') diff --git a/quantum/dynamic_macro.h b/quantum/dynamic_macro.h index 1a8ec4032..c9120897f 100644 --- a/quantum/dynamic_macro.h +++ b/quantum/dynamic_macro.h @@ -119,9 +119,7 @@ void dynamic_macro_record_key( **macro_pointer = *record; *macro_pointer += direction; } else { - /* Notify about the end of buffer. The blinks are paired - * because they should happen on both down and up events. */ - backlight_toggle(); + dynamic_macro_led_blink(); } } -- cgit v1.2.3-24-g4f1b From 436d661775178fb62b46afdc3d755fdb413dcb35 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Thu, 4 May 2017 01:19:05 +0200 Subject: dynamic_macro.h: Fix an off-by-two error We need to check whether we just passed the after-the-end point of the other macro. Instead we were checking whether we are going to reach it now. --- quantum/dynamic_macro.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'quantum/dynamic_macro.h') diff --git a/quantum/dynamic_macro.h b/quantum/dynamic_macro.h index c9120897f..9e7845c99 100644 --- a/quantum/dynamic_macro.h +++ b/quantum/dynamic_macro.h @@ -99,14 +99,14 @@ void dynamic_macro_play( * * @param macro_buffer[in] The start of the used macro buffer. * @param macro_pointer[in,out] The current buffer position. - * @param macro_end2[in] The end of the other macro which shouldn't be overwritten. + * @param macro2_end[in] The last buffer element it is safe to use before overwriting the other macro. * @param direction[in] Either +1 or -1, which way to iterate the buffer. * @param record[in] The current keypress. */ void dynamic_macro_record_key( keyrecord_t *macro_buffer, keyrecord_t **macro_pointer, - keyrecord_t *macro_end2, + keyrecord_t *macro2_end, int8_t direction, keyrecord_t *record) { @@ -115,7 +115,7 @@ void dynamic_macro_record_key( return; } - if (*macro_pointer + direction != macro_end2) { + if (*macro_pointer - direction != macro2_end) { **macro_pointer = *record; *macro_pointer += direction; } else { -- cgit v1.2.3-24-g4f1b