make astyle

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

@ -21,8 +21,7 @@
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,
@ -36,15 +35,14 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
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 (&TypingBreaks); USE_PLUGINS(&TypingBreaks);
} }
void loop () { void loop() {
Kaleidoscope.loop (); Kaleidoscope.loop();
} }

@ -36,64 +36,64 @@ uint16_t TypingBreaks::leftHandKeys;
uint16_t TypingBreaks::rightHandKeys; uint16_t TypingBreaks::rightHandKeys;
uint16_t TypingBreaks::settingsBase; uint16_t TypingBreaks::settingsBase;
TypingBreaks::TypingBreaks (void) { TypingBreaks::TypingBreaks(void) {
} }
void void
TypingBreaks::begin (void) { TypingBreaks::begin(void) {
event_handler_hook_use (this->eventHandlerHook); event_handler_hook_use(this->eventHandlerHook);
} }
Key Key
TypingBreaks::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { 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 we are locked, and didn't time out yet, no key has to be pressed.
if (lockStartTime && (millis () - lockStartTime <= settings.lockLength)) if (lockStartTime && (millis() - lockStartTime <= settings.lockLength))
return Key_NoKey; return Key_NoKey;
// If we are locked... // If we are locked...
if (lockStartTime) { if (lockStartTime) {
// ...and the lock has not expired yet // ...and the lock has not expired yet
if (millis () - lockStartTime <= settings.lockLength) if (millis() - lockStartTime <= settings.lockLength)
return Key_NoKey; // remain locked return Key_NoKey; // remain locked
// ...otherwise clear the lock // ...otherwise clear the lock
lockStartTime = 0; lockStartTime = 0;
leftHandKeys = rightHandKeys = 0; leftHandKeys = rightHandKeys = 0;
sessionStartTime = millis (); sessionStartTime = millis();
TypingBreak (false); TypingBreak(false);
} }
// Any other case, we are not locked yet! (or we just unlocked) // Any other case, we are not locked yet! (or we just unlocked)
// Are we still in the same session? // Are we still in the same session?
if (lastKeyTime && (millis () - lastKeyTime) >= settings.idleTimeLimit) { if (lastKeyTime && (millis() - lastKeyTime) >= settings.idleTimeLimit) {
// No, we are not. Clear timers and start over. // No, we are not. Clear timers and start over.
lockStartTime = 0; lockStartTime = 0;
leftHandKeys = rightHandKeys = 0; leftHandKeys = rightHandKeys = 0;
sessionStartTime = millis (); sessionStartTime = millis();
} }
// If we have a limit on the left hand, and we reached it, lock up! // If we have a limit on the left hand, and we reached it, lock up!
if (settings.leftHandMaxKeys && leftHandKeys >= settings.leftHandMaxKeys) { if (settings.leftHandMaxKeys && leftHandKeys >= settings.leftHandMaxKeys) {
lockStartTime = millis (); lockStartTime = millis();
TypingBreak (true); TypingBreak(true);
return Key_NoKey; return Key_NoKey;
} }
// If we have a limit on the right hand, and we reached it, lock up! // If we have a limit on the right hand, and we reached it, lock up!
if (settings.rightHandMaxKeys && rightHandKeys >= settings.rightHandMaxKeys) { if (settings.rightHandMaxKeys && rightHandKeys >= settings.rightHandMaxKeys) {
lockStartTime = millis (); lockStartTime = millis();
TypingBreak (true); TypingBreak(true);
return Key_NoKey; return Key_NoKey;
} }
if (settings.lockTimeOut) { if (settings.lockTimeOut) {
// Is the session longer than lockTimeOut? // Is the session longer than lockTimeOut?
if (millis () - sessionStartTime >= settings.lockTimeOut) { if (millis() - sessionStartTime >= settings.lockTimeOut) {
// Yeah, it is. // Yeah, it is.
lockStartTime = millis (); lockStartTime = millis();
TypingBreak (true); TypingBreak(true);
return Key_NoKey; return Key_NoKey;
} }
} }
@ -101,34 +101,34 @@ TypingBreaks::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keySt
// So it seems we did not need to lock up. In this case, lets increase key // So it seems we did not need to lock up. In this case, lets increase key
// counters if need be. // counters if need be.
if (key_toggled_on (keyState)) { if (key_toggled_on(keyState)) {
if (col <= COLS / 2) if (col <= COLS / 2)
leftHandKeys++; leftHandKeys++;
else else
rightHandKeys++; rightHandKeys++;
lastKeyTime = millis (); lastKeyTime = millis();
} }
return mappedKey; return mappedKey;
} }
void void
TypingBreaks::enableEEPROM (void) { TypingBreaks::enableEEPROM(void) {
settingsBase = ::EEPROMSettings.requestSlice (sizeof (settings)); settingsBase = ::EEPROMSettings.requestSlice(sizeof(settings));
// If idleTime is max, assume that EEPROM is uninitialized, and store the // If idleTime is max, assume that EEPROM is uninitialized, and store the
// defaults. // defaults.
uint32_t idleTime; uint32_t idleTime;
EEPROM.get (settingsBase, idleTime); EEPROM.get(settingsBase, idleTime);
if (idleTime == 0xffffffff) { if (idleTime == 0xffffffff) {
EEPROM.put (settingsBase, settings); EEPROM.put(settingsBase, settings);
} }
EEPROM.get (settingsBase, settings); EEPROM.get(settingsBase, settings);
} }
bool bool
TypingBreaks::focusHook (const char *command) { TypingBreaks::focusHook(const char *command) {
enum { enum {
IDLE_TIME_LIMIT, IDLE_TIME_LIMIT,
LOCK_TIMEOUT, LOCK_TIMEOUT,
@ -137,67 +137,67 @@ TypingBreaks::focusHook (const char *command) {
RIGHT_MAX, RIGHT_MAX,
} subCommand; } subCommand;
if (strncmp_P (command, PSTR ("typingbreaks."), 13) != 0) if (strncmp_P(command, PSTR("typingbreaks."), 13) != 0)
return false; return false;
if (strcmp_P (command + 13, PSTR ("idleTimeLimit")) == 0) 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) else if (strcmp_P(command + 13, PSTR("lockTimeOut")) == 0)
subCommand = LOCK_TIMEOUT; subCommand = LOCK_TIMEOUT;
else if (strcmp_P (command + 13, PSTR ("lockLength")) == 0) else if (strcmp_P(command + 13, PSTR("lockLength")) == 0)
subCommand = LOCK_LENGTH; subCommand = LOCK_LENGTH;
else if (strcmp_P (command + 13, PSTR ("leftMaxKeys")) == 0) else if (strcmp_P(command + 13, PSTR("leftMaxKeys")) == 0)
subCommand = LEFT_MAX; subCommand = LEFT_MAX;
else if (strcmp_P (command + 13, PSTR ("rightMaxKeys")) == 0) else if (strcmp_P(command + 13, PSTR("rightMaxKeys")) == 0)
subCommand = RIGHT_MAX; subCommand = RIGHT_MAX;
else else
return false; return false;
switch (subCommand) { switch (subCommand) {
case IDLE_TIME_LIMIT: case IDLE_TIME_LIMIT:
if (Serial.peek () == '\n') { if (Serial.peek() == '\n') {
Serial.println (settings.idleTimeLimit); Serial.println(settings.idleTimeLimit);
} else { } else {
settings.idleTimeLimit = Serial.parseInt (); settings.idleTimeLimit = Serial.parseInt();
} }
break; break;
case LOCK_TIMEOUT: case LOCK_TIMEOUT:
if (Serial.peek () == '\n') { if (Serial.peek() == '\n') {
Serial.println (settings.lockTimeOut); Serial.println(settings.lockTimeOut);
} else { } else {
settings.lockTimeOut = Serial.parseInt (); settings.lockTimeOut = Serial.parseInt();
} }
break; break;
case LOCK_LENGTH: case LOCK_LENGTH:
if (Serial.peek () == '\n') { if (Serial.peek() == '\n') {
Serial.println (settings.lockLength); Serial.println(settings.lockLength);
} else { } else {
settings.lockLength = Serial.parseInt (); settings.lockLength = Serial.parseInt();
} }
break; break;
case LEFT_MAX: case LEFT_MAX:
if (Serial.peek () == '\n') { if (Serial.peek() == '\n') {
Serial.println (settings.leftHandMaxKeys); Serial.println(settings.leftHandMaxKeys);
} else { } else {
settings.leftHandMaxKeys = Serial.parseInt (); settings.leftHandMaxKeys = Serial.parseInt();
} }
break; break;
case RIGHT_MAX: case RIGHT_MAX:
if (Serial.peek () == '\n') { if (Serial.peek() == '\n') {
Serial.println (settings.rightHandMaxKeys); Serial.println(settings.rightHandMaxKeys);
} else { } else {
settings.rightHandMaxKeys = Serial.parseInt (); settings.rightHandMaxKeys = Serial.parseInt();
} }
break; break;
} }
EEPROM.put (settingsBase, settings); EEPROM.put(settingsBase, settings);
return true; return true;
} }
} // namespace KaleidoscopePlugins }
KaleidoscopePlugins::TypingBreaks TypingBreaks; KaleidoscopePlugins::TypingBreaks TypingBreaks;
__attribute__((weak)) __attribute__((weak))
void void
TypingBreak (bool isLocked) { TypingBreak(bool isLocked) {
} }

