Merge pull request #5 from keyboardio/f/new-step-types

New step types
pull/365/head
Jesse Vincent 8 years ago committed by GitHub
commit 6c8dd7ef04

@ -7,10 +7,25 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
byte Macros_::row, Macros_::col; byte Macros_::row, Macros_::col;
static void readKeyCodeAndPlay (const macro_t *macro_p, uint8_t flags, uint8_t keyStates) {
Key key;
key.flags = flags;
key.keyCode = pgm_read_byte(macro_p++);
if (keyStates & IS_PRESSED) {
handle_key_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
Keyboard.sendReport();
}
if (keyStates & WAS_PRESSED) {
handle_key_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
Keyboard.sendReport();
}
}
void Macros_::play(const macro_t *macro_p) { void Macros_::play(const macro_t *macro_p) {
macro_t macro = END; macro_t macro = END;
uint8_t interval = 0; uint8_t interval = 0;
Key key; uint8_t flags;
if (!macro_p) if (!macro_p)
return; return;
@ -26,17 +41,28 @@ void Macros_::play(const macro_t *macro_p) {
break; break;
} }
case MACRO_ACTION_STEP_KEYDOWN: case MACRO_ACTION_STEP_KEYDOWN:
key.flags = pgm_read_byte(macro_p++); flags = pgm_read_byte(macro_p++);
key.keyCode = pgm_read_byte(macro_p++); readKeyCodeAndPlay (macro_p++, flags, IS_PRESSED);
handle_key_event(key, 255, 255, IS_PRESSED | INJECTED);
Keyboard.sendReport();
break; break;
case MACRO_ACTION_STEP_KEYUP: case MACRO_ACTION_STEP_KEYUP:
key.flags = pgm_read_byte(macro_p++); flags = pgm_read_byte(macro_p++);
key.keyCode = pgm_read_byte(macro_p++); readKeyCodeAndPlay (macro_p++, flags, WAS_PRESSED);
handle_key_event(key, 255, 255, WAS_PRESSED | INJECTED);
Keyboard.sendReport();
break; break;
case MACRO_ACTION_STEP_TAP:
flags = pgm_read_byte(macro_p++);
readKeyCodeAndPlay (macro_p++, flags, IS_PRESSED | WAS_PRESSED);
break;
case MACRO_ACTION_STEP_KEYCODEDOWN:
readKeyCodeAndPlay (macro_p++, 0, IS_PRESSED);
break;
case MACRO_ACTION_STEP_KEYCODEUP:
readKeyCodeAndPlay (macro_p++, 0, WAS_PRESSED);
break;
case MACRO_ACTION_STEP_TAPCODE:
readKeyCodeAndPlay (macro_p++, 0, IS_PRESSED | WAS_PRESSED);
break;
case END: case END:
default: default:
return; return;

@ -5,8 +5,14 @@ typedef enum {
MACRO_ACTION_STEP_INTERVAL, MACRO_ACTION_STEP_INTERVAL,
MACRO_ACTION_STEP_WAIT, MACRO_ACTION_STEP_WAIT,
MACRO_ACTION_STEP_KEYDOWN, MACRO_ACTION_STEP_KEYDOWN,
MACRO_ACTION_STEP_KEYUP, MACRO_ACTION_STEP_KEYUP,
MACRO_ACTION_STEP_TAP,
MACRO_ACTION_STEP_KEYCODEDOWN,
MACRO_ACTION_STEP_KEYCODEUP,
MACRO_ACTION_STEP_TAPCODE,
} MacroActionStepType; } MacroActionStepType;
typedef uint8_t macro_t; typedef uint8_t macro_t;
@ -17,10 +23,16 @@ typedef uint8_t macro_t;
#define I(n) MACRO_ACTION_STEP_INTERVAL, n #define I(n) MACRO_ACTION_STEP_INTERVAL, n
#define W(n) MACRO_ACTION_STEP_WAIT, n #define W(n) MACRO_ACTION_STEP_WAIT, n
#define Dr(k) MACRO_ACTION_STEP_KEYDOWN, (k).flags, (k).keyCode #define Dr(k) MACRO_ACTION_STEP_KEYDOWN, (k).flags, (k).keyCode
#define D(k) Dr(Key_ ## k) #define D(k) Dr(Key_ ## k)
#define Ur(k) MACRO_ACTION_STEP_KEYUP, (k).flags, (k).keyCode #define Ur(k) MACRO_ACTION_STEP_KEYUP, (k).flags, (k).keyCode
#define U(k) Ur(Key_ ## k) #define U(k) Ur(Key_ ## k)
#define Tr(k) Dr(k), Ur(k) #define Tr(k) MACRO_ACTION_STEP_TAP, (k).flags, (k).keyCode
#define T(k) D(k), U(k) #define T(k) Tr(Key_ ## k)
#define Dc(k) MACRO_ACTION_STEP_KEYCODEDOWN, (Key_ ## k).keyCode
#define Uc(k) MACRO_ACTION_STEP_KEYCODEUP, (Key_ ## k).keyCode
#define Tc(k) MACRO_ACTION_STEP_TAPCODE, (Key_ ## k).keyCode
#define END MACRO_ACTION_END #define END MACRO_ACTION_END

Loading…
Cancel
Save