astyle with current project style guidelines

pull/365/head
Jesse Vincent 7 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)) __attribute__((weak))
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
return MACRO_NONE; return MACRO_NONE;
} }
byte Macros_::row, Macros_::col; byte Macros_::row, Macros_::col;
static void readKeyCodeAndPlay (const macro_t *macro_p, uint8_t flags, uint8_t keyStates) { static void readKeyCodeAndPlay(const macro_t *macro_p, uint8_t flags, uint8_t keyStates) {
Key key; Key key;
key.flags = flags; key.flags = flags;
key.keyCode = pgm_read_byte(macro_p++); key.keyCode = pgm_read_byte(macro_p++);
if (keyStates & IS_PRESSED) { if (keyStates & IS_PRESSED) {
handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
Keyboard.sendReport(); Keyboard.sendReport();
} }
if (keyStates & WAS_PRESSED) { if (keyStates & WAS_PRESSED) {
handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
Keyboard.sendReport(); 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;
uint8_t flags; uint8_t flags;
if (!macro_p) if (!macro_p)
return; return;
while (true) { while (true) {
switch (macro = pgm_read_byte(macro_p++)) { switch (macro = pgm_read_byte(macro_p++)) {
case MACRO_ACTION_STEP_INTERVAL: case MACRO_ACTION_STEP_INTERVAL:
interval = pgm_read_byte(macro_p++); interval = pgm_read_byte(macro_p++);
break; break;
case MACRO_ACTION_STEP_WAIT: { case MACRO_ACTION_STEP_WAIT: {
uint8_t wait = pgm_read_byte(macro_p++); uint8_t wait = pgm_read_byte(macro_p++);
delay(wait); delay(wait);
break; 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);
} }
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) { static Key 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; Macros_::row = row;
Macros_::col = col; Macros_::col = col;
const macro_t *m = macroAction(mappedKey.keyCode, keyState); const macro_t *m = macroAction(mappedKey.keyCode, keyState);
Macros.play(m); Macros.play(m);
return Key_NoKey; return Key_NoKey;
} }
Macros_::Macros_ (void) { Macros_::Macros_(void) {
} }
void void
Macros_::begin (void) { Macros_::begin(void) {
event_handler_hook_use (handleMacroEvent); event_handler_hook_use(handleMacroEvent);
} }
Macros_ Macros; Macros_ Macros;

@ -8,14 +8,14 @@
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState); const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState);
class Macros_ : public KaleidoscopePlugin { class Macros_ : public KaleidoscopePlugin {
public: public:
Macros_(void); 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; extern Macros_ Macros;

@ -1,18 +1,18 @@
#pragma once #pragma once
typedef enum { typedef enum {
MACRO_ACTION_END, MACRO_ACTION_END,
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_TAP,
MACRO_ACTION_STEP_KEYCODEDOWN, MACRO_ACTION_STEP_KEYCODEDOWN,
MACRO_ACTION_STEP_KEYCODEUP, MACRO_ACTION_STEP_KEYCODEUP,
MACRO_ACTION_STEP_TAPCODE, MACRO_ACTION_STEP_TAPCODE,
} MacroActionStepType; } MacroActionStepType;
typedef uint8_t macro_t; typedef uint8_t macro_t;

Loading…
Cancel
Save