Use an overridable macroAction function for macro actions

Instead of hardcoding the macro actions into the core firmware, use a
`macroAction` function that is marked weak. This makes it possible to override
the function from Sketches, and implement the handlers there.

While there, also made sure that the `macroAction` is always called, with
`keyState` argument appropriately set. With this, macro actions can trigger on
keyup, or while held, or anytime the implementor wants, not just on keypress.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/58/head
Gergely Nagy 8 years ago
parent 95b2b4ea4f
commit 8b3b321c0e

@ -39,6 +39,12 @@ static LEDChaseEffect chaseEffect;
static LEDNumlock numLockEffect (NUMPAD_KEYMAP);
void macroAction(uint8_t macroIndex, uint8_t keyState) {
if (macroIndex == 1 && key_toggled_on(keyState)) {
Serial.print("Keyboard.IO keyboard driver v0.00");
}
}
void setup() {
Keyboardio.setup(KEYMAP_SIZE);
}

@ -52,7 +52,17 @@ typedef union {
#define Key_NoKey (Key){ KEY_FLAGS,0 }
#define Key_skip (Key){ KEY_FLAGS,0 }
#define Key_macroKey1 (Key){ KEY_FLAGS|SYNTHETIC|IS_MACRO, 1}
#define M(n) (Key){ KEY_FLAGS|SYNTHETIC|IS_MACRO, n}
#define Key_macroKey1 M(1)
#define Key_macroKey2 M(2)
#define Key_macroKey3 M(3)
#define Key_macroKey4 M(4)
#define Key_macroKey5 M(5)
#define Key_macroKey6 M(6)
#define Key_macroKey7 M(7)
#define Key_macroKey8 M(8)
#define Key_macroKey9 M(9)
#define Key_macroKey10 M(10)
#define Key_powerDown (Key) {KEY_FLAGS | SYNTHETIC|IS_SYSCTL,HID_SYSTEM_POWER_DOWN }

@ -1,21 +1,27 @@
#include "key_events.h"
__attribute__((weak))
void
macroAction(uint8_t macroIndex, uint8_t keyState) {
}
void handle_synthetic_key_event(Key mappedKey, uint8_t keyState) {
if (key_toggled_on(keyState)) {
if (mappedKey.flags & IS_CONSUMER) {
ConsumerControl.press(mappedKey.rawKey);
} else if (mappedKey.flags & IS_INTERNAL) {
if (mappedKey.rawKey == LED_TOGGLE) {
LEDControl.next_mode();
}
} else if (mappedKey.flags & IS_SYSCTL) {
SystemControl.press(mappedKey.rawKey);
} else if (mappedKey.flags & IS_MACRO) {
if (mappedKey.rawKey == 1) {
Serial.print("Keyboard.IO keyboard driver v0.00");
}
}
if (mappedKey.flags & IS_MACRO) {
macroAction(mappedKey.rawKey, keyState);
return;
}
if (!key_toggled_on(keyState))
return;
if (mappedKey.flags & IS_CONSUMER) {
ConsumerControl.press(mappedKey.rawKey);
} else if (mappedKey.flags & IS_INTERNAL) {
if (mappedKey.rawKey == LED_TOGGLE) {
LEDControl.next_mode();
}
} else if (mappedKey.flags & IS_SYSCTL) {
SystemControl.press(mappedKey.rawKey);
}
}

@ -45,6 +45,8 @@ extern const Key keymaps[][ROWS][COLS];
*/
void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState);
void macroAction(uint8_t macroIndex, uint8_t keyState);
// Internal use
void handle_synthetic_key_event( Key mappedKey, uint8_t keyState);
void press_key(Key mappedKey);

Loading…
Cancel
Save