@ -23,12 +23,12 @@
namespace KaleidoscopePlugins { namespace KaleidoscopePlugins {
class TypingBreaks : public KaleidoscopePlugin { class TypingBreaks : public KaleidoscopePlugin {
public: public:
TypingBreaks (void); TypingBreaks(void);
void begin (void) final; void begin(void) final;
static void enableEEPROM (void); static void enableEEPROM(void);
static bool focusHook (const char *command); static bool focusHook(const char *command);
typedef struct settings_t { typedef struct settings_t {
uint32_t idleTimeLimit; uint32_t idleTimeLimit;
@ -49,13 +49,13 @@ class TypingBreaks : public KaleidoscopePlugin {
static uint16_t settingsBase; static uint16_t settingsBase;
static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState);
}
} }
} // namespace KaleidoscopePlugins
extern KaleidoscopePlugins::TypingBreaks TypingBreaks; extern KaleidoscopePlugins::TypingBreaks TypingBreaks;
void TypingBreak (bool isLocked); void TypingBreak(bool isLocked);
#define FOCUS_HOOK_TYPINGBREAKS FOCUS_HOOK(TypingBreaks.focusHook, \ #define FOCUS_HOOK_TYPINGBREAKS FOCUS_HOOK(TypingBreaks.focusHook, \
"typingbreaks.idleTimeLimit\n" \ "typingbreaks.idleTimeLimit\n" \

Loading…
Cancel
Save