Merge pull request #20 from gedankenexperimenter/bug/scan-order

Fixed scan order bug
pull/365/head
Gergely Nagy 7 years ago committed by GitHub
commit bcf3cf191b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,8 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
return MACRO_NONE; return MACRO_NONE;
} }
MacroKeyEvent Macros_::active_macros[];
byte Macros_::active_macro_count;
byte Macros_::row, Macros_::col; byte Macros_::row, Macros_::col;
void playMacroKeyswitchEvent(Key key, uint8_t flags) { void playMacroKeyswitchEvent(Key key, uint8_t flags) {
@ -181,16 +183,34 @@ const macro_t *Macros_::type(const char *string) {
return MACRO_NONE; return MACRO_NONE;
} }
static Key handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) { Key Macros_::handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (mappedKey.flags != (SYNTHETIC | IS_MACRO)) if (mappedKey.flags != (SYNTHETIC | IS_MACRO))
return mappedKey; return mappedKey;
Macros_::row = row; byte key_id = (row * COLS) + col;
Macros_::col = col; addActiveMacroKey(mappedKey.keyCode, key_id, keyState);
const macro_t *m = macroAction(mappedKey.keyCode, keyState); return Key_NoKey;
}
void Macros_::loopHook(bool post_clear) {
if (post_clear) {
active_macro_count = 0;
return;
}
for (byte i = 0; i < active_macro_count; ++i) {
if (active_macros[i].key_id == 0xFF) {
// i.e. UNKNOWN_KEYSWITCH_LOCATION
row = 0xFF;
col = 0xFF;
} else {
row = active_macros[i].key_id / COLS;
col = active_macros[i].key_id % COLS;
}
const macro_t *m = macroAction(active_macros[i].key_code,
active_macros[i].key_state);
Macros.play(m); Macros.play(m);
return Key_NoKey; }
} }
Macros_::Macros_(void) { Macros_::Macros_(void) {
@ -198,7 +218,9 @@ Macros_::Macros_(void) {
void void
Macros_::begin(void) { Macros_::begin(void) {
active_macro_count = 0;
Kaleidoscope.useEventHandlerHook(handleMacroEvent); Kaleidoscope.useEventHandlerHook(handleMacroEvent);
Kaleidoscope.useLoopHook(loopHook);
} }
Macros_ Macros; Macros_ Macros;

@ -7,12 +7,37 @@
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState); const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState);
#if !defined(MAX_CONCURRENT_MACROS)
#define MAX_CONCURRENT_MACROS 8
#endif
struct MacroKeyEvent {
byte key_code;
byte key_id;
byte key_state;
};
class Macros_ : public KaleidoscopePlugin { class Macros_ : public KaleidoscopePlugin {
public: public:
Macros_(void); Macros_(void);
void begin(void) final; void begin(void) final;
static MacroKeyEvent active_macros[MAX_CONCURRENT_MACROS];
static byte active_macro_count;
static void addActiveMacroKey(byte key_code, byte key_id, byte key_state) {
// If we've got too many active macros, give up:
if (active_macro_count >= MAX_CONCURRENT_MACROS) {
return;
}
active_macros[active_macro_count].key_code = key_code;
active_macros[active_macro_count].key_id = key_id;
active_macros[active_macro_count].key_state = key_state;
++active_macro_count;
}
static Key handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState);
static void loopHook(bool post_clear);
void play(const macro_t *macro_p); void play(const macro_t *macro_p);
/* What follows below, is a bit of template magic that allows us to use /* What follows below, is a bit of template magic that allows us to use

Loading…
Cancel
Save