Merge pull request #14 from keyboardio/f/onFocusEvent

Migrate to the new onFocusEvent APIs
pull/389/head
Jesse Vincent 6 years ago committed by GitHub
commit 00f88b52dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -84,10 +84,6 @@ properties. All times are in seconds.
## Focus commands
The plugin provides a single `Focus` hook, `FOCUS_HOOK_TYPINGBREAKS`, which in
turn make a few commands available. All of these return the respective setting's
value when called without arguments, or set them if called with some.
### `typingbreaks.idleTimeLimit [limit]`
> Get or set the `.settings.idle_time_limit` property.

@ -17,7 +17,7 @@
#include <Kaleidoscope-TypingBreaks.h>
#include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Focus.h>
#include <Kaleidoscope-FocusSerial.h>
namespace kaleidoscope {
@ -123,7 +123,14 @@ void TypingBreaks::enableEEPROM(void) {
EEPROM.get(settings_base_, settings);
}
bool TypingBreaks::focusHook(const char *command) {
#define FOCUS_HOOK_TYPINGBREAKS FOCUS_HOOK(TypingBreaks.focusHook, \
"typingbreaks.idleTimeLimit\n" \
"typingbreaks.lockTimeOut\n" \
"typingbreaks.lockLength\n" \
"typingbreaks.leftMaxKeys\n" \
"typingbreaks.rightMaxKeys")
EventHandlerResult TypingBreaks::onFocusEvent(const char *command) {
enum {
IDLE_TIME_LIMIT,
LOCK_TIMEOUT,
@ -132,8 +139,15 @@ bool TypingBreaks::focusHook(const char *command) {
RIGHT_MAX,
} subCommand;
if (::Focus.handleHelp(command, PSTR("typingbreaks.idleTimeLimit\n"
"typingbreaks.lockTimeOut\n"
"typingbreaks.lockLength\n"
"typingbreaks.leftMaxKeys\n"
"typingbreaks.rightMaxKeys")))
return EventHandlerResult::OK;
if (strncmp_P(command, PSTR("typingbreaks."), 13) != 0)
return false;
return EventHandlerResult::OK;
if (strcmp_P(command + 13, PSTR("idleTimeLimit")) == 0)
subCommand = IDLE_TIME_LIMIT;
else if (strcmp_P(command + 13, PSTR("lockTimeOut")) == 0)
@ -145,7 +159,7 @@ bool TypingBreaks::focusHook(const char *command) {
else if (strcmp_P(command + 13, PSTR("rightMaxKeys")) == 0)
subCommand = RIGHT_MAX;
else
return false;
return EventHandlerResult::OK;
switch (subCommand) {
case IDLE_TIME_LIMIT:
@ -186,7 +200,7 @@ bool TypingBreaks::focusHook(const char *command) {
}
EEPROM.put(settings_base_, settings);
return true;
return EventHandlerResult::EVENT_CONSUMED;
}
}

@ -26,7 +26,6 @@ class TypingBreaks : public kaleidoscope::Plugin {
TypingBreaks(void) {}
static void enableEEPROM(void);
static bool focusHook(const char *command);
typedef struct settings_t {
uint16_t idle_time_limit;
@ -39,6 +38,7 @@ class TypingBreaks : public kaleidoscope::Plugin {
static settings_t settings;
EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state);
EventHandlerResult onFocusEvent(const char *command);
private:
static uint32_t session_start_time_;
@ -55,10 +55,3 @@ class TypingBreaks : public kaleidoscope::Plugin {
extern kaleidoscope::TypingBreaks TypingBreaks;
void TypingBreak(bool is_locked);
#define FOCUS_HOOK_TYPINGBREAKS FOCUS_HOOK(TypingBreaks.focusHook, \
"typingbreaks.idleTimeLimit\n" \
"typingbreaks.lockTimeOut\n" \
"typingbreaks.lockLength\n" \
"typingbreaks.leftMaxKeys\n" \
"typingbreaks.rightMaxKeys")

Loading…
Cancel
Save