astyle with current project style guidelines

pull/365/head
Jesse Vincent 8 years ago
parent 7d6225f724
commit 1ef902c27e
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -2,94 +2,94 @@
__attribute__((weak))
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
return MACRO_NONE;
return MACRO_NONE;
}
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_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
Keyboard.sendReport();
}
if (keyStates & WAS_PRESSED) {
handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
Keyboard.sendReport();
}
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_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
Keyboard.sendReport();
}
if (keyStates & WAS_PRESSED) {
handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
Keyboard.sendReport();
}
}
void Macros_::play(const macro_t *macro_p) {
macro_t macro = END;
uint8_t interval = 0;
uint8_t flags;
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:
flags = pgm_read_byte(macro_p++);
readKeyCodeAndPlay (macro_p++, flags, IS_PRESSED);
break;
case MACRO_ACTION_STEP_KEYUP:
flags = pgm_read_byte(macro_p++);
readKeyCodeAndPlay (macro_p++, flags, WAS_PRESSED);
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:
default:
return;
}
delay(interval);
macro_t macro = END;
uint8_t interval = 0;
uint8_t flags;
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:
flags = pgm_read_byte(macro_p++);
readKeyCodeAndPlay(macro_p++, flags, IS_PRESSED);
break;
case MACRO_ACTION_STEP_KEYUP:
flags = pgm_read_byte(macro_p++);
readKeyCodeAndPlay(macro_p++, flags, WAS_PRESSED);
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:
default:
return;
}
delay(interval);
}
}
static Key handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (mappedKey.flags != (SYNTHETIC | IS_MACRO))
return mappedKey;
if (mappedKey.flags != (SYNTHETIC | IS_MACRO))
return mappedKey;
Macros_::row = row;
Macros_::col = col;
const macro_t *m = macroAction(mappedKey.keyCode, keyState);
Macros_::row = row;
Macros_::col = col;
const macro_t *m = macroAction(mappedKey.keyCode, keyState);
Macros.play(m);
return Key_NoKey;
Macros.play(m);
return Key_NoKey;
}
Macros_::Macros_ (void) {
Macros_::Macros_(void) {
}
void
Macros_::begin (void) {
event_handler_hook_use (handleMacroEvent);
Macros_::begin(void) {
event_handler_hook_use(handleMacroEvent);
}
Macros_ Macros;

@ -8,14 +8,14 @@
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState);
class Macros_ : public KaleidoscopePlugin {
public:
Macros_(void);
public:
Macros_(void);
virtual void begin(void) final;
virtual void begin(void) final;
void play(const macro_t *macro_p);
void play(const macro_t *macro_p);
static byte row, col;
static byte row, col;
};
extern Macros_ Macros;

@ -1,18 +1,18 @@
#pragma once
typedef enum {
MACRO_ACTION_END,
MACRO_ACTION_END,
MACRO_ACTION_STEP_INTERVAL,
MACRO_ACTION_STEP_WAIT,
MACRO_ACTION_STEP_INTERVAL,
MACRO_ACTION_STEP_WAIT,
MACRO_ACTION_STEP_KEYDOWN,
MACRO_ACTION_STEP_KEYUP,
MACRO_ACTION_STEP_TAP,
MACRO_ACTION_STEP_KEYDOWN,
MACRO_ACTION_STEP_KEYUP,
MACRO_ACTION_STEP_TAP,
MACRO_ACTION_STEP_KEYCODEDOWN,
MACRO_ACTION_STEP_KEYCODEUP,
MACRO_ACTION_STEP_TAPCODE,
MACRO_ACTION_STEP_KEYCODEDOWN,
MACRO_ACTION_STEP_KEYCODEUP,
MACRO_ACTION_STEP_TAPCODE,
} MacroActionStepType;
typedef uint8_t macro_t;

Loading…
Cancel
Save