Move the configurable settings into a struct

This is in preparation for persisting these in EEPROM.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 107d51ce5a
commit 6e49fb4481

@ -41,27 +41,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.
### `.idleTimeLimit` ### `.settings.idleTimeLimit`
> 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).
### `.lockTimeOut` ### `.settings.lockTimeOut`
> 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).
### `.lockLength` ### `.settings.lockLength`
> 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).
### `.leftHandMaxKeys` ### `.settings.leftHandMaxKeys`
> 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 +70,7 @@ properties. All times are in milliseconds.
> >
> Defaults to 0 (off). > Defaults to 0 (off).
### `.rightHandMaxKeys` ### `.settings.rightHandMaxKeys`
> 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.

@ -20,11 +20,11 @@
namespace KaleidoscopePlugins { namespace KaleidoscopePlugins {
uint32_t TypingBreaks::idleTimeLimit = 10000; // 10s uint32_t TypingBreaks::settings::idleTimeLimit = 10000; // 10s
uint32_t TypingBreaks::lockTimeOut = 2700000; // 45m uint32_t TypingBreaks::settings::lockTimeOut = 2700000; // 45m
uint32_t TypingBreaks::lockLength = 300000; // 5m uint32_t TypingBreaks::settings::lockLength = 300000; // 5m
uint16_t TypingBreaks::leftHandMaxKeys; uint16_t TypingBreaks::settings::leftHandMaxKeys;
uint16_t TypingBreaks::rightHandMaxKeys; uint16_t TypingBreaks::settings::rightHandMaxKeys;
uint32_t TypingBreaks::sessionStartTime; uint32_t TypingBreaks::sessionStartTime;
uint32_t TypingBreaks::lastKeyTime; uint32_t TypingBreaks::lastKeyTime;
@ -43,13 +43,13 @@ namespace KaleidoscopePlugins {
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 <= 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 <= lockLength) if (millis () - lockStartTime <= settings.lockLength)
return Key_NoKey; // remain locked return Key_NoKey; // remain locked
// ...otherwise clear the lock // ...otherwise clear the lock
@ -61,7 +61,7 @@ namespace KaleidoscopePlugins {
// 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) >= 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;
@ -69,20 +69,20 @@ namespace KaleidoscopePlugins {
} }
// 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 (leftHandMaxKeys && leftHandKeys >= leftHandMaxKeys) { if (settings.leftHandMaxKeys && leftHandKeys >= settings.leftHandMaxKeys) {
lockStartTime = millis (); lockStartTime = millis ();
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 (rightHandMaxKeys && rightHandKeys >= rightHandMaxKeys) { if (settings.rightHandMaxKeys && rightHandKeys >= settings.rightHandMaxKeys) {
lockStartTime = millis (); lockStartTime = millis ();
return Key_NoKey; return Key_NoKey;
} }
if (lockTimeOut) { if (settings.lockTimeOut) {
// Is the session longer than lockTimeOut? // Is the session longer than lockTimeOut?
if (millis () - sessionStartTime >= lockTimeOut) { if (millis () - sessionStartTime >= settings.lockTimeOut) {
// Yeah, it is. // Yeah, it is.
lockStartTime = millis (); lockStartTime = millis ();
return Key_NoKey; return Key_NoKey;

@ -27,11 +27,13 @@ namespace KaleidoscopePlugins {
virtual void begin (void) final; virtual void begin (void) final;
static struct settings {
static uint32_t idleTimeLimit; static uint32_t idleTimeLimit;
static uint32_t lockTimeOut; static uint32_t lockTimeOut;
static uint32_t lockLength; static uint32_t lockLength;
static uint16_t leftHandMaxKeys; static uint16_t leftHandMaxKeys;
static uint16_t rightHandMaxKeys; static uint16_t rightHandMaxKeys;
} settings;
private: private:
static uint32_t sessionStartTime; static uint32_t sessionStartTime;

Loading…
Cancel
Save