astyle with current project style guidelines

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

@ -20,31 +20,31 @@
#include <Kaleidoscope-SpaceCadet.h> #include <Kaleidoscope-SpaceCadet.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,
Key_skip, Key_skip,
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,
Key_skip Key_skip
), ),
}; };
void setup () { void setup() {
Kaleidoscope.setup (); Kaleidoscope.setup();
USE_PLUGINS (&SpaceCadetShift); USE_PLUGINS(&SpaceCadetShift);
} }
void loop () { void loop() {
Kaleidoscope.loop (); Kaleidoscope.loop();
} }

@ -25,80 +25,80 @@ uint32_t SpaceCadetShift::startTime;
uint16_t SpaceCadetShift::timeOut = 1000; uint16_t SpaceCadetShift::timeOut = 1000;
Key SpaceCadetShift::leftParen, SpaceCadetShift::rightParen; Key SpaceCadetShift::leftParen, SpaceCadetShift::rightParen;
SpaceCadetShift::SpaceCadetShift () { SpaceCadetShift::SpaceCadetShift() {
leftParen.raw = Key_9.raw; leftParen.raw = Key_9.raw;
rightParen.raw = Key_0.raw; rightParen.raw = Key_0.raw;
} }
void void
SpaceCadetShift::begin () { SpaceCadetShift::begin() {
event_handler_hook_use (this->eventHandlerHook); event_handler_hook_use(this->eventHandlerHook);
} }
void void
SpaceCadetShift::configure (Key left, Key right) { SpaceCadetShift::configure(Key left, Key right) {
leftParen = left; leftParen = left;
rightParen = right; rightParen = right;
} }
Key Key
SpaceCadetShift::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { SpaceCadetShift::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
// If nothing happened, bail out fast. // If nothing happened, bail out fast.
if (!key_is_pressed (keyState) && !key_was_pressed (keyState)) { if (!key_is_pressed(keyState) && !key_was_pressed(keyState)) {
return mappedKey; return mappedKey;
} }
// If a key has been just toggled on... // If a key has been just toggled on...
if (key_toggled_on (keyState)) { if (key_toggled_on(keyState)) {
if (mappedKey.raw == Key_LeftShift.raw) { // if it is LShift, remember it if (mappedKey.raw == Key_LeftShift.raw) { // if it is LShift, remember it
bitWrite (parenNeeded, 0, 1); bitWrite(parenNeeded, 0, 1);
startTime = millis (); startTime = millis();
} else if (mappedKey.raw == Key_RightShift.raw) { // if it is RShift, remember it } else if (mappedKey.raw == Key_RightShift.raw) { // if it is RShift, remember it
bitWrite (parenNeeded, 1, 1); bitWrite(parenNeeded, 1, 1);
startTime = millis (); startTime = millis();
} else { // if it is something else, we do not need a paren at the end. } else { // if it is something else, we do not need a paren at the end.
parenNeeded = 0; parenNeeded = 0;
startTime = 0; startTime = 0;
}
// this is all we need to do on keypress, let the next handler do its thing too.
return mappedKey;
} }
// if the state is empty, that means that either the shifts weren't pressed, // this is all we need to do on keypress, let the next handler do its thing too.
// or we used another key in the interim. in both cases, nothing special to do. return mappedKey;
if (!parenNeeded) }
return mappedKey;
// if we timed out, that means we need to keep pressing shift, but won't // if the state is empty, that means that either the shifts weren't pressed,
// need the parens in the end. // or we used another key in the interim. in both cases, nothing special to do.
if ((millis () - startTime) >= timeOut) { if (!parenNeeded)
parenNeeded = 0; return mappedKey;
return mappedKey;
}
// if we have a state, but the key in question is not either of the shifts, // if we timed out, that means we need to keep pressing shift, but won't
// return. This can happen when another key is released, and that should not // need the parens in the end.
// interrupt us. if ((millis() - startTime) >= timeOut) {
if (mappedKey.raw != Key_LeftShift.raw && parenNeeded = 0;
mappedKey.raw != Key_RightShift.raw) return mappedKey;
return mappedKey; }
// if a key toggled off (and that must be one of the shifts at this point),
// send the parens too (if we were interrupted, we bailed out earlier).
if (key_toggled_off (keyState)) {
Key paren = leftParen;
if (bitRead (parenNeeded, 1))
paren = rightParen;
handle_keyswitch_event (mappedKey, row, col, IS_PRESSED | INJECTED);
handle_keyswitch_event (paren, row, col, IS_PRESSED | INJECTED);
Keyboard.sendReport ();
parenNeeded = 0;
}
// if we have a state, but the key in question is not either of the shifts,
// return. This can happen when another key is released, and that should not
// interrupt us.
if (mappedKey.raw != Key_LeftShift.raw &&
mappedKey.raw != Key_RightShift.raw)
return mappedKey; return mappedKey;
// if a key toggled off (and that must be one of the shifts at this point),
// send the parens too (if we were interrupted, we bailed out earlier).
if (key_toggled_off(keyState)) {
Key paren = leftParen;
if (bitRead(parenNeeded, 1))
paren = rightParen;
handle_keyswitch_event(mappedKey, row, col, IS_PRESSED | INJECTED);
handle_keyswitch_event(paren, row, col, IS_PRESSED | INJECTED);
Keyboard.sendReport();
parenNeeded = 0;
}
return mappedKey;
} }
}; };

@ -22,20 +22,20 @@
namespace KaleidoscopePlugins { namespace KaleidoscopePlugins {
class SpaceCadetShift : public KaleidoscopePlugin { class SpaceCadetShift : public KaleidoscopePlugin {
public: public:
SpaceCadetShift (void); SpaceCadetShift(void);
void begin (void) final; void begin(void) final;
static void configure (Key left, Key right); static void configure(Key left, Key right);
static uint16_t timeOut; static uint16_t timeOut;
private: private:
static uint8_t parenNeeded; static uint8_t parenNeeded;
static uint32_t startTime; static uint32_t startTime;
static Key leftParen, rightParen; static Key leftParen, rightParen;
static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState);
}; };
}; };

Loading…
Cancel
Save