make astyle

pull/389/head
Jesse Vincent 8 years ago
parent ae3b49d01e
commit ad09f54c0d
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -20,44 +20,44 @@
#include <Kaleidoscope-TapDance.h> #include <Kaleidoscope-TapDance.h>
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (
Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
TD(0), TD(0),
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
TD(1) TD(1)
), ),
}; };
static void tapDanceEsc (uint8_t tapDanceIndex, uint8_t tapCount, KaleidoscopePlugins::TapDance::ActionType tapDanceAction) { static void tapDanceEsc (uint8_t tapDanceIndex, uint8_t tapCount, KaleidoscopePlugins::TapDance::ActionType tapDanceAction) {
tapDanceActionKeys (tapCount, tapDanceAction, Key_Escape, Key_Tab); tapDanceActionKeys (tapCount, tapDanceAction, Key_Escape, Key_Tab);
} }
void tapDanceAction (uint8_t tapDanceIndex, byte row, byte col, uint8_t tapCount, KaleidoscopePlugins::TapDance::ActionType tapDanceAction) { void tapDanceAction (uint8_t tapDanceIndex, byte row, byte col, uint8_t tapCount, KaleidoscopePlugins::TapDance::ActionType tapDanceAction) {
switch (tapDanceIndex) { switch (tapDanceIndex) {
case 0: case 0:
return tapDanceActionKeys (tapCount, tapDanceAction, Key_Tab, Key_Escape); return tapDanceActionKeys (tapCount, tapDanceAction, Key_Tab, Key_Escape);
case 1: case 1:
return tapDanceEsc (tapDanceIndex, tapCount, tapDanceAction); return tapDanceEsc (tapDanceIndex, tapCount, tapDanceAction);
} }
} }
void setup () { void setup () {
Kaleidoscope.setup (KEYMAP_SIZE); Kaleidoscope.setup (KEYMAP_SIZE);
Kaleidoscope.use (&TapDance, NULL); Kaleidoscope.use (&TapDance, NULL);
} }
void loop () { void loop () {
Kaleidoscope.loop (); Kaleidoscope.loop ();
} }

