summaryrefslogtreecommitdiffstats
path: root/quantum/dynamic_macro.h
diff options
context:
space:
mode:
authorWojciech Siewierski <wojciech.siewierski@onet.pl>2017-05-04 22:55:35 +0200
committerWojciech Siewierski <wojciech.siewierski@onet.pl>2017-05-04 23:57:22 +0200
commit10a7cd7e5ae1affe226423dd94c6443f8cf64e22 (patch)
treef2bdfeb97955f71768e6b19868ba0bff6aec5a2e /quantum/dynamic_macro.h
parent8e94c9b4cba4cf3479154a11faacfa2bbad50098 (diff)
downloadqmk_firmware-10a7cd7e5ae1affe226423dd94c6443f8cf64e22.tar.gz
qmk_firmware-10a7cd7e5ae1affe226423dd94c6443f8cf64e22.tar.xz
dynamic_macro.h: Add debug logs
Diffstat (limited to 'quantum/dynamic_macro.h')
-rw-r--r--quantum/dynamic_macro.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/quantum/dynamic_macro.h b/quantum/dynamic_macro.h
index 6aae7d230..7dca30f07 100644
--- a/quantum/dynamic_macro.h
+++ b/quantum/dynamic_macro.h
@@ -53,6 +53,15 @@ void dynamic_macro_led_blink(void)
backlight_toggle();
}
+/* Convenience macros used for retrieving the debug info. All of them
+ * 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))
+
/**
* Start recording of the dynamic macro.
*
@@ -62,6 +71,8 @@ void dynamic_macro_led_blink(void)
void dynamic_macro_record_start(
keyrecord_t **macro_pointer, keyrecord_t *macro_buffer)
{
+ dprintln("dynamic macro recording: started");
+
dynamic_macro_led_blink();
clear_keyboard();
@@ -79,6 +90,8 @@ void dynamic_macro_record_start(
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;
clear_keyboard();
@@ -112,6 +125,7 @@ void dynamic_macro_record_key(
{
/* 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");
return;
}
@@ -124,6 +138,12 @@ void dynamic_macro_record_key(
} else {
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));
}
/**
@@ -143,9 +163,15 @@ void dynamic_macro_record_end(
*/
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));
+
*macro_end = macro_pointer;
}
@@ -264,4 +290,8 @@ bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record)
return true;
}
+#undef DYNAMIC_MACRO_CURRENT_SLOT
+#undef DYNAMIC_MACRO_CURRENT_LENGTH
+#undef DYNAMIC_MACRO_CURRENT_CAPACITY
+
#endif