From b624f32f944acdc59dcb130674c09090c5c404cb Mon Sep 17 00:00:00 2001 From: skullY Date: Fri, 30 Aug 2019 11:19:03 -0700 Subject: clang-format changes --- quantum/dynamic_macro.h | 137 +++++++++++++++++++----------------------------- 1 file changed, 55 insertions(+), 82 deletions(-) (limited to 'quantum/dynamic_macro.h') diff --git a/quantum/dynamic_macro.h b/quantum/dynamic_macro.h index 07cba19f60..c7632c004b 100644 --- a/quantum/dynamic_macro.h +++ b/quantum/dynamic_macro.h @@ -30,7 +30,7 @@ * there have been reports of it being too much in some users' cases, * so 128 is considered a safe default. */ -#define DYNAMIC_MACRO_SIZE 128 +# define DYNAMIC_MACRO_SIZE 128 #endif /* DYNAMIC_MACRO_RANGE must be set as the last element of user's @@ -46,8 +46,7 @@ enum dynamic_macro_keycodes { }; /* Blink the LEDs to notify the user about some event. */ -void dynamic_macro_led_blink(void) -{ +void dynamic_macro_led_blink(void) { #ifdef BACKLIGHT_ENABLE backlight_toggle(); wait_ms(100); @@ -59,10 +58,8 @@ void dynamic_macro_led_blink(void) * need a `direction` variable accessible at the call site. */ #define DYNAMIC_MACRO_CURRENT_SLOT() (direction > 0 ? 1 : 2) -#define DYNAMIC_MACRO_CURRENT_LENGTH(BEGIN, POINTER) \ - ((int)(direction * ((POINTER) - (BEGIN)))) -#define DYNAMIC_MACRO_CURRENT_CAPACITY(BEGIN, END2) \ - ((int)(direction * ((END2) - (BEGIN)) + 1)) +#define DYNAMIC_MACRO_CURRENT_LENGTH(BEGIN, POINTER) ((int)(direction * ((POINTER) - (BEGIN)))) +#define DYNAMIC_MACRO_CURRENT_CAPACITY(BEGIN, END2) ((int)(direction * ((END2) - (BEGIN)) + 1)) /** * Start recording of the dynamic macro. @@ -70,9 +67,7 @@ void dynamic_macro_led_blink(void) * @param[out] macro_pointer The new macro buffer iterator. * @param[in] macro_buffer The macro buffer used to initialize macro_pointer. */ -void dynamic_macro_record_start( - keyrecord_t **macro_pointer, keyrecord_t *macro_buffer) -{ +void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer) { dprintln("dynamic macro recording: started"); dynamic_macro_led_blink(); @@ -89,9 +84,7 @@ void dynamic_macro_record_start( * @param macro_end[in] The element after the last macro buffer element. * @param direction[in] Either +1 or -1, which way to iterate the buffer. */ -void dynamic_macro_play( - keyrecord_t *macro_buffer, keyrecord_t *macro_end, int8_t direction) -{ +void dynamic_macro_play(keyrecord_t *macro_buffer, keyrecord_t *macro_end, int8_t direction) { dprintf("dynamic macro: slot %d playback\n", DYNAMIC_MACRO_CURRENT_SLOT()); uint32_t saved_layer_state = layer_state; @@ -118,13 +111,7 @@ void dynamic_macro_play( * @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 *macro2_end, - int8_t direction, - keyrecord_t *record) -{ +void dynamic_macro_record_key(keyrecord_t *macro_buffer, keyrecord_t **macro_pointer, keyrecord_t *macro2_end, 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) { dprintln("dynamic macro: ignoring a leading key-up event"); @@ -141,38 +128,25 @@ void dynamic_macro_record_key( dynamic_macro_led_blink(); } - 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)); + 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)); } /** * End recording of the dynamic macro. Essentially just update the * pointer to the end of the macro. */ -void dynamic_macro_record_end( - keyrecord_t *macro_buffer, - keyrecord_t *macro_pointer, - int8_t direction, - keyrecord_t **macro_end) -{ +void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_pointer, int8_t direction, keyrecord_t **macro_end) { dynamic_macro_led_blink(); /* Do not save the keys being held when stopping the recording, * i.e. the keys used to access the layer DYN_REC_STOP is on. */ - while (macro_pointer != macro_buffer && - (macro_pointer - direction)->event.pressed) { + while (macro_pointer != macro_buffer && (macro_pointer - direction)->event.pressed) { dprintln("dynamic macro: trimming a trailing key-down event"); macro_pointer -= direction; } - dprintf( - "dynamic macro: slot %d saved, length: %d\n", - DYNAMIC_MACRO_CURRENT_SLOT(), - DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, macro_pointer)); + dprintf("dynamic macro: slot %d saved, length: %d\n", DYNAMIC_MACRO_CURRENT_SLOT(), DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, macro_pointer)); *macro_end = macro_pointer; } @@ -187,8 +161,7 @@ void dynamic_macro_record_end( * <...THE REST OF THE FUNCTION...> * } */ -bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record) -{ +bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record) { /* Both macros use the same buffer but read/write on different * ends of it. * @@ -239,57 +212,57 @@ bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record) /* No macro recording in progress. */ if (!record->event.pressed) { switch (keycode) { - case DYN_REC_START1: - dynamic_macro_record_start(¯o_pointer, macro_buffer); - macro_id = 1; - return false; - case DYN_REC_START2: - dynamic_macro_record_start(¯o_pointer, r_macro_buffer); - macro_id = 2; - return false; - case DYN_MACRO_PLAY1: - dynamic_macro_play(macro_buffer, macro_end, +1); - return false; - case DYN_MACRO_PLAY2: - dynamic_macro_play(r_macro_buffer, r_macro_end, -1); - return false; + case DYN_REC_START1: + dynamic_macro_record_start(¯o_pointer, macro_buffer); + macro_id = 1; + return false; + case DYN_REC_START2: + dynamic_macro_record_start(¯o_pointer, r_macro_buffer); + macro_id = 2; + return false; + case DYN_MACRO_PLAY1: + dynamic_macro_play(macro_buffer, macro_end, +1); + return false; + case DYN_MACRO_PLAY2: + dynamic_macro_play(r_macro_buffer, r_macro_end, -1); + return false; } } } else { /* A macro is being recorded right now. */ switch (keycode) { - case DYN_REC_STOP: - /* Stop the macro recording. */ - if (record->event.pressed) { /* Ignore the initial release - * just after the recoding - * starts. */ + case DYN_REC_STOP: + /* Stop the macro recording. */ + if (record->event.pressed) { /* Ignore the initial release + * just after the recoding + * starts. */ + switch (macro_id) { + case 1: + dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); + break; + case 2: + dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); + break; + } + macro_id = 0; + } + return false; + case DYN_MACRO_PLAY1: + case DYN_MACRO_PLAY2: + dprintln("dynamic macro: ignoring macro play key while recording"); + return false; + default: + /* Store the key in the macro buffer and process it normally. */ switch (macro_id) { - case 1: - dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); - break; - case 2: - dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); - break; + case 1: + dynamic_macro_record_key(macro_buffer, ¯o_pointer, r_macro_end, +1, record); + break; + case 2: + dynamic_macro_record_key(r_macro_buffer, ¯o_pointer, macro_end, -1, record); + break; } - macro_id = 0; - } - return false; - case DYN_MACRO_PLAY1: - case DYN_MACRO_PLAY2: - dprintln("dynamic macro: ignoring macro play key while recording"); - return false; - default: - /* Store the key in the macro buffer and process it normally. */ - switch (macro_id) { - case 1: - dynamic_macro_record_key(macro_buffer, ¯o_pointer, r_macro_end, +1, record); - break; - case 2: - dynamic_macro_record_key(r_macro_buffer, ¯o_pointer, macro_end, -1, record); + return true; break; - } - return true; - break; } } -- cgit v1.2.3 From 542cb0a8ce3f324c6bd46751d733daf86384a8f6 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 4 Nov 2019 22:59:13 -0800 Subject: [Core] Convert Dynamic Macro to a Core Feature (#5948) * Convert Dynamic Macro to a Core Feature This imports the code from Dynamic Macro into the core code, and handles it, as such. This deprecates the old method but does not remove it, for legacy support. This way, no existing user files need to be touched. Additionally, this reorganizes the documentation to better reflect the changes. Also, it adds user hooks to the feature so users can customize the existing functionality. Based heavily on and closes #2976 * Apply suggestions from code review Co-Authored-By: fauxpark Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Cleanup based on feedback * Add short-form keycodes and document them - add short-form keycodes to quantum/quantum_keycodes.h - document the new aliases in docs/feature_dynamic_macros.md * Add Dynamic Macros section and keycodes to docs/keycodes.md * Make anti-nesting optional * Add documentation for DYNAMIC_MACRO_NO_NESTING option * Fix Merge artifacts * Fix formatting typo in docs Co-Authored-By: James Young <18669334+noroadsleft@users.noreply.github.com> * Remove DYNAMIC_MACRO_RANGE as it's not needed * Fix includes and layer var type --- quantum/dynamic_macro.h | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'quantum/dynamic_macro.h') diff --git a/quantum/dynamic_macro.h b/quantum/dynamic_macro.h index c7632c004b..fe9de6fa65 100644 --- a/quantum/dynamic_macro.h +++ b/quantum/dynamic_macro.h @@ -15,8 +15,10 @@ */ /* Author: Wojciech Siewierski < wojciech dot siewierski at onet dot pl > */ -#ifndef DYNAMIC_MACROS_H -#define DYNAMIC_MACROS_H +#pragma once + +/* Warn users that this is now deprecated and they should use the core feature instead. */ +#pragma message "Dynamic Macros is now a core feature. See updated documentation to see how to configure it: https://docs.qmk.fm/#/feature_dynamic_macros" #include "action_layer.h" @@ -33,18 +35,6 @@ # define DYNAMIC_MACRO_SIZE 128 #endif -/* DYNAMIC_MACRO_RANGE must be set as the last element of user's - * "planck_keycodes" enum prior to including this header. This allows - * us to 'extend' it. - */ -enum dynamic_macro_keycodes { - DYN_REC_START1 = DYNAMIC_MACRO_RANGE, - DYN_REC_START2, - DYN_REC_STOP, - DYN_MACRO_PLAY1, - DYN_MACRO_PLAY2, -}; - /* Blink the LEDs to notify the user about some event. */ void dynamic_macro_led_blink(void) { #ifdef BACKLIGHT_ENABLE @@ -272,5 +262,3 @@ bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record) { #undef DYNAMIC_MACRO_CURRENT_SLOT #undef DYNAMIC_MACRO_CURRENT_LENGTH #undef DYNAMIC_MACRO_CURRENT_CAPACITY - -#endif -- cgit v1.2.3