@ -21,28 +21,28 @@
using namespace KaleidoscopePlugins::Ranges; using namespace KaleidoscopePlugins::Ranges;
namespace KaleidoscopePlugins { namespace KaleidoscopePlugins {
// --- state --- // --- state ---
uint32_t TapDance::endTime; uint32_t TapDance::endTime;
uint16_t TapDance::timeOut = 200; uint16_t TapDance::timeOut = 200;
uint8_t TapDance::tapCount[16]; uint8_t TapDance::tapCount[16];
uint16_t TapDance::pressedState; uint16_t TapDance::pressedState;
uint16_t TapDance::triggeredState; uint16_t TapDance::triggeredState;
uint16_t TapDance::releaseNextState; uint16_t TapDance::releaseNextState;
Key TapDance::lastTapDanceKey; Key TapDance::lastTapDanceKey;
byte TapDance::lastTapDanceRow; byte TapDance::lastTapDanceRow;
byte TapDance::lastTapDanceCol; byte TapDance::lastTapDanceCol;
// --- helpers --- // --- helpers ---
#define isTapDance(k) (k.raw >= TD_FIRST && k.raw <= TD_LAST) #define isTapDance(k) (k.raw >= TD_FIRST && k.raw <= TD_LAST)
#define isInSeq(k) (lastTapDanceKey.raw == k.raw) #define isInSeq(k) (lastTapDanceKey.raw == k.raw)
#define stillHeld(idx) (tapCount[idx]) #define stillHeld(idx) (tapCount[idx])
#define isActive() (lastTapDanceKey.raw != Key_NoKey.raw) #define isActive() (lastTapDanceKey.raw != Key_NoKey.raw)
// --- actions --- // --- actions ---
void void
TapDance::interrupt (void) { TapDance::interrupt (void) {
uint8_t idx = lastTapDanceKey.raw - TD_FIRST; uint8_t idx = lastTapDanceKey.raw - TD_FIRST;
tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Interrupt); tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Interrupt);
@ -51,28 +51,28 @@ namespace KaleidoscopePlugins {
endTime = 0; endTime = 0;
if (bitRead (pressedState, idx)) if (bitRead (pressedState, idx))
return; return;
release (idx); release (idx);
} }
void void
TapDance::timeout (void) { TapDance::timeout (void) {
uint8_t idx = lastTapDanceKey.raw - TD_FIRST; uint8_t idx = lastTapDanceKey.raw - TD_FIRST;
tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Timeout); tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Timeout);
bitWrite (triggeredState, idx, 1); bitWrite (triggeredState, idx, 1);
if (bitRead (pressedState, idx)) if (bitRead (pressedState, idx))
return; return;
lastTapDanceKey.raw = Key_NoKey.raw; lastTapDanceKey.raw = Key_NoKey.raw;
release (idx); release (idx);
} }
Key Key
TapDance::release (uint8_t tapDanceIndex) { TapDance::release (uint8_t tapDanceIndex) {
endTime = 0; endTime = 0;
lastTapDanceKey.raw = Key_NoKey.raw; lastTapDanceKey.raw = Key_NoKey.raw;
@ -80,10 +80,10 @@ namespace KaleidoscopePlugins {
bitClear (triggeredState, tapDanceIndex); bitClear (triggeredState, tapDanceIndex);
bitWrite (releaseNextState, tapDanceIndex, 1); bitWrite (releaseNextState, tapDanceIndex, 1);
return Key_NoKey; return Key_NoKey;
} }
Key Key
TapDance::tap (void) { TapDance::tap (void) {
uint8_t idx = lastTapDanceKey.raw - TD_FIRST; uint8_t idx = lastTapDanceKey.raw - TD_FIRST;
tapCount[idx]++; tapCount[idx]++;
@ -92,101 +92,101 @@ namespace KaleidoscopePlugins {
tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Tap); tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Tap);
return Key_NoKey; return Key_NoKey;
} }
// --- api --- // --- api ---
TapDance::TapDance (void) { TapDance::TapDance (void) {
lastTapDanceKey.raw = Key_NoKey.raw; lastTapDanceKey.raw = Key_NoKey.raw;
} }
void void
TapDance::begin (void) { TapDance::begin (void) {
event_handler_hook_use (this->eventHandlerHook); event_handler_hook_use (this->eventHandlerHook);
loop_hook_use (this->loopHook); loop_hook_use (this->loopHook);
} }
void void
TapDance::actionKeys (uint8_t tapCount, ActionType tapDanceAction, uint8_t maxKeys, const Key tapKeys[]) { TapDance::actionKeys (uint8_t tapCount, ActionType tapDanceAction, uint8_t maxKeys, const Key tapKeys[]) {
if (tapCount > maxKeys) if (tapCount > maxKeys)
tapCount = maxKeys; tapCount = maxKeys;
Key key; Key key;
key.raw = pgm_read_word (&(tapKeys[tapCount - 1].raw)); key.raw = pgm_read_word (&(tapKeys[tapCount - 1].raw));
switch (tapDanceAction) { switch (tapDanceAction) {
case Tap: case Tap:
break; break;
case Interrupt: case Interrupt:
case Timeout: case Timeout:
handle_keyswitch_event (key, lastTapDanceRow, lastTapDanceCol, IS_PRESSED | INJECTED); handle_keyswitch_event (key, lastTapDanceRow, lastTapDanceCol, IS_PRESSED | INJECTED);
break; break;
case Hold: case Hold:
handle_keyswitch_event (key, lastTapDanceRow, lastTapDanceCol, IS_PRESSED | WAS_PRESSED | INJECTED); handle_keyswitch_event (key, lastTapDanceRow, lastTapDanceCol, IS_PRESSED | WAS_PRESSED | INJECTED);
break; break;
case Release: case Release:
Keyboard.sendReport (); Keyboard.sendReport ();
handle_keyswitch_event (key, lastTapDanceRow, lastTapDanceCol, WAS_PRESSED | INJECTED); handle_keyswitch_event (key, lastTapDanceRow, lastTapDanceCol, WAS_PRESSED | INJECTED);
break; break;
} }
} }
// --- hooks --- // --- hooks ---
Key Key
TapDance::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { TapDance::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
if (keyState & INJECTED) if (keyState & INJECTED)
return mappedKey; return mappedKey;
if (!key_is_pressed (keyState) && !key_was_pressed (keyState)) { if (!key_is_pressed (keyState) && !key_was_pressed (keyState)) {
if (isTapDance (mappedKey)) if (isTapDance (mappedKey))
return Key_NoKey; return Key_NoKey;
return mappedKey; return mappedKey;
} }
if (!isTapDance (mappedKey)) { if (!isTapDance (mappedKey)) {
if (!isActive ()) if (!isActive ())
return mappedKey; return mappedKey;
if (key_toggled_on (keyState)) if (key_toggled_on (keyState))
interrupt (); interrupt ();
return mappedKey; return mappedKey;
} }
uint8_t tapDanceIndex = mappedKey.raw - TD_FIRST; uint8_t tapDanceIndex = mappedKey.raw - TD_FIRST;
if (key_toggled_off (keyState)) if (key_toggled_off (keyState))
bitClear (pressedState, tapDanceIndex); bitClear (pressedState, tapDanceIndex);
if (!isInSeq (mappedKey)) { if (!isInSeq (mappedKey)) {
if (!isActive ()) { if (!isActive ()) {
if (bitRead (triggeredState, tapDanceIndex)) { if (bitRead (triggeredState, tapDanceIndex)) {
if (key_toggled_off (keyState)) if (key_toggled_off (keyState))
return release (tapDanceIndex); return release (tapDanceIndex);
return Key_NoKey; return Key_NoKey;
}
lastTapDanceKey.raw = mappedKey.raw;
lastTapDanceRow = row;
lastTapDanceCol = col;
return tap ();
} else {
if (key_toggled_off (keyState) && stillHeld (tapDanceIndex)) {
return release (tapDanceIndex);
}
if (!key_toggled_on (keyState))
return Key_NoKey;
interrupt ();
} }
lastTapDanceKey.raw = mappedKey.raw;
lastTapDanceRow = row;
lastTapDanceCol = col;
return tap ();
} else {
if (key_toggled_off (keyState) && stillHeld (tapDanceIndex)) {
return release (tapDanceIndex);
}
if (!key_toggled_on (keyState))
return Key_NoKey;
interrupt ();
}
} }
// in sequence // in sequence
if (key_toggled_off (keyState)) if (key_toggled_off (keyState))
return Key_NoKey; return Key_NoKey;
lastTapDanceKey.raw = mappedKey.raw; lastTapDanceKey.raw = mappedKey.raw;
lastTapDanceRow = row; lastTapDanceRow = row;
@ -194,34 +194,34 @@ namespace KaleidoscopePlugins {
bitSet (pressedState, tapDanceIndex); bitSet (pressedState, tapDanceIndex);
if (key_toggled_on (keyState)) if (key_toggled_on (keyState))
return tap (); return tap ();
if (bitRead (triggeredState, tapDanceIndex)) if (bitRead (triggeredState, tapDanceIndex))
tapDanceAction (tapDanceIndex, row, col, tapCount[tapDanceIndex], Hold); tapDanceAction (tapDanceIndex, row, col, tapCount[tapDanceIndex], Hold);
return Key_NoKey; return Key_NoKey;
} }
void void
TapDance::loopHook (bool postClear) { TapDance::loopHook (bool postClear) {
if (!postClear) if (!postClear)
return; return;
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
if (!bitRead (releaseNextState, i)) if (!bitRead (releaseNextState, i))
continue; continue;
tapDanceAction (i, lastTapDanceRow, lastTapDanceCol, tapCount[i], Release); tapDanceAction (i, lastTapDanceRow, lastTapDanceCol, tapCount[i], Release);
tapCount[i] = 0; tapCount[i] = 0;
bitClear (releaseNextState, i); bitClear (releaseNextState, i);
} }
if (!isActive ()) if (!isActive ())
return; return;
if (endTime && millis () > endTime) if (endTime && millis () > endTime)
timeout(); timeout();
} }
}; };
__attribute__((weak)) __attribute__((weak))

@ -30,14 +30,14 @@
}) })
namespace KaleidoscopePlugins { namespace KaleidoscopePlugins {
class TapDance : public KaleidoscopePlugin { class TapDance : public KaleidoscopePlugin {
public: public:
typedef enum { typedef enum {
Tap, Tap,
Hold, Hold,
Interrupt, Interrupt,
Timeout, Timeout,
Release, Release,
} ActionType; } ActionType;
TapDance (void); TapDance (void);
@ -64,7 +64,7 @@ namespace KaleidoscopePlugins {
static void interrupt (void); static void interrupt (void);
static void timeout (void); static void timeout (void);
static Key release (uint8_t tapDanceIndex); static Key release (uint8_t tapDanceIndex);
}; };
}; };
void tapDanceAction (uint8_t tapDanceIndex, byte row, byte col, uint8_t tapCount, KaleidoscopePlugins::TapDance::ActionType tapDanceAction); void tapDanceAction (uint8_t tapDanceIndex, byte row, byte col, uint8_t tapCount, KaleidoscopePlugins::TapDance::ActionType tapDanceAction);

Loading…
Cancel
Save