Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 0f09130069
commit 9d9ef489be

@ -31,8 +31,9 @@ the box, without any further configuration:
#include <Kaleidoscope-TypingBreaks.h> #include <Kaleidoscope-TypingBreaks.h>
void setup (void) { void setup (void) {
Kaleidoscope.setup ();
USE_PLUGINS (&TypingBreaks); USE_PLUGINS (&TypingBreaks);
Kaleidoscope.setup ();
} }
``` ```
@ -41,27 +42,27 @@ void setup (void) {
The plugin provides a single object, `TypingBreaks`, with the following The plugin provides a single object, `TypingBreaks`, with the following
properties. All times are in milliseconds. properties. All times are in milliseconds.
### `.settings.idleTimeLimit` ### `.settings.idle_time_limit`
> The amount of time that can pass between two pressed keys, before the plugin > The amount of time that can pass between two pressed keys, before the plugin
> considers it a new session, and starts all timers and counters over. > considers it a new session, and starts all timers and counters over.
> >
> Defaults to 10000 (10 seconds). > Defaults to 10000 (10 seconds).
### `.settings.lockTimeOut` ### `.settings.lock_time_out`
> The length of the session, after which the keyboard will be locked. > The length of the session, after which the keyboard will be locked.
> >
> Defaults to 2700000 (45 minutes). > Defaults to 2700000 (45 minutes).
### `.settings.lockLength` ### `.settings.lock_length`
> The length until the keyboard lock is held. Any key pressed while the lock is > The length until the keyboard lock is held. Any key pressed while the lock is
> active, will be discarded. > active, will be discarded.
> >
> Defaults to 300000 (15 minutes). > Defaults to 300000 (15 minutes).
### `.settings.leftHandMaxKeys` ### `.settings.left_hand_max_keys`
> It is possible to lock the keyboard after a number of keys pressed, too. If > It is possible to lock the keyboard after a number of keys pressed, too. If
> this happens sooner than the timeout, the keyboard will still be locked. > this happens sooner than the timeout, the keyboard will still be locked.
@ -70,7 +71,7 @@ properties. All times are in milliseconds.
> >
> Defaults to 0 (off). > Defaults to 0 (off).
### `.settings.rightHandMaxKeys` ### `.settings.right_hand_max_keys`
> It is possible to lock the keyboard after a number of keys pressed, too. If > It is possible to lock the keyboard after a number of keys pressed, too. If
> this happens sooner than the timeout, the keyboard will still be locked. > this happens sooner than the timeout, the keyboard will still be locked.

@ -40,8 +40,9 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
}; };
void setup() { void setup() {
Kaleidoscope.setup();
USE_PLUGINS(&TypingBreaks); USE_PLUGINS(&TypingBreaks);
Kaleidoscope.setup();
} }
void loop() { void loop() {

@ -20,46 +20,45 @@
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-Focus.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
TypingBreaks::settings_t TypingBreaks::settings = { TypingBreaks::settings_t TypingBreaks::settings = {
.idleTimeLimit = 10000, // 10s .idle_time_limit = 10000, // 10s
.lockTimeOut = 2700000, // 45m .lock_time_out = 2700000, // 45m
.lockLength = 300000, // 5m .lock_length = 300000, // 5m
.leftHandMaxKeys = 0, .left_hand_max_keys = 0,
.rightHandMaxKeys = 0 .right_hand_max_keys = 0
}; };
uint32_t TypingBreaks::sessionStartTime; uint32_t TypingBreaks::session_start_time_;
uint32_t TypingBreaks::lastKeyTime; uint32_t TypingBreaks::last_key_time_;
uint32_t TypingBreaks::lockStartTime; uint32_t TypingBreaks::lock_start_time_;
uint16_t TypingBreaks::leftHandKeys; uint16_t TypingBreaks::left_hand_keys_;
uint16_t TypingBreaks::rightHandKeys; uint16_t TypingBreaks::right_hand_keys_;
uint16_t TypingBreaks::settingsBase; uint16_t TypingBreaks::settings_base_;
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 mapped_key, byte row, byte col, uint8_t key_state) {
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 (lock_start_time_ && (millis() - lock_start_time_ <= settings.lock_length))
return Key_NoKey; return Key_NoKey;
// If we are locked... // If we are locked...
if (lockStartTime) { if (lock_start_time_) {
// ...and the lock has not expired yet // ...and the lock has not expired yet
if (millis() - lockStartTime <= settings.lockLength) if (millis() - lock_start_time_ <= settings.lock_length)
return Key_NoKey; // remain locked return Key_NoKey; // remain locked
// ...otherwise clear the lock // ...otherwise clear the lock
lockStartTime = 0; lock_start_time_ = 0;
leftHandKeys = rightHandKeys = 0; left_hand_keys_ = right_hand_keys_ = 0;
sessionStartTime = millis(); session_start_time_ = millis();
TypingBreak(false); TypingBreak(false);
} }
@ -67,32 +66,32 @@ TypingBreaks::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keySta
// 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 (last_key_time_ && (millis() - last_key_time_) >= settings.idle_time_limit) {
// No, we are not. Clear timers and start over. // No, we are not. Clear timers and start over.
lockStartTime = 0; lock_start_time_ = 0;
leftHandKeys = rightHandKeys = 0; left_hand_keys_ = right_hand_keys_ = 0;
sessionStartTime = millis(); session_start_time_ = 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.left_hand_max_keys && left_hand_keys_ >= settings.left_hand_max_keys) {
lockStartTime = millis(); lock_start_time_ = 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.right_hand_max_keys && right_hand_keys_ >= settings.right_hand_max_keys) {
lockStartTime = millis(); lock_start_time_ = millis();
TypingBreak(true); TypingBreak(true);
return Key_NoKey; return Key_NoKey;
} }
if (settings.lockTimeOut) { if (settings.lock_time_out) {
// Is the session longer than lockTimeOut? // Is the session longer than lock_time_out?
if (millis() - sessionStartTime >= settings.lockTimeOut) { if (millis() - session_start_time_ >= settings.lock_time_out) {
// Yeah, it is. // Yeah, it is.
lockStartTime = millis(); lock_start_time_ = millis();
TypingBreak(true); TypingBreak(true);
return Key_NoKey; return Key_NoKey;
} }
@ -101,34 +100,32 @@ TypingBreaks::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keySta
// 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(key_state)) {
if (col <= COLS / 2) if (col <= COLS / 2)
leftHandKeys++; left_hand_keys_++;
else else
rightHandKeys++; right_hand_keys_++;
lastKeyTime = millis(); last_key_time_ = millis();
} }
return mappedKey; return mapped_key;
} }
void void TypingBreaks::enableEEPROM(void) {
TypingBreaks::enableEEPROM(void) { settings_base_ = ::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 idle_time;
EEPROM.get(settingsBase, idleTime); EEPROM.get(settings_base_, idle_time);
if (idleTime == 0xffffffff) { if (idle_time == 0xffffffff) {
EEPROM.put(settingsBase, settings); EEPROM.put(settings_base_, settings);
} }
EEPROM.get(settingsBase, settings); EEPROM.get(settings_base_, 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,
@ -155,49 +152,47 @@ TypingBreaks::focusHook(const char *command) {
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.idle_time_limit);
} else { } else {
settings.idleTimeLimit = Serial.parseInt(); settings.idle_time_limit = 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.lock_time_out);
} else { } else {
settings.lockTimeOut = Serial.parseInt(); settings.lock_time_out = 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.lock_length);
} else { } else {
settings.lockLength = Serial.parseInt(); settings.lock_length = 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.left_hand_max_keys);
} else { } else {
settings.leftHandMaxKeys = Serial.parseInt(); settings.left_hand_max_keys = 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.right_hand_max_keys);
} else { } else {
settings.rightHandMaxKeys = Serial.parseInt(); settings.right_hand_max_keys = Serial.parseInt();
} }
break; break;
} }
EEPROM.put(settingsBase, settings); EEPROM.put(settings_base_, settings);
return true; return true;
} }
} }
KaleidoscopePlugins::TypingBreaks TypingBreaks; kaleidoscope::TypingBreaks TypingBreaks;
__attribute__((weak)) __attribute__((weak)) void TypingBreak(bool isLocked) {
void
TypingBreak(bool isLocked) {
} }

