diff options
| author | Ariane Emory <97994360+ariane-emory@users.noreply.github.com> | 2023-06-02 17:46:04 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-02 14:46:04 -0700 |
| commit | c754f644dcccc44e09a3e6f9986ad70ec2fc3b54 (patch) | |
| tree | ad67cd9ef8a9ea3c6df15613f40abfc870e18cce /quantum/process_keycode | |
| parent | 27120f2fb6cc32a1a544c2d26decce8facac9740 (diff) | |
[Core] Move dynamic macro "stop recording" logic to a function (#21108)
Diffstat (limited to 'quantum/process_keycode')
| -rw-r--r-- | quantum/process_keycode/process_dynamic_macro.c | 117 | ||||
| -rw-r--r-- | quantum/process_keycode/process_dynamic_macro.h | 1 |
2 files changed, 63 insertions, 55 deletions
diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index bf6af566e2..a022949d3d 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c | |||
| @@ -151,6 +151,67 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin | |||
| 151 | *macro_end = macro_pointer; | 151 | *macro_end = macro_pointer; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | /* Both macros use the same buffer but read/write on different | ||
| 155 | * ends of it. | ||
| 156 | * | ||
| 157 | * Macro1 is written left-to-right starting from the beginning of | ||
| 158 | * the buffer. | ||
| 159 | * | ||
| 160 | * Macro2 is written right-to-left starting from the end of the | ||
| 161 | * buffer. | ||
| 162 | * | ||
| 163 | * ¯o_buffer macro_end | ||
| 164 | * v v | ||
| 165 | * +------------------------------------------------------------+ | ||
| 166 | * |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<| | ||
| 167 | * +------------------------------------------------------------+ | ||
| 168 | * ^ ^ | ||
| 169 | * r_macro_end r_macro_buffer | ||
| 170 | * | ||
| 171 | * During the recording when one macro encounters the end of the | ||
| 172 | * other macro, the recording is stopped. Apart from this, there | ||
| 173 | * are no arbitrary limits for the macros' length in relation to | ||
| 174 | * each other: for example one can either have two medium sized | ||
| 175 | * macros or one long macro and one short macro. Or even one empty | ||
| 176 | * and one using the whole buffer. | ||
| 177 | */ | ||
| 178 | static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE]; | ||
| 179 | |||
| 180 | /* Pointer to the first buffer element after the first macro. | ||
| 181 | * Initially points to the very beginning of the buffer since the | ||
| 182 | * macro is empty. */ | ||
| 183 | static keyrecord_t *macro_end = macro_buffer; | ||
| 184 | |||
| 185 | /* The other end of the macro buffer. Serves as the beginning of | ||
| 186 | * the second macro. */ | ||
| 187 | static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1; | ||
| 188 | |||
| 189 | /* Like macro_end but for the second macro. */ | ||
| 190 | static keyrecord_t *r_macro_end = r_macro_buffer; | ||
| 191 | |||
| 192 | /* A persistent pointer to the current macro position (iterator) | ||
| 193 | * used during the recording. */ | ||
| 194 | static keyrecord_t *macro_pointer = NULL; | ||
| 195 | |||
| 196 | /* 0 - no macro is being recorded right now | ||
| 197 | * 1,2 - either macro 1 or 2 is being recorded */ | ||
| 198 | static uint8_t macro_id = 0; | ||
| 199 | |||
| 200 | /** | ||
| 201 | * If a dynamic macro is currently being recorded, stop recording. | ||
| 202 | */ | ||
| 203 | void dynamic_macro_stop_recording(void) { | ||
| 204 | switch (macro_id) { | ||
| 205 | case 1: | ||
| 206 | dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); | ||
| 207 | break; | ||
| 208 | case 2: | ||
| 209 | dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); | ||
| 210 | break; | ||
| 211 | } | ||
| 212 | macro_id = 0; | ||
| 213 | } | ||
| 214 | |||
| 154 | /* Handle the key events related to the dynamic macros. Should be | 215 | /* Handle the key events related to the dynamic macros. Should be |
| 155 | * called from process_record_user() like this: | 216 | * called from process_record_user() like this: |
| 156 | * | 217 | * |
| @@ -162,52 +223,6 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin | |||
| 162 | * } | 223 | * } |
| 163 | */ | 224 | */ |
| 164 | bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { | 225 | bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { |
| 165 | /* Both macros use the same buffer but read/write on different | ||
| 166 | * ends of it. | ||
| 167 | * | ||
| 168 | * Macro1 is written left-to-right starting from the beginning of | ||
| 169 | * the buffer. | ||
| 170 | * | ||
| 171 | * Macro2 is written right-to-left starting from the end of the | ||
| 172 | * buffer. | ||
| 173 | * | ||
| 174 | * ¯o_buffer macro_end | ||
| 175 | * v v | ||
| 176 | * +------------------------------------------------------------+ | ||
| 177 | * |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<| | ||
| 178 | * +------------------------------------------------------------+ | ||
| 179 | * ^ ^ | ||
| 180 | * r_macro_end r_macro_buffer | ||
| 181 | * | ||
| 182 | * During the recording when one macro encounters the end of the | ||
| 183 | * other macro, the recording is stopped. Apart from this, there | ||
| 184 | * are no arbitrary limits for the macros' length in relation to | ||
| 185 | * each other: for example one can either have two medium sized | ||
| 186 | * macros or one long macro and one short macro. Or even one empty | ||
| 187 | * and one using the whole buffer. | ||
| 188 | */ | ||
| 189 | static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE]; | ||
| 190 | |||
| 191 | /* Pointer to the first buffer element after the first macro. | ||
| 192 | * Initially points to the very beginning of the buffer since the | ||
| 193 | * macro is empty. */ | ||
| 194 | static keyrecord_t *macro_end = macro_buffer; | ||
| 195 | |||
| 196 | /* The other end of the macro buffer. Serves as the beginning of | ||
| 197 | * the second macro. */ | ||
| 198 | static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1; | ||
| 199 | |||
| 200 | /* Like macro_end but for the second macro. */ | ||
| 201 | static keyrecord_t *r_macro_end = r_macro_buffer; | ||
| 202 | |||
| 203 | /* A persistent pointer to the current macro position (iterator) | ||
| 204 | * used during the recording. */ | ||
| 205 | static keyrecord_t *macro_pointer = NULL; | ||
| 206 | |||
| 207 | /* 0 - no macro is being recorded right now | ||
| 208 | * 1,2 - either macro 1 or 2 is being recorded */ | ||
| 209 | static uint8_t macro_id = 0; | ||
| 210 | |||
| 211 | if (macro_id == 0) { | 226 | if (macro_id == 0) { |
| 212 | /* No macro recording in progress. */ | 227 | /* No macro recording in progress. */ |
| 213 | if (!record->event.pressed) { | 228 | if (!record->event.pressed) { |
| @@ -238,15 +253,7 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { | |||
| 238 | if (record->event.pressed ^ (keycode != QK_DYNAMIC_MACRO_RECORD_STOP)) { /* Ignore the initial release | 253 | if (record->event.pressed ^ (keycode != QK_DYNAMIC_MACRO_RECORD_STOP)) { /* Ignore the initial release |
| 239 | * just after the recording | 254 | * just after the recording |
| 240 | * starts for DM_RSTP. */ | 255 | * starts for DM_RSTP. */ |
| 241 | switch (macro_id) { | 256 | dynamic_macro_stop_recording(); |
| 242 | case 1: | ||
| 243 | dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); | ||
| 244 | break; | ||
| 245 | case 2: | ||
| 246 | dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); | ||
| 247 | break; | ||
| 248 | } | ||
| 249 | macro_id = 0; | ||
| 250 | } | 257 | } |
| 251 | return false; | 258 | return false; |
| 252 | #ifdef DYNAMIC_MACRO_NO_NESTING | 259 | #ifdef DYNAMIC_MACRO_NO_NESTING |
diff --git a/quantum/process_keycode/process_dynamic_macro.h b/quantum/process_keycode/process_dynamic_macro.h index ab70726897..9841254af4 100644 --- a/quantum/process_keycode/process_dynamic_macro.h +++ b/quantum/process_keycode/process_dynamic_macro.h | |||
| @@ -39,3 +39,4 @@ void dynamic_macro_record_start_user(int8_t direction); | |||
| 39 | void dynamic_macro_play_user(int8_t direction); | 39 | void dynamic_macro_play_user(int8_t direction); |
| 40 | void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record); | 40 | void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record); |
| 41 | void dynamic_macro_record_end_user(int8_t direction); | 41 | void dynamic_macro_record_end_user(int8_t direction); |
| 42 | void dynamic_macro_stop_recording(void); | ||
