Merge pull request #1263 from noerw/typingbreaks-add-focus-cmds

TypingBreaks: add focus commands for getting runtime state
master
Gergely Nagy 2 years ago committed by GitHub
commit 49a691e0f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -96,6 +96,18 @@ properties. All times are in seconds.
> Get or set the `.settings.right_hand_max_keys` property. > Get or set the `.settings.right_hand_max_keys` property.
### `typingbreaks.leftKeys`
> Get the current counter of keys pressed on the left half of the keyboard.
### `typingbreaks.rightKeys`
> Get the current counter of keys pressed on the right half of the keyboard.
### `typingbreaks.lockSecsRemaining`
> Get the duration the keyboard remains locked in seconds.
## Dependencies ## Dependencies
* [Kaleidoscope-EEPROM-Settings](Kaleidoscope-EEPROM-Settings.md) * [Kaleidoscope-EEPROM-Settings](Kaleidoscope-EEPROM-Settings.md)

@ -132,13 +132,6 @@ EventHandlerResult TypingBreaks::onSetup() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
#define FOCUS_HOOK_TYPINGBREAKS FOCUS_HOOK(TypingBreaks.focusHook, \
"typingbreaks.idleTimeLimit\r\n" \
"typingbreaks.lockTimeOut\r\n" \
"typingbreaks.lockLength\r\n" \
"typingbreaks.leftMaxKeys\r\n" \
"typingbreaks.rightMaxKeys")
EventHandlerResult TypingBreaks::onFocusEvent(const char *input) { EventHandlerResult TypingBreaks::onFocusEvent(const char *input) {
enum { enum {
IDLE_TIME_LIMIT, IDLE_TIME_LIMIT,
@ -146,6 +139,9 @@ EventHandlerResult TypingBreaks::onFocusEvent(const char *input) {
LOCK_LENGTH, LOCK_LENGTH,
LEFT_MAX, LEFT_MAX,
RIGHT_MAX, RIGHT_MAX,
LEFT_COUNT,
RIGHT_COUNT,
LOCK_SECS_REMAINING,
} subCommand; } subCommand;
const char *cmd_idleTimeLimit = PSTR("typingbreaks.idleTimeLimit"); const char *cmd_idleTimeLimit = PSTR("typingbreaks.idleTimeLimit");
@ -153,12 +149,18 @@ EventHandlerResult TypingBreaks::onFocusEvent(const char *input) {
const char *cmd_lockLength = PSTR("typingbreaks.lockLength"); const char *cmd_lockLength = PSTR("typingbreaks.lockLength");
const char *cmd_leftMaxKeys = PSTR("typingbreaks.leftMaxKeys"); const char *cmd_leftMaxKeys = PSTR("typingbreaks.leftMaxKeys");
const char *cmd_rightMaxKeys = PSTR("typingbreaks.rightMaxKeys"); const char *cmd_rightMaxKeys = PSTR("typingbreaks.rightMaxKeys");
const char *cmd_leftKeys = PSTR("typingbreaks.leftKeys");
const char *cmd_rightKeys = PSTR("typingbreaks.rightKeys");
const char *cmd_lockSecsRem = PSTR("typingbreaks.lockSecsRemaining");
if (::Focus.inputMatchesHelp(input)) if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_idleTimeLimit, return ::Focus.printHelp(cmd_idleTimeLimit,
cmd_lockTimeOut, cmd_lockTimeOut,
cmd_lockLength, cmd_lockLength,
cmd_leftMaxKeys, cmd_leftMaxKeys,
cmd_rightMaxKeys); cmd_rightMaxKeys,
cmd_leftKeys,
cmd_rightKeys,
cmd_lockSecsRem);
if (::Focus.inputMatchesCommand(input, cmd_idleTimeLimit)) if (::Focus.inputMatchesCommand(input, cmd_idleTimeLimit))
subCommand = IDLE_TIME_LIMIT; subCommand = IDLE_TIME_LIMIT;
@ -170,6 +172,12 @@ EventHandlerResult TypingBreaks::onFocusEvent(const char *input) {
subCommand = LEFT_MAX; subCommand = LEFT_MAX;
else if (::Focus.inputMatchesCommand(input, cmd_rightMaxKeys)) else if (::Focus.inputMatchesCommand(input, cmd_rightMaxKeys))
subCommand = RIGHT_MAX; subCommand = RIGHT_MAX;
else if (::Focus.inputMatchesCommand(input, cmd_leftKeys))
subCommand = LEFT_COUNT;
else if (::Focus.inputMatchesCommand(input, cmd_rightKeys))
subCommand = RIGHT_COUNT;
else if (::Focus.inputMatchesCommand(input, cmd_lockSecsRem))
subCommand = LOCK_SECS_REMAINING;
else else
return EventHandlerResult::OK; return EventHandlerResult::OK;
@ -209,6 +217,21 @@ EventHandlerResult TypingBreaks::onFocusEvent(const char *input) {
::Focus.read(settings.right_hand_max_keys); ::Focus.read(settings.right_hand_max_keys);
} }
break; break;
case LEFT_COUNT:
::Focus.send(left_hand_keys_);
return EventHandlerResult::EVENT_CONSUMED;
case RIGHT_COUNT:
::Focus.send(right_hand_keys_);
return EventHandlerResult::EVENT_CONSUMED;
case LOCK_SECS_REMAINING:
if (keyboard_locked_) {
uint16_t elapsed = Runtime.millisAtCycleStart() / 1000 - lock_start_time_ / 1000;
uint16_t remaining = settings.lock_length - elapsed;
::Focus.send(remaining);
} else {
::Focus.send(0);
}
return EventHandlerResult::EVENT_CONSUMED;
} }
Runtime.storage().put(settings_base_, settings); Runtime.storage().put(settings_base_, settings);

Loading…
Cancel
Save