@ -20,7 +20,8 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class TypingBreaks : public KaleidoscopePlugin { class TypingBreaks : public KaleidoscopePlugin {
public: public:
TypingBreaks(void); TypingBreaks(void);
@ -31,31 +32,32 @@ class TypingBreaks : public KaleidoscopePlugin {
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 idle_time_limit;
uint32_t lockTimeOut; uint32_t lock_time_out;
uint32_t lockLength; uint32_t lock_length;
uint16_t leftHandMaxKeys; uint16_t left_hand_max_keys;
uint16_t rightHandMaxKeys; uint16_t right_hand_max_keys;
} settings_t; } settings_t;
static settings_t settings; static settings_t settings;
private: private:
static uint32_t sessionStartTime; static uint32_t session_start_time_;
static uint32_t lockStartTime; static uint32_t lock_start_time_;
static uint32_t lastKeyTime; static uint32_t last_key_time_;
static uint16_t leftHandKeys; static uint16_t left_hand_keys_;
static uint16_t rightHandKeys; static uint16_t right_hand_keys_;
static uint16_t settingsBase; static uint16_t settings_base_;
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
} }
extern KaleidoscopePlugins::TypingBreaks TypingBreaks; extern kaleidoscope::TypingBreaks TypingBreaks;
void TypingBreak(bool isLocked); void TypingBreak(bool is_locked);
#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