Merge branch 'f/macros' of https://github.com/algernon/KeyboardioFirmware into algernon-f/macros
commit
24bd828b21
@ -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
|
Loading…
Reference in new issue