Merge branch 'f/macros' of https://github.com/algernon/KeyboardioFirmware into algernon-f/macros

pull/62/head
Jesse Vincent 8 years ago
commit 24bd828b21

@ -5,6 +5,7 @@
#define DEBUG_SERIAL false
#include "Keyboardio-MouseKeys.h"
#include "Keyboardio-Macros.h"
#include "KeyboardioFirmware.h"
#include "generated/keymaps.h"
@ -39,6 +40,19 @@ static LEDChaseEffect chaseEffect;
static LEDNumlock numLockEffect (NUMPAD_KEYMAP);
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
if (macroIndex == 1 && key_toggled_on(keyState)) {
Serial.print("Keyboard.IO keyboard driver v0.00");
return MACRO(I(25),
D(LShift), T(M), U(LShift), T(O), T(D), T(E), T(L),
T(Space),
W(100),
T(0), T(1),
END);
}
return MACRO_NONE;
}
void setup() {
Keyboardio.setup(KEYMAP_SIZE);
}

@ -0,0 +1,10 @@
name=Keyboardio-Macros
version=0.0.1
author=Jesse Vincent
maintainer=Jesse Vincent <jesse@keyboard.io>
sentence=Macro keys for Keyboardio boards.
paragraph=...
category=Communication
url=https://github.com/keyboardio/KeyboardioFirmware
architectures=avr
dot_a_linkage=true

@ -0,0 +1,59 @@
#include "Keyboardio-Macros.h"
__attribute__((weak))
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
return MACRO_NONE;
}
void Macros_::play(const macro_t *macro_p) {
macro_t macro = END;
uint8_t interval = 0;
Key key;
if (!macro_p)
return;
while (true) {
switch (macro = pgm_read_byte(macro_p++)) {
case MACRO_ACTION_STEP_INTERVAL:
interval = pgm_read_byte(macro_p++);
break;
case MACRO_ACTION_STEP_WAIT: {
uint8_t wait = pgm_read_byte(macro_p++);
delay(wait);
break;
}
case MACRO_ACTION_STEP_KEYDOWN:
key.flags = pgm_read_byte(macro_p++);
key.rawKey = pgm_read_byte(macro_p++);
handle_key_event(key, 255, 255, IS_PRESSED | INJECTED);
Keyboard.sendReport();
break;
case MACRO_ACTION_STEP_KEYUP:
key.flags = pgm_read_byte(macro_p++);
key.rawKey = pgm_read_byte(macro_p++);
handle_key_event(key, 255, 255, WAS_PRESSED | INJECTED);
Keyboard.sendReport();
break;
case END:
default:
return;
}
delay(interval);
}
}
static bool handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (!(mappedKey.flags & (SYNTHETIC|IS_MACRO)) || (mappedKey.flags & IS_INTERNAL))
return false;
const macro_t *m = macroAction(mappedKey.rawKey, keyState);
Macros.play(m);
return true;
}
Macros_::Macros_ (void) {
event_handler_hook_add (handleMacroEvent);
}

@ -0,0 +1,17 @@
#pragma once
#include <KeyboardioFirmware.h>
#include "MacroKeyDefs.h"
#include "MacroSteps.h"
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState);
class Macros_ {
public:
Macros_(void);
void play(const macro_t *macro_p);
};
static Macros_ Macros;

@ -0,0 +1,15 @@
#pragma once
#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)

@ -0,0 +1,22 @@
#pragma once
typedef enum {
MACRO_ACTION_END,
MACRO_ACTION_STEP_INTERVAL,
MACRO_ACTION_STEP_WAIT,
MACRO_ACTION_STEP_KEYDOWN,
MACRO_ACTION_STEP_KEYUP,
} MacroActionStepType;
typedef uint8_t macro_t;
#define MACRO_NONE 0
#define MACRO(...) ({static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })
#define I(n) MACRO_ACTION_STEP_INTERVAL, n
#define W(n) MACRO_ACTION_STEP_WAIT, n
#define D(k) MACRO_ACTION_STEP_KEYDOWN, (Key_ ## k).flags, (Key_ ## k).rawKey
#define U(k) MACRO_ACTION_STEP_KEYUP, (Key_ ## k).flags, (Key_ ## k).rawKey
#define T(k) D(k), U(k)
#define END MACRO_ACTION_END

@ -22,7 +22,6 @@ typedef union {
#define SYNTHETIC B10000000
// 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_CONSUMER B00000100
#define IS_INTERNAL B00001000
@ -52,8 +51,6 @@ 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 Key_powerDown (Key) {KEY_FLAGS | SYNTHETIC|IS_SYSCTL,HID_SYSTEM_POWER_DOWN }
#define Key_sleep (Key) {KEY_FLAGS | SYNTHETIC|IS_SYSCTL,HID_SYSTEM_SLEEP }

@ -1,7 +1,9 @@
#include "key_events.h"
void handle_synthetic_key_event(Key mappedKey, uint8_t keyState) {
if (key_toggled_on(keyState)) {
if (!key_toggled_on(keyState))
return;
if (mappedKey.flags & IS_CONSUMER) {
ConsumerControl.press(mappedKey.rawKey);
} else if (mappedKey.flags & IS_INTERNAL) {
@ -10,12 +12,6 @@ void handle_synthetic_key_event(Key mappedKey, uint8_t keyState) {
}
} 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");
}
}
}
}
@ -56,6 +52,8 @@ bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t keyStat
handle_synthetic_key_event( mappedKey, keyState);
} else if (key_is_pressed(keyState)) {
press_key(mappedKey);
} else if (key_toggled_off(keyState) && (keyState & INJECTED)) {
release_key(mappedKey);
}
return true;
}
@ -80,6 +78,26 @@ void press_key(Key mappedKey) {
}
void release_key(Key mappedKey) {
if (mappedKey.flags & SHIFT_HELD) {
Keyboard.release(Key_LShift.rawKey);
}
if (mappedKey.flags & CTRL_HELD) {
Keyboard.release(Key_LCtrl.rawKey);
}
if (mappedKey.flags & LALT_HELD) {
Keyboard.release(Key_LAlt.rawKey);
}
if (mappedKey.flags & RALT_HELD) {
Keyboard.release(Key_RAlt.rawKey);
}
if (mappedKey.flags & GUI_HELD) {
Keyboard.release(Key_LGUI.rawKey);
}
Keyboard.release(mappedKey.rawKey);
}
void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.flags & SWITCH_TO_KEYMAP_MOMENTARY ) {
if (key_toggled_on(keyState)) {

@ -48,6 +48,7 @@ void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState);
// Internal use
void handle_synthetic_key_event( Key mappedKey, uint8_t keyState);
void press_key(Key mappedKey);
void release_key(Key mappedKey);
void handle_keymap_key_event(Key keymapEntry, uint8_t keyState);
bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t keyState);

Loading…
Cancel
Save