From 437a349288d34cc2c7f912d3f3d876120eef6524 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Fri, 26 May 2017 16:20:24 -0700 Subject: [PATCH] make astyle --- examples/TypingBreaks/TypingBreaks.ino | 36 ++--- src/Kaleidoscope/TypingBreaks.cpp | 192 ++++++++++++------------- src/Kaleidoscope/TypingBreaks.h | 14 +- 3 files changed, 121 insertions(+), 121 deletions(-) diff --git a/examples/TypingBreaks/TypingBreaks.ino b/examples/TypingBreaks/TypingBreaks.ino index bf75347b..9a3e4515 100644 --- a/examples/TypingBreaks/TypingBreaks.ino +++ b/examples/TypingBreaks/TypingBreaks.ino @@ -20,31 +20,31 @@ #include const Key keymaps[][ROWS][COLS] PROGMEM = { - [0] = KEYMAP_STACKED - ( - 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_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, + [0] = KEYMAP_STACKED + ( + 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_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_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, - Key_skip, + Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, + 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_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_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_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_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, - Key_skip - ), + Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, + Key_skip + ), }; void setup () { - Kaleidoscope.setup (); - USE_PLUGINS (&TypingBreaks); + Kaleidoscope.setup (); + USE_PLUGINS (&TypingBreaks); } void loop () { - Kaleidoscope.loop (); + Kaleidoscope.loop (); } diff --git a/src/Kaleidoscope/TypingBreaks.cpp b/src/Kaleidoscope/TypingBreaks.cpp index 356caf9f..922a85ad 100644 --- a/src/Kaleidoscope/TypingBreaks.cpp +++ b/src/Kaleidoscope/TypingBreaks.cpp @@ -21,99 +21,99 @@ #include namespace KaleidoscopePlugins { - TypingBreaks::settings_t TypingBreaks::settings = { +TypingBreaks::settings_t TypingBreaks::settings = { .idleTimeLimit = 10000, // 10s .lockTimeOut = 2700000, // 45m .lockLength = 300000, // 5m .leftHandMaxKeys = 0, .rightHandMaxKeys = 0 - }; +}; - uint32_t TypingBreaks::sessionStartTime; - uint32_t TypingBreaks::lastKeyTime; - uint32_t TypingBreaks::lockStartTime; - uint16_t TypingBreaks::leftHandKeys; - uint16_t TypingBreaks::rightHandKeys; - uint16_t TypingBreaks::settingsBase; +uint32_t TypingBreaks::sessionStartTime; +uint32_t TypingBreaks::lastKeyTime; +uint32_t TypingBreaks::lockStartTime; +uint16_t TypingBreaks::leftHandKeys; +uint16_t TypingBreaks::rightHandKeys; +uint16_t TypingBreaks::settingsBase; - TypingBreaks::TypingBreaks (void) { - } +TypingBreaks::TypingBreaks (void) { +} - void - TypingBreaks::begin (void) { +void +TypingBreaks::begin (void) { event_handler_hook_use (this->eventHandlerHook); - } +} - Key - TypingBreaks::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { +Key +TypingBreaks::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { // If we are locked, and didn't time out yet, no key has to be pressed. if (lockStartTime && (millis () - lockStartTime <= settings.lockLength)) - return Key_NoKey; + return Key_NoKey; // If we are locked... if (lockStartTime) { - // ...and the lock has not expired yet - if (millis () - lockStartTime <= settings.lockLength) - return Key_NoKey; // remain locked + // ...and the lock has not expired yet + if (millis () - lockStartTime <= settings.lockLength) + return Key_NoKey; // remain locked - // ...otherwise clear the lock - lockStartTime = 0; - leftHandKeys = rightHandKeys = 0; - sessionStartTime = millis (); + // ...otherwise clear the lock + lockStartTime = 0; + leftHandKeys = rightHandKeys = 0; + sessionStartTime = millis (); - TypingBreak (false); + TypingBreak (false); } // Any other case, we are not locked yet! (or we just unlocked) // Are we still in the same session? if (lastKeyTime && (millis () - lastKeyTime) >= settings.idleTimeLimit) { - // No, we are not. Clear timers and start over. - lockStartTime = 0; - leftHandKeys = rightHandKeys = 0; - sessionStartTime = millis (); + // No, we are not. Clear timers and start over. + lockStartTime = 0; + leftHandKeys = rightHandKeys = 0; + sessionStartTime = millis (); } // If we have a limit on the left hand, and we reached it, lock up! if (settings.leftHandMaxKeys && leftHandKeys >= settings.leftHandMaxKeys) { - lockStartTime = millis (); - TypingBreak (true); - return Key_NoKey; + lockStartTime = millis (); + TypingBreak (true); + return Key_NoKey; } // If we have a limit on the right hand, and we reached it, lock up! if (settings.rightHandMaxKeys && rightHandKeys >= settings.rightHandMaxKeys) { - lockStartTime = millis (); - TypingBreak (true); - return Key_NoKey; - } - - if (settings.lockTimeOut) { - // Is the session longer than lockTimeOut? - if (millis () - sessionStartTime >= settings.lockTimeOut) { - // Yeah, it is. lockStartTime = millis (); TypingBreak (true); return Key_NoKey; - } + } + + if (settings.lockTimeOut) { + // Is the session longer than lockTimeOut? + if (millis () - sessionStartTime >= settings.lockTimeOut) { + // Yeah, it is. + lockStartTime = millis (); + TypingBreak (true); + return Key_NoKey; + } } // So it seems we did not need to lock up. In this case, lets increase key // counters if need be. if (key_toggled_on (keyState)) { - if (col <= COLS / 2) - leftHandKeys++; - else - rightHandKeys++; - lastKeyTime = millis (); + if (col <= COLS / 2) + leftHandKeys++; + else + rightHandKeys++; + lastKeyTime = millis (); } return mappedKey; - } +} - void - TypingBreaks::enableEEPROM (void) { +void +TypingBreaks::enableEEPROM (void) { settingsBase = ::EEPROMSettings.requestSlice (sizeof (settings)); // If idleTime is max, assume that EEPROM is uninitialized, and store the @@ -121,78 +121,78 @@ namespace KaleidoscopePlugins { uint32_t idleTime; EEPROM.get (settingsBase, idleTime); if (idleTime == 0xffffffff) { - EEPROM.put (settingsBase, settings); + EEPROM.put (settingsBase, settings); } EEPROM.get (settingsBase, settings); - } +} - bool - TypingBreaks::focusHook (const char *command) { +bool +TypingBreaks::focusHook (const char *command) { enum { - IDLE_TIME_LIMIT, - LOCK_TIMEOUT, - LOCK_LENGTH, - LEFT_MAX, - RIGHT_MAX, + IDLE_TIME_LIMIT, + LOCK_TIMEOUT, + LOCK_LENGTH, + LEFT_MAX, + RIGHT_MAX, } subCommand; if (strncmp_P (command, PSTR ("typingbreaks."), 13) != 0) - return false; + return false; if (strcmp_P (command + 13, PSTR ("idleTimeLimit")) == 0) - subCommand = IDLE_TIME_LIMIT; + subCommand = IDLE_TIME_LIMIT; else if (strcmp_P (command + 13, PSTR ("lockTimeOut")) == 0) - subCommand = LOCK_TIMEOUT; + subCommand = LOCK_TIMEOUT; else if (strcmp_P (command + 13, PSTR ("lockLength")) == 0) - subCommand = LOCK_LENGTH; + subCommand = LOCK_LENGTH; else if (strcmp_P (command + 13, PSTR ("leftMaxKeys")) == 0) - subCommand = LEFT_MAX; + subCommand = LEFT_MAX; else if (strcmp_P (command + 13, PSTR ("rightMaxKeys")) == 0) - subCommand = RIGHT_MAX; + subCommand = RIGHT_MAX; else - return false; + return false; switch (subCommand) { case IDLE_TIME_LIMIT: - if (Serial.peek () == '\n') { - Serial.println (settings.idleTimeLimit); - } else { - settings.idleTimeLimit = Serial.parseInt (); - } - break; + if (Serial.peek () == '\n') { + Serial.println (settings.idleTimeLimit); + } else { + settings.idleTimeLimit = Serial.parseInt (); + } + break; case LOCK_TIMEOUT: - if (Serial.peek () == '\n') { - Serial.println (settings.lockTimeOut); - } else { - settings.lockTimeOut = Serial.parseInt (); - } - break; + if (Serial.peek () == '\n') { + Serial.println (settings.lockTimeOut); + } else { + settings.lockTimeOut = Serial.parseInt (); + } + break; case LOCK_LENGTH: - if (Serial.peek () == '\n') { - Serial.println (settings.lockLength); - } else { - settings.lockLength = Serial.parseInt (); - } - break; + if (Serial.peek () == '\n') { + Serial.println (settings.lockLength); + } else { + settings.lockLength = Serial.parseInt (); + } + break; case LEFT_MAX: - if (Serial.peek () == '\n') { - Serial.println (settings.leftHandMaxKeys); - } else { - settings.leftHandMaxKeys = Serial.parseInt (); - } - break; + if (Serial.peek () == '\n') { + Serial.println (settings.leftHandMaxKeys); + } else { + settings.leftHandMaxKeys = Serial.parseInt (); + } + break; case RIGHT_MAX: - if (Serial.peek () == '\n') { - Serial.println (settings.rightHandMaxKeys); - } else { - settings.rightHandMaxKeys = Serial.parseInt (); - } - break; + if (Serial.peek () == '\n') { + Serial.println (settings.rightHandMaxKeys); + } else { + settings.rightHandMaxKeys = Serial.parseInt (); + } + break; } EEPROM.put (settingsBase, settings); return true; - } +} }; KaleidoscopePlugins::TypingBreaks TypingBreaks; diff --git a/src/Kaleidoscope/TypingBreaks.h b/src/Kaleidoscope/TypingBreaks.h index cea9133c..02dbdaf5 100644 --- a/src/Kaleidoscope/TypingBreaks.h +++ b/src/Kaleidoscope/TypingBreaks.h @@ -21,7 +21,7 @@ #include namespace KaleidoscopePlugins { - class TypingBreaks : public KaleidoscopePlugin { +class TypingBreaks : public KaleidoscopePlugin { public: TypingBreaks (void); @@ -31,11 +31,11 @@ namespace KaleidoscopePlugins { static bool focusHook (const char *command); typedef struct settings_t { - uint32_t idleTimeLimit; - uint32_t lockTimeOut; - uint32_t lockLength; - uint16_t leftHandMaxKeys; - uint16_t rightHandMaxKeys; + uint32_t idleTimeLimit; + uint32_t lockTimeOut; + uint32_t lockLength; + uint16_t leftHandMaxKeys; + uint16_t rightHandMaxKeys; } settings_t; static settings_t settings; @@ -50,7 +50,7 @@ namespace KaleidoscopePlugins { static uint16_t settingsBase; static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); - }; +}; }; extern KaleidoscopePlugins::TypingBreaks TypingBreaks;