Migrate to the new onFocusEvent APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 6 years ago
parent 6152edc6d1
commit 1fcaca840b

@ -84,10 +84,6 @@ properties. All times are in seconds.
## Focus commands ## 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]` ### `typingbreaks.idleTimeLimit [limit]`
> Get or set the `.settings.idle_time_limit` property. > Get or set the `.settings.idle_time_limit` property.

@ -17,7 +17,7 @@
#include <Kaleidoscope-TypingBreaks.h> #include <Kaleidoscope-TypingBreaks.h>
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-FocusSerial.h>
namespace kaleidoscope { namespace kaleidoscope {
@ -123,7 +123,14 @@ void TypingBreaks::enableEEPROM(void) {
EEPROM.get(settings_base_, settings); 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 { enum {
IDLE_TIME_LIMIT, IDLE_TIME_LIMIT,
LOCK_TIMEOUT, LOCK_TIMEOUT,
@ -132,8 +139,15 @@ bool TypingBreaks::focusHook(const char *command) {
RIGHT_MAX, RIGHT_MAX,
} subCommand; } 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) if (strncmp_P(command, PSTR("typingbreaks."), 13) != 0)
return false; return EventHandlerResult::OK;
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)
@ -145,7 +159,7 @@ bool TypingBreaks::focusHook(const char *command) {
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 EventHandlerResult::OK;
switch (subCommand) { switch (subCommand) {
case IDLE_TIME_LIMIT: case IDLE_TIME_LIMIT:
@ -186,7 +200,7 @@ bool TypingBreaks::focusHook(const char *command) {
} }
EEPROM.put(settings_base_, settings); EEPROM.put(settings_base_, settings);
return true; return EventHandlerResult::EVENT_CONSUMED;
} }
} }

@ -26,7 +26,6 @@ class TypingBreaks : public kaleidoscope::Plugin {
TypingBreaks(void) {} TypingBreaks(void) {}
static void enableEEPROM(void); static void enableEEPROM(void);
static bool focusHook(const char *command);
typedef struct settings_t { typedef struct settings_t {
uint16_t idle_time_limit; uint16_t idle_time_limit;
@ -39,6 +38,7 @@ class TypingBreaks : public kaleidoscope::Plugin {
static settings_t settings; static settings_t settings;
EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state); EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state);
EventHandlerResult onFocusEvent(const char *command);
private: private:
static uint32_t session_start_time_; static uint32_t session_start_time_;
@ -55,10 +55,3 @@ class TypingBreaks : public kaleidoscope::Plugin {
extern kaleidoscope::TypingBreaks TypingBreaks; extern kaleidoscope::TypingBreaks TypingBreaks;
void TypingBreak(bool is_locked); 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