Migrate to the new onFocusEvent API

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 6 years ago
parent ad36c4c10f
commit 504727d677

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

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* 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-Focus.h>
#include <Kaleidoscope-FocusSerial.h>
#include "crc.h"
namespace kaleidoscope {
namespace eeprom_settings {
namespace eeprom {
bool settingsFocusHook(const char *command) {
EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *command) {
enum {
ISVALID,
GETVERSION,
CRC,
} 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)
return false;
return EventHandlerResult::OK;
if (strcmp_P(command + 9, PSTR("valid?")) == 0)
sub_command = ISVALID;
@ -39,7 +44,7 @@ bool settingsFocusHook(const char *command) {
else if (strcmp_P(command + 9, PSTR("crc")) == 0)
sub_command = CRC;
else
return false;
return EventHandlerResult::OK;
switch (sub_command) {
case ISVALID:
@ -56,21 +61,24 @@ bool settingsFocusHook(const char *command) {
break;
}
return true;
return EventHandlerResult::EVENT_CONSUMED;
}
bool eepromFocusHook(const char *command) {
EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) {
enum {
CONTENTS,
FREE,
} sub_command;
if (::Focus.handleHelp(command, PSTR("eeprom.contents\neeprom.free")))
return EventHandlerResult::OK;
if (strcmp_P(command, PSTR("eeprom.contents")) == 0)
sub_command = CONTENTS;
else if (strcmp_P(command, PSTR("eeprom.free")) == 0)
sub_command = FREE;
else
return false;
return EventHandlerResult::OK;
switch (sub_command) {
case CONTENTS: {
@ -95,9 +103,11 @@ bool eepromFocusHook(const char *command) {
break;
}
return true;
return EventHandlerResult::EVENT_CONSUMED;
}
}
}
kaleidoscope::eeprom::FocusSettingsCommand FocusSettingsCommand;
kaleidoscope::eeprom::FocusEEPROMCommand FocusEEPROMCommand;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* the terms of the GNU General Public License as published by the Free Software
@ -20,21 +20,23 @@
#include <Kaleidoscope.h>
namespace kaleidoscope {
namespace eeprom_settings {
namespace eeprom {
class FocusSettingsCommand : public kaleidoscope::Plugin {
public:
FocusSettingsCommand() {}
bool settingsFocusHook(const char *command);
bool eepromFocusHook(const char *command);
EventHandlerResult onFocusEvent(const char *command);
};
class FocusEEPROMCommand : public kaleidoscope::Plugin {
public:
FocusEEPROMCommand () {}
EventHandlerResult onFocusEvent(const char *command);
};
}
}
#define FOCUS_HOOK_SETTINGS FOCUS_HOOK \
(kaleidoscope::eeprom_settings::settingsFocusHook, \
"settings.valid?\n" \
"settings.version\n" \
"settings.crc")
#define FOCUS_HOOK_EEPROM FOCUS_HOOK \
(kaleidoscope::eeprom_settings::eepromFocusHook, \
"eeprom.free\n" \
"eeprom.contents")
extern kaleidoscope::eeprom::FocusSettingsCommand FocusSettingsCommand;
extern kaleidoscope::eeprom::FocusEEPROMCommand FocusEEPROMCommand;

Loading…
Cancel
Save