From ace478116f4cf14b630a060fadaa91604f9789a1 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 28 Jan 2017 14:09:24 +0100 Subject: [PATCH 1/2] Make the macros aware of the row/col they were pressed at Signed-off-by: Gergely Nagy --- src/Keyboardio-Macros.cpp | 4 ++-- src/Keyboardio-Macros.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Keyboardio-Macros.cpp b/src/Keyboardio-Macros.cpp index bd4b4e4e..5518b333 100644 --- a/src/Keyboardio-Macros.cpp +++ b/src/Keyboardio-Macros.cpp @@ -1,7 +1,7 @@ #include "Keyboardio-Macros.h" __attribute__((weak)) -const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { +const macro_t *macroAction(uint8_t macroIndex, byte row, byte col, uint8_t keyState) { return MACRO_NONE; } @@ -51,7 +51,7 @@ static Key handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) if (!key_toggled_on(keyState)) return Key_NoKey; - const macro_t *m = macroAction(mappedKey.keyCode, keyState); + const macro_t *m = macroAction(mappedKey.keyCode, row, col, keyState); Macros.play(m); return Key_NoKey; diff --git a/src/Keyboardio-Macros.h b/src/Keyboardio-Macros.h index 172de9d7..7b24dd2f 100644 --- a/src/Keyboardio-Macros.h +++ b/src/Keyboardio-Macros.h @@ -5,7 +5,7 @@ #include "MacroKeyDefs.h" #include "MacroSteps.h" -const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState); +const macro_t *macroAction(uint8_t macroIndex, byte row, byte col, uint8_t keyState); class Macros_ : public KeyboardioPlugin { public: From 4d22c27e8db4dc290ca6c3ff7a40e45fbee831ee Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 29 Jan 2017 08:20:03 +0100 Subject: [PATCH 2/2] Use Macros.row/.col instead of macroAction params To make the signature of `macroAction` simple, the `row` and `col` properties are not passed in every time anymore, but they are available as `Macros.row` and `Macros.col`, respectively. This keeps the function simple, but still allows access to these properties for the rarer case of needing them. Signed-off-by: Gergely Nagy --- src/Keyboardio-Macros.cpp | 8 ++++++-- src/Keyboardio-Macros.h | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Keyboardio-Macros.cpp b/src/Keyboardio-Macros.cpp index 5518b333..eb408576 100644 --- a/src/Keyboardio-Macros.cpp +++ b/src/Keyboardio-Macros.cpp @@ -1,10 +1,12 @@ #include "Keyboardio-Macros.h" __attribute__((weak)) -const macro_t *macroAction(uint8_t macroIndex, byte row, byte col, uint8_t keyState) { +const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { return MACRO_NONE; } +byte Macros_::row, Macros_::col; + void Macros_::play(const macro_t *macro_p) { macro_t macro = END; uint8_t interval = 0; @@ -51,7 +53,9 @@ static Key handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) if (!key_toggled_on(keyState)) return Key_NoKey; - const macro_t *m = macroAction(mappedKey.keyCode, row, col, keyState); + Macros_::row = row; + Macros_::col = col; + const macro_t *m = macroAction(mappedKey.keyCode, keyState); Macros.play(m); return Key_NoKey; diff --git a/src/Keyboardio-Macros.h b/src/Keyboardio-Macros.h index 7b24dd2f..e5e8b723 100644 --- a/src/Keyboardio-Macros.h +++ b/src/Keyboardio-Macros.h @@ -5,7 +5,7 @@ #include "MacroKeyDefs.h" #include "MacroSteps.h" -const macro_t *macroAction(uint8_t macroIndex, byte row, byte col, uint8_t keyState); +const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState); class Macros_ : public KeyboardioPlugin { public: @@ -14,6 +14,8 @@ class Macros_ : public KeyboardioPlugin { virtual void begin(void) final; void play(const macro_t *macro_p); + + static byte row, col; }; extern Macros_ Macros;