aboutsummaryrefslogtreecommitdiff
path: root/quantum/dynamic_macro.h
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /quantum/dynamic_macro.h
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
downloadqmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz
qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip
clang-format changes
Diffstat (limited to 'quantum/dynamic_macro.h')
-rw-r--r--quantum/dynamic_macro.h137
1 files changed, 55 insertions, 82 deletions
diff --git a/quantum/dynamic_macro.h b/quantum/dynamic_macro.h
index 07cba19f6..c7632c004 100644
--- a/quantum/dynamic_macro.h
+++ b/quantum/dynamic_macro.h
@@ -30,7 +30,7 @@
30 * there have been reports of it being too much in some users' cases, 30 * there have been reports of it being too much in some users' cases,
31 * so 128 is considered a safe default. 31 * so 128 is considered a safe default.
32 */ 32 */
33#define DYNAMIC_MACRO_SIZE 128 33# define DYNAMIC_MACRO_SIZE 128
34#endif 34#endif
35 35
36/* DYNAMIC_MACRO_RANGE must be set as the last element of user's 36/* DYNAMIC_MACRO_RANGE must be set as the last element of user's
@@ -46,8 +46,7 @@ enum dynamic_macro_keycodes {
46}; 46};
47 47
48/* Blink the LEDs to notify the user about some event. */ 48/* Blink the LEDs to notify the user about some event. */
49void dynamic_macro_led_blink(void) 49void dynamic_macro_led_blink(void) {
50{
51#ifdef BACKLIGHT_ENABLE 50#ifdef BACKLIGHT_ENABLE
52 backlight_toggle(); 51 backlight_toggle();
53 wait_ms(100); 52 wait_ms(100);
@@ -59,10 +58,8 @@ void dynamic_macro_led_blink(void)
59 * need a `direction` variable accessible at the call site. 58 * need a `direction` variable accessible at the call site.
60 */ 59 */
61#define DYNAMIC_MACRO_CURRENT_SLOT() (direction > 0 ? 1 : 2) 60#define DYNAMIC_MACRO_CURRENT_SLOT() (direction > 0 ? 1 : 2)
62#define DYNAMIC_MACRO_CURRENT_LENGTH(BEGIN, POINTER) \ 61#define DYNAMIC_MACRO_CURRENT_LENGTH(BEGIN, POINTER) ((int)(direction * ((POINTER) - (BEGIN))))
63 ((int)(direction * ((POINTER) - (BEGIN)))) 62#define DYNAMIC_MACRO_CURRENT_CAPACITY(BEGIN, END2) ((int)(direction * ((END2) - (BEGIN)) + 1))
64#define DYNAMIC_MACRO_CURRENT_CAPACITY(BEGIN, END2) \
65 ((int)(direction * ((END2) - (BEGIN)) + 1))
66 63
67/** 64/**
68 * Start recording of the dynamic macro. 65 * Start recording of the dynamic macro.
@@ -70,9 +67,7 @@ void dynamic_macro_led_blink(void)
70 * @param[out] macro_pointer The new macro buffer iterator. 67 * @param[out] macro_pointer The new macro buffer iterator.
71 * @param[in] macro_buffer The macro buffer used to initialize macro_pointer. 68 * @param[in] macro_buffer The macro buffer used to initialize macro_pointer.
72 */ 69 */
73void dynamic_macro_record_start( 70void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer) {
74 keyrecord_t **macro_pointer, keyrecord_t *macro_buffer)
75{
76 dprintln("dynamic macro recording: started"); 71 dprintln("dynamic macro recording: started");
77 72
78 dynamic_macro_led_blink(); 73 dynamic_macro_led_blink();
@@ -89,9 +84,7 @@ void dynamic_macro_record_start(
89 * @param macro_end[in] The element after the last macro buffer element. 84 * @param macro_end[in] The element after the last macro buffer element.
90 * @param direction[in] Either +1 or -1, which way to iterate the buffer. 85 * @param direction[in] Either +1 or -1, which way to iterate the buffer.
91 */ 86 */
92void dynamic_macro_play( 87void dynamic_macro_play(keyrecord_t *macro_buffer, keyrecord_t *macro_end, int8_t direction) {
93 keyrecord_t *macro_buffer, keyrecord_t *macro_end, int8_t direction)
94{
95 dprintf("dynamic macro: slot %d playback\n", DYNAMIC_MACRO_CURRENT_SLOT()); 88 dprintf("dynamic macro: slot %d playback\n", DYNAMIC_MACRO_CURRENT_SLOT());
96 89
97 uint32_t saved_layer_state = layer_state; 90 uint32_t saved_layer_state = layer_state;
@@ -118,13 +111,7 @@ void dynamic_macro_play(
118 * @param direction[in] Either +1 or -1, which way to iterate the buffer. 111 * @param direction[in] Either +1 or -1, which way to iterate the buffer.
119 * @param record[in] The current keypress. 112 * @param record[in] The current keypress.
120 */ 113 */
121void dynamic_macro_record_key( 114void dynamic_macro_record_key(keyrecord_t *macro_buffer, keyrecord_t **macro_pointer, keyrecord_t *macro2_end, int8_t direction, keyrecord_t *record) {
122 keyrecord_t *macro_buffer,
123 keyrecord_t **macro_pointer,
124 keyrecord_t *macro2_end,
125 int8_t direction,
126 keyrecord_t *record)
127{
128 /* If we've just started recording, ignore all the key releases. */ 115 /* If we've just started recording, ignore all the key releases. */
129 if (!record->event.pressed && *macro_pointer == macro_buffer) { 116 if (!record->event.pressed && *macro_pointer == macro_buffer) {
130 dprintln("dynamic macro: ignoring a leading key-up event"); 117 dprintln("dynamic macro: ignoring a leading key-up event");
@@ -141,38 +128,25 @@ void dynamic_macro_record_key(
141 dynamic_macro_led_blink(); 128 dynamic_macro_led_blink();
142 } 129 }
143 130
144 dprintf( 131 dprintf("dynamic macro: slot %d length: %d/%d\n", DYNAMIC_MACRO_CURRENT_SLOT(), DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, *macro_pointer), DYNAMIC_MACRO_CURRENT_CAPACITY(macro_buffer, macro2_end));
145 "dynamic macro: slot %d length: %d/%d\n",
146 DYNAMIC_MACRO_CURRENT_SLOT(),
147 DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, *macro_pointer),
148 DYNAMIC_MACRO_CURRENT_CAPACITY(macro_buffer, macro2_end));
149} 132}
150 133
151/** 134/**
152 * End recording of the dynamic macro. Essentially just update the 135 * End recording of the dynamic macro. Essentially just update the
153 * pointer to the end of the macro. 136 * pointer to the end of the macro.
154 */ 137 */
155void dynamic_macro_record_end( 138void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_pointer, int8_t direction, keyrecord_t **macro_end) {
156 keyrecord_t *macro_buffer,
157 keyrecord_t *macro_pointer,
158 int8_t direction,
159 keyrecord_t **macro_end)
160{
161 dynamic_macro_led_blink(); 139 dynamic_macro_led_blink();
162 140
163 /* Do not save the keys being held when stopping the recording, 141 /* Do not save the keys being held when stopping the recording,
164 * i.e. the keys used to access the layer DYN_REC_STOP is on. 142 * i.e. the keys used to access the layer DYN_REC_STOP is on.
165 */ 143 */
166 while (macro_pointer != macro_buffer && 144 while (macro_pointer != macro_buffer && (macro_pointer - direction)->event.pressed) {
167 (macro_pointer - direction)->event.pressed) {
168 dprintln("dynamic macro: trimming a trailing key-down event"); 145 dprintln("dynamic macro: trimming a trailing key-down event");
169 macro_pointer -= direction; 146 macro_pointer -= direction;
170 } 147 }
171 148
172 dprintf( 149 dprintf("dynamic macro: slot %d saved, length: %d\n", DYNAMIC_MACRO_CURRENT_SLOT(), DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, macro_pointer));
173 "dynamic macro: slot %d saved, length: %d\n",
174 DYNAMIC_MACRO_CURRENT_SLOT(),
175 DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, macro_pointer));
176 150
177 *macro_end = macro_pointer; 151 *macro_end = macro_pointer;
178} 152}
@@ -187,8 +161,7 @@ void dynamic_macro_record_end(
187 * <...THE REST OF THE FUNCTION...> 161 * <...THE REST OF THE FUNCTION...>
188 * } 162 * }
189 */ 163 */
190bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record) 164bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
191{
192 /* Both macros use the same buffer but read/write on different 165 /* Both macros use the same buffer but read/write on different
193 * ends of it. 166 * ends of it.
194 * 167 *
@@ -239,57 +212,57 @@ bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record)
239 /* No macro recording in progress. */ 212 /* No macro recording in progress. */
240 if (!record->event.pressed) { 213 if (!record->event.pressed) {
241 switch (keycode) { 214 switch (keycode) {
242 case DYN_REC_START1: 215 case DYN_REC_START1:
243 dynamic_macro_record_start(&macro_pointer, macro_buffer); 216 dynamic_macro_record_start(&macro_pointer, macro_buffer);
244 macro_id = 1; 217 macro_id = 1;
245 return false; 218 return false;
246 case DYN_REC_START2: 219 case DYN_REC_START2:
247 dynamic_macro_record_start(&macro_pointer, r_macro_buffer); 220 dynamic_macro_record_start(&macro_pointer, r_macro_buffer);
248 macro_id = 2; 221 macro_id = 2;
249 return false; 222 return false;
250 case DYN_MACRO_PLAY1: 223 case DYN_MACRO_PLAY1:
251 dynamic_macro_play(macro_buffer, macro_end, +1); 224 dynamic_macro_play(macro_buffer, macro_end, +1);
252 return false; 225 return false;
253 case DYN_MACRO_PLAY2: 226 case DYN_MACRO_PLAY2:
254 dynamic_macro_play(r_macro_buffer, r_macro_end, -1); 227 dynamic_macro_play(r_macro_buffer, r_macro_end, -1);
255 return false; 228 return false;
256 } 229 }
257 } 230 }
258 } else { 231 } else {
259 /* A macro is being recorded right now. */ 232 /* A macro is being recorded right now. */
260 switch (keycode) { 233 switch (keycode) {
261 case DYN_REC_STOP: 234 case DYN_REC_STOP:
262 /* Stop the macro recording. */ 235 /* Stop the macro recording. */
263 if (record->event.pressed) { /* Ignore the initial release 236 if (record->event.pressed) { /* Ignore the initial release
264 * just after the recoding 237 * just after the recoding
265 * starts. */ 238 * starts. */
239 switch (macro_id) {
240 case 1:
241 dynamic_macro_record_end(macro_buffer, macro_pointer, +1, &macro_end);
242 break;
243 case 2:
244 dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end);
245 break;
246 }
247 macro_id = 0;
248 }
249 return false;
250 case DYN_MACRO_PLAY1:
251 case DYN_MACRO_PLAY2:
252 dprintln("dynamic macro: ignoring macro play key while recording");
253 return false;
254 default:
255 /* Store the key in the macro buffer and process it normally. */
266 switch (macro_id) { 256 switch (macro_id) {
267 case 1: 257 case 1:
268 dynamic_macro_record_end(macro_buffer, macro_pointer, +1, &macro_end); 258 dynamic_macro_record_key(macro_buffer, &macro_pointer, r_macro_end, +1, record);
269 break; 259 break;
270 case 2: 260 case 2:
271 dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); 261 dynamic_macro_record_key(r_macro_buffer, &macro_pointer, macro_end, -1, record);
272 break; 262 break;
273 } 263 }
274 macro_id = 0; 264 return true;
275 }
276 return false;
277 case DYN_MACRO_PLAY1:
278 case DYN_MACRO_PLAY2:
279 dprintln("dynamic macro: ignoring macro play key while recording");
280 return false;
281 default:
282 /* Store the key in the macro buffer and process it normally. */
283 switch (macro_id) {
284 case 1:
285 dynamic_macro_record_key(macro_buffer, &macro_pointer, r_macro_end, +1, record);
286 break;
287 case 2:
288 dynamic_macro_record_key(r_macro_buffer, &macro_pointer, macro_end, -1, record);
289 break; 265 break;
290 }
291 return true;
292 break;
293 } 266 }
294 } 267 }
295 268