Merge pull request #7 from keyboardio/f/onFocusEvent

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

@ -118,13 +118,12 @@ The plugin provides the `EEPROMSettings` object, which has the following methods
## Focus commands ## Focus commands
The plugin provides two [Focus][focus] hooks: `FOCUS_HOOK_SETTINGS`, and The plugin provides two - optional - [Focus][FocusSerial] command plugins:
`FOCUS_HOOK_EEPROM`, that register commands that allow one to work with the `FocusSettingsCommand` and `FocusEEPROMCommand`. These must be explicitly added
settings, and with the contents of the `EEPROM` through Focus. to `KALEIDOSCOPE_INIT_PLUGINS` if one wishes to use them. They provide the
following commands:
[focus]: https://github.com/keyboardio/Kaleidoscope-Focus [FocusSerial]: https://github.com/keyboardio/Kaleidoscope-FocusSerial
These provide the following `Focus` commands:
### `settings.crc` ### `settings.crc`
@ -153,7 +152,7 @@ These provide the following `Focus` commands:
## Dependencies ## Dependencies
* [Kaleidoscope-Focus][focus] * [Kaleidoscope-FocusSerial][FocusSerial]
## Further reading ## Further reading

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope. * Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope.
* Copyright (C) 2017 Keyboard.io, Inc * Copyright (C) 2017-2018 Keyboard.io, Inc
* *
* This program is free software: you can redistribute it and/or modify it under * This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software * the terms of the GNU General Public License as published by the Free Software
@ -16,21 +16,26 @@
*/ */
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-FocusSerial.h>
#include "crc.h" #include "crc.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace eeprom_settings { namespace eeprom {
bool settingsFocusHook(const char *command) { EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *command) {
enum { enum {
ISVALID, ISVALID,
GETVERSION, GETVERSION,
CRC, CRC,
} sub_command; } sub_command;
if (strcmp_P(command, PSTR("help")) == 0) {
Serial.println(F("settings.valid?\nsettings.version\nsettings.crc"));
return EventHandlerResult::OK;
}
if (strncmp_P(command, PSTR("settings."), 9) != 0) if (strncmp_P(command, PSTR("settings."), 9) != 0)
return false; return EventHandlerResult::OK;
if (strcmp_P(command + 9, PSTR("valid?")) == 0) if (strcmp_P(command + 9, PSTR("valid?")) == 0)
sub_command = ISVALID; sub_command = ISVALID;
@ -39,7 +44,7 @@ bool settingsFocusHook(const char *command) {
else if (strcmp_P(command + 9, PSTR("crc")) == 0) else if (strcmp_P(command + 9, PSTR("crc")) == 0)
sub_command = CRC; sub_command = CRC;
else else
return false; return EventHandlerResult::OK;
switch (sub_command) { switch (sub_command) {
case ISVALID: case ISVALID:
@ -56,21 +61,24 @@ bool settingsFocusHook(const char *command) {
break; break;
} }
return true; return EventHandlerResult::EVENT_CONSUMED;
} }
bool eepromFocusHook(const char *command) { EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) {
enum { enum {
CONTENTS, CONTENTS,
FREE, FREE,
} sub_command; } sub_command;
if (::Focus.handleHelp(command, PSTR("eeprom.contents\neeprom.free")))
return EventHandlerResult::OK;
if (strcmp_P(command, PSTR("eeprom.contents")) == 0) if (strcmp_P(command, PSTR("eeprom.contents")) == 0)
sub_command = CONTENTS; sub_command = CONTENTS;
else if (strcmp_P(command, PSTR("eeprom.free")) == 0) else if (strcmp_P(command, PSTR("eeprom.free")) == 0)
sub_command = FREE; sub_command = FREE;
else else
return false; return EventHandlerResult::OK;
switch (sub_command) { switch (sub_command) {
case CONTENTS: { case CONTENTS: {
@ -95,9 +103,11 @@ bool eepromFocusHook(const char *command) {
break; break;
} }
return true; return EventHandlerResult::EVENT_CONSUMED;
} }
} }
} }
kaleidoscope::eeprom::FocusSettingsCommand FocusSettingsCommand;
kaleidoscope::eeprom::FocusEEPROMCommand FocusEEPROMCommand;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope. * Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope.
* Copyright (C) 2017 Keyboard.io, Inc * Copyright (C) 2017, 2018 Keyboard.io, Inc
* *
* This program is free software: you can redistribute it and/or modify it under * This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software * the terms of the GNU General Public License as published by the Free Software
@ -20,21 +20,23 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
namespace kaleidoscope { namespace kaleidoscope {
namespace eeprom_settings { namespace eeprom {
class FocusSettingsCommand : public kaleidoscope::Plugin {
public:
FocusSettingsCommand() {}
bool settingsFocusHook(const char *command); EventHandlerResult onFocusEvent(const char *command);
bool eepromFocusHook(const char *command); };
class FocusEEPROMCommand : public kaleidoscope::Plugin {
public:
FocusEEPROMCommand () {}
EventHandlerResult onFocusEvent(const char *command);
};
} }
} }
#define FOCUS_HOOK_SETTINGS FOCUS_HOOK \ extern kaleidoscope::eeprom::FocusSettingsCommand FocusSettingsCommand;
(kaleidoscope::eeprom_settings::settingsFocusHook, \ extern kaleidoscope::eeprom::FocusEEPROMCommand FocusEEPROMCommand;
"settings.valid?\n" \
"settings.version\n" \
"settings.crc")
#define FOCUS_HOOK_EEPROM FOCUS_HOOK \
(kaleidoscope::eeprom_settings::eepromFocusHook, \
"eeprom.free\n" \
"eeprom.contents")

Loading…
Cancel
Save