Move all macro handling into separate files

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

@ -0,0 +1,21 @@
#include "Macros.h"
#include "hooks.h"
__attribute__((weak))
void
macroAction(uint8_t macroIndex, uint8_t keyState) {
}
static bool handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (!(mappedKey.flags & (SYNTHETIC|IS_MACRO)))
return false;
macroAction(mappedKey.rawKey, keyState);
return true;
}
Macros_::Macros_ (void) {
event_handler_hook_add (handleMacroEvent);
}
Macros_ Macros;

@ -0,0 +1,27 @@
#pragma once
#include <Arduino.h>
#include "key_defs.h"
#define IS_MACRO B00000001
#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)
void macroAction(uint8_t macroIndex, uint8_t keyState);
class Macros_ {
public:
Macros_(void);
};
extern Macros_ Macros;

@ -22,7 +22,6 @@ typedef union {
#define SYNTHETIC B10000000 #define SYNTHETIC B10000000
// we assert that synthetic keys can never have keys held, so we reuse the _HELD bits // we assert that synthetic keys can never have keys held, so we reuse the _HELD bits
#define IS_MACRO B00000001
#define IS_SYSCTL B00000010 #define IS_SYSCTL B00000010
#define IS_CONSUMER B00000100 #define IS_CONSUMER B00000100
#define IS_INTERNAL B00001000 #define IS_INTERNAL B00001000
@ -52,18 +51,6 @@ typedef union {
#define Key_NoKey (Key){ KEY_FLAGS,0 } #define Key_NoKey (Key){ KEY_FLAGS,0 }
#define Key_skip (Key){ KEY_FLAGS,0 } #define Key_skip (Key){ KEY_FLAGS,0 }
#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 } #define Key_powerDown (Key) {KEY_FLAGS | SYNTHETIC|IS_SYSCTL,HID_SYSTEM_POWER_DOWN }
#define Key_sleep (Key) {KEY_FLAGS | SYNTHETIC|IS_SYSCTL,HID_SYSTEM_SLEEP } #define Key_sleep (Key) {KEY_FLAGS | SYNTHETIC|IS_SYSCTL,HID_SYSTEM_SLEEP }

@ -1,16 +1,6 @@
#include "key_events.h" #include "key_events.h"
__attribute__((weak))
void
macroAction(uint8_t macroIndex, uint8_t keyState) {
}
void handle_synthetic_key_event(Key mappedKey, uint8_t keyState) { void handle_synthetic_key_event(Key mappedKey, uint8_t keyState) {
if (mappedKey.flags & IS_MACRO) {
macroAction(mappedKey.rawKey, keyState);
return;
}
if (!key_toggled_on(keyState)) if (!key_toggled_on(keyState))
return; return;

@ -8,6 +8,7 @@
#include "Storage.h" #include "Storage.h"
#include "keymap_metadata.h" #include "keymap_metadata.h"
#include "hooks.h" #include "hooks.h"
#include "Macros.h"
//static const Key keymaps[KEYMAPS][ROWS][COLS]; //static const Key keymaps[KEYMAPS][ROWS][COLS];
extern uint8_t primary_keymap; extern uint8_t primary_keymap;
@ -45,8 +46,6 @@ extern const Key keymaps[][ROWS][COLS];
*/ */
void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState); void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState);
void macroAction(uint8_t macroIndex, uint8_t keyState);
// Internal use // Internal use
void handle_synthetic_key_event( Key mappedKey, uint8_t keyState); void handle_synthetic_key_event( Key mappedKey, uint8_t keyState);
void press_key(Key mappedKey); void press_key(Key mappedKey);

Loading…
Cancel
Save