mirror of
https://github.com/firewalkwithm3/qmk_firmware.git
synced 2024-11-22 19:40:29 +08:00
[Core] Move dynamic macro "stop recording" logic to a function (#21108)
This commit is contained in:
parent
27120f2fb6
commit
c754f644dc
|
@ -151,18 +151,7 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin
|
||||||
*macro_end = macro_pointer;
|
*macro_end = macro_pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle the key events related to the dynamic macros. Should be
|
/* Both macros use the same buffer but read/write on different
|
||||||
* called from process_record_user() like this:
|
|
||||||
*
|
|
||||||
* bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
|
||||||
* if (!process_record_dynamic_macro(keycode, record)) {
|
|
||||||
* return false;
|
|
||||||
* }
|
|
||||||
* <...THE REST OF THE FUNCTION...>
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
|
|
||||||
/* Both macros use the same buffer but read/write on different
|
|
||||||
* ends of it.
|
* ends of it.
|
||||||
*
|
*
|
||||||
* Macro1 is written left-to-right starting from the beginning of
|
* Macro1 is written left-to-right starting from the beginning of
|
||||||
|
@ -186,28 +175,54 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
|
||||||
* macros or one long macro and one short macro. Or even one empty
|
* macros or one long macro and one short macro. Or even one empty
|
||||||
* and one using the whole buffer.
|
* and one using the whole buffer.
|
||||||
*/
|
*/
|
||||||
static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE];
|
static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE];
|
||||||
|
|
||||||
/* Pointer to the first buffer element after the first macro.
|
/* Pointer to the first buffer element after the first macro.
|
||||||
* Initially points to the very beginning of the buffer since the
|
* Initially points to the very beginning of the buffer since the
|
||||||
* macro is empty. */
|
* macro is empty. */
|
||||||
static keyrecord_t *macro_end = macro_buffer;
|
static keyrecord_t *macro_end = macro_buffer;
|
||||||
|
|
||||||
/* The other end of the macro buffer. Serves as the beginning of
|
/* The other end of the macro buffer. Serves as the beginning of
|
||||||
* the second macro. */
|
* the second macro. */
|
||||||
static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1;
|
static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1;
|
||||||
|
|
||||||
/* Like macro_end but for the second macro. */
|
/* Like macro_end but for the second macro. */
|
||||||
static keyrecord_t *r_macro_end = r_macro_buffer;
|
static keyrecord_t *r_macro_end = r_macro_buffer;
|
||||||
|
|
||||||
/* A persistent pointer to the current macro position (iterator)
|
/* A persistent pointer to the current macro position (iterator)
|
||||||
* used during the recording. */
|
* used during the recording. */
|
||||||
static keyrecord_t *macro_pointer = NULL;
|
static keyrecord_t *macro_pointer = NULL;
|
||||||
|
|
||||||
/* 0 - no macro is being recorded right now
|
/* 0 - no macro is being recorded right now
|
||||||
* 1,2 - either macro 1 or 2 is being recorded */
|
* 1,2 - either macro 1 or 2 is being recorded */
|
||||||
static uint8_t macro_id = 0;
|
static uint8_t macro_id = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a dynamic macro is currently being recorded, stop recording.
|
||||||
|
*/
|
||||||
|
void dynamic_macro_stop_recording(void) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Handle the key events related to the dynamic macros. Should be
|
||||||
|
* called from process_record_user() like this:
|
||||||
|
*
|
||||||
|
* bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
* if (!process_record_dynamic_macro(keycode, record)) {
|
||||||
|
* return false;
|
||||||
|
* }
|
||||||
|
* <...THE REST OF THE FUNCTION...>
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
|
||||||
if (macro_id == 0) {
|
if (macro_id == 0) {
|
||||||
/* No macro recording in progress. */
|
/* No macro recording in progress. */
|
||||||
if (!record->event.pressed) {
|
if (!record->event.pressed) {
|
||||||
|
@ -238,15 +253,7 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
|
||||||
if (record->event.pressed ^ (keycode != QK_DYNAMIC_MACRO_RECORD_STOP)) { /* Ignore the initial release
|
if (record->event.pressed ^ (keycode != QK_DYNAMIC_MACRO_RECORD_STOP)) { /* Ignore the initial release
|
||||||
* just after the recording
|
* just after the recording
|
||||||
* starts for DM_RSTP. */
|
* starts for DM_RSTP. */
|
||||||
switch (macro_id) {
|
dynamic_macro_stop_recording();
|
||||||
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;
|
return false;
|
||||||
#ifdef DYNAMIC_MACRO_NO_NESTING
|
#ifdef DYNAMIC_MACRO_NO_NESTING
|
||||||
|
|
|
@ -39,3 +39,4 @@ void dynamic_macro_record_start_user(int8_t direction);
|
||||||
void dynamic_macro_play_user(int8_t direction);
|
void dynamic_macro_play_user(int8_t direction);
|
||||||
void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record);
|
void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record);
|
||||||
void dynamic_macro_record_end_user(int8_t direction);
|
void dynamic_macro_record_end_user(int8_t direction);
|
||||||
|
void dynamic_macro_stop_recording(void);
|
||||||
|
|
Loading…
Reference in a new issue