Merge pull request #1231 from keyboardio/f/handleHelp-varargs

My take on a Focus refactor
master
Gergely Nagy 2 years ago committed by GitHub
commit ca9b4cb50c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -273,8 +273,13 @@ class FocusExampleCommand : public Plugin {
return ::Focus.sendName(F("FocusExampleCommand"));
}
EventHandlerResult onFocusEvent(const char *command) {
if (strcmp_P(command, PSTR("example")) != 0)
EventHandlerResult onFocusEvent(const char *input) {
const char *cmd = PSTR("example");
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);
if (!::Focus.inputMatchesCommand(input, cmd))
return EventHandlerResult::OK;
::Focus.send(F("This is an example response. Hello world!"));
@ -348,8 +353,8 @@ class ExamplePlugin : public Plugin {
public:
ExamplePlugin();
EventHandlerResult onFocusEvent(const char *command) {
if (strcmp_P(command, PSTR("example.toggle")) != 0)
EventHandlerResult onFocusEvent(const char *input) {
if (!::Focus.inputMatchesCommand(input, PSTR("example.toggle")))
return EventHandlerResult::OK;
example_toggle_ = !example_toggle_;
@ -408,8 +413,8 @@ class ExampleOptionalCommand : public Plugin {
public:
ExampleOptionalCommand() {}
EventHandlerResult onFocusEvent(const char *command) {
if (strcmp_P(command, PSTR("optional")) != 0)
EventHandlerResult onFocusEvent(const char *input) {
if (!::Focus.inputMatchesCommand(input, PSTR("optional")))
return EventHandlerResult::OK;
::Focus.send(Layer.getLayerState());
@ -793,7 +798,7 @@ void macroNewSentence(KeyEvent &event) {
`kaleidoscope-builder` has been removed.
We replaced it with a new Makefile based build system that uses `arduino-cli` instead of of the full Arduino IDE. This means that you can now check out development copies of Kaliedoscope into any directory, using the `KALEIDOSCOPE_DIR` environment variable to point to your installation.
We replaced it with a new Makefile based build system that uses `arduino-cli` instead of of the full Arduino IDE. This means that you can now check out development copies of Kaliedoscope into any directory, using the `KALEIDOSCOPE_DIR` environment variable to point to your installation.
### OneShot meta keys

@ -44,13 +44,13 @@ class FocusTestCommand : public Plugin {
public:
FocusTestCommand() {}
EventHandlerResult onFocusEvent(const char *command) {
EventHandlerResult onFocusEvent(const char *input) {
const char *cmd = PSTR("test");
if (::Focus.handleHelp(command, cmd))
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);
if (strcmp_P(command, cmd) == 0) {
if (::Focus.inputMatchesCommand(input, cmd)) {
::Focus.send(F("ok!"));
return EventHandlerResult::EVENT_CONSUMED;
}
@ -63,8 +63,9 @@ class FocusHelpCommand : public Plugin {
public:
FocusHelpCommand() {}
EventHandlerResult onFocusEvent(const char *command) {
::Focus.handleHelp(command, PSTR("help"));
EventHandlerResult onFocusEvent(const char *input) {
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(PSTR("help"));
return EventHandlerResult::OK;
}

@ -27,7 +27,7 @@ class TestLEDMode : public kaleidoscope::plugin::LEDMode {
public:
TestLEDMode() {}
kaleidoscope::EventHandlerResult onFocusEvent(const char *command);
kaleidoscope::EventHandlerResult onFocusEvent(const char *input);
protected:
void setup() final;
@ -48,8 +48,8 @@ void TestLEDMode::update(void) {
}
kaleidoscope::EventHandlerResult
TestLEDMode::onFocusEvent(const char *command) {
return LEDPaletteTheme.themeFocusEvent(command, PSTR("testLedMode.map"), map_base_, 1);
TestLEDMode::onFocusEvent(const char *input) {
return LEDPaletteTheme.themeFocusEvent(input, PSTR("testLedMode.map"), map_base_, 1);
}
} // namespace example

@ -275,7 +275,7 @@ class AutoShift : public Plugin {
class AutoShiftConfig : public Plugin {
public:
EventHandlerResult onSetup();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
private:
// The base address in persistent storage for configuration data

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/AutoShift.h" // IWYU pragma: associated
#include <Arduino.h> // for PSTR, strcmp_P, strncmp_P
#include <Arduino.h> // for PSTR
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t, uint16_t
@ -47,25 +47,25 @@ EventHandlerResult AutoShiftConfig::onSetup() {
return EventHandlerResult::OK;
}
EventHandlerResult AutoShiftConfig::onFocusEvent(const char *command) {
EventHandlerResult AutoShiftConfig::onFocusEvent(const char *input) {
enum {
ENABLED,
TIMEOUT,
CATEGORIES,
} subCommand;
if (::Focus.handleHelp(command, PSTR("autoshift.enabled\r\n"
"autoshift.timeout\r\n"
"autoshift.categories")))
return EventHandlerResult::OK;
const char *cmd_enabled = PSTR("autoshift.enabled");
const char *cmd_timeout = PSTR("autoshift.timeout");
const char *cmd_categories = PSTR("autoshift.categories");
if (strncmp_P(command, PSTR("autoshift."), 10) != 0)
return EventHandlerResult::OK;
if (strcmp_P(command + 10, PSTR("enabled")) == 0)
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_enabled, cmd_timeout, cmd_categories);
if (::Focus.inputMatchesCommand(input, cmd_enabled))
subCommand = ENABLED;
else if (strcmp_P(command + 10, PSTR("timeout")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_timeout))
subCommand = TIMEOUT;
else if (strcmp_P(command + 10, PSTR("categories")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_categories))
subCommand = CATEGORIES;
else
return EventHandlerResult::OK;

@ -78,8 +78,8 @@ EventHandlerResult ColormapEffect::onLayerChange() {
return EventHandlerResult::OK;
}
EventHandlerResult ColormapEffect::onFocusEvent(const char *command) {
return ::LEDPaletteTheme.themeFocusEvent(command, PSTR("colormap.map"), map_base_, max_layers_);
EventHandlerResult ColormapEffect::onFocusEvent(const char *input) {
return ::LEDPaletteTheme.themeFocusEvent(input, PSTR("colormap.map"), map_base_, max_layers_);
}
} // namespace plugin

@ -36,7 +36,7 @@ class ColormapEffect : public Plugin,
EventHandlerResult onLayerChange();
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
static bool isUninitialized();
static void updateColorIndexAtPosition(uint8_t layer, uint16_t position, uint8_t palette_index);

@ -72,16 +72,16 @@ void DefaultColormap::install() {
::LEDControl.refreshAll();
}
EventHandlerResult DefaultColormap::onFocusEvent(const char *command) {
EventHandlerResult DefaultColormap::onFocusEvent(const char *input) {
if (!Runtime.has_leds)
return EventHandlerResult::OK;
const char *cmd = PSTR("colormap.install");
if (::Focus.handleHelp(command, cmd))
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);
if (strcmp_P(command, cmd) != 0)
if (!::Focus.inputMatchesCommand(input, cmd))
return EventHandlerResult::OK;
install();

@ -87,7 +87,7 @@ class DefaultColormap : public Plugin {
static void setup();
static void install();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
};
} // namespace plugin

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/DefaultLEDModeConfig.h"
#include <Arduino.h> // for PSTR, strcmp_P, F, __FlashStringHelper
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t, uint16_t
@ -48,13 +48,13 @@ EventHandlerResult DefaultLEDModeConfig::onSetup() {
return EventHandlerResult::OK;
}
EventHandlerResult DefaultLEDModeConfig::onFocusEvent(const char *command) {
EventHandlerResult DefaultLEDModeConfig::onFocusEvent(const char *input) {
const char *cmd = PSTR("led_mode.default");
if (::Focus.handleHelp(command, cmd))
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);
if (strcmp_P(command, cmd) != 0)
if (!::Focus.inputMatchesCommand(input, cmd))
return EventHandlerResult::OK;
if (::Focus.isEOL()) {

@ -30,7 +30,7 @@ class DefaultLEDModeConfig : public kaleidoscope::Plugin {
public:
EventHandlerResult onSetup();
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
void activateLEDModeIfUnconfigured(LEDModeInterface *plugin);

@ -16,7 +16,7 @@
#include "kaleidoscope/plugin/DynamicMacros.h"
#include <Arduino.h> // for delay, PSTR, strcmp_P, F, __FlashStri...
#include <Arduino.h> // for delay, PSTR, F, __FlashStri...
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <Kaleidoscope-Ranges.h> // for DYNAMIC_MACRO_FIRST, DYNAMIC_MACRO_LAST
@ -214,14 +214,14 @@ EventHandlerResult DynamicMacros::onNameQuery() {
return ::Focus.sendName(F("DynamicMacros"));
}
EventHandlerResult DynamicMacros::onFocusEvent(const char *command) {
if (::Focus.handleHelp(command, PSTR("macros.map\r\nmacros.trigger")))
return EventHandlerResult::OK;
EventHandlerResult DynamicMacros::onFocusEvent(const char *input) {
const char *cmd_map = PSTR("macros.map");
const char *cmd_trigger = PSTR("macros.trigger");
if (strncmp_P(command, PSTR("macros."), 7) != 0)
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_map, cmd_trigger);
if (strcmp_P(command + 7, PSTR("map")) == 0) {
if (::Focus.inputMatchesCommand(input, cmd_map)) {
if (::Focus.isEOL()) {
for (uint16_t i = 0; i < storage_size_; i++) {
uint8_t b;
@ -240,15 +240,16 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) {
Runtime.storage().commit();
macro_count_ = updateDynamicMacroCache();
}
}
if (strcmp_P(command + 7, PSTR("trigger")) == 0) {
return EventHandlerResult::EVENT_CONSUMED;
} else if (::Focus.inputMatchesCommand(input, cmd_trigger)) {
uint8_t id = 0;
::Focus.read(id);
play(id);
return EventHandlerResult::EVENT_CONSUMED;
}
return EventHandlerResult::EVENT_CONSUMED;
return EventHandlerResult::OK;
}
// public

@ -38,7 +38,7 @@ class DynamicMacros : public kaleidoscope::Plugin {
public:
EventHandlerResult onNameQuery();
EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
EventHandlerResult beforeReportingState(const KeyEvent &event) {
return ::MacroSupport.beforeReportingState(event);
}

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/DynamicTapDance.h"
#include <Arduino.h> // for PSTR, F, __FlashStringHelper, strcmp_P
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t, uint8_t
@ -93,33 +93,33 @@ EventHandlerResult DynamicTapDance::onNameQuery() {
return ::Focus.sendName(F("DynamicTapDance"));
}
EventHandlerResult DynamicTapDance::onFocusEvent(const char *command) {
if (::Focus.handleHelp(command, PSTR("tapdance.map")))
return EventHandlerResult::OK;
EventHandlerResult DynamicTapDance::onFocusEvent(const char *input) {
const char *cmd_map = PSTR("tapdance.map");
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_map);
if (strncmp_P(command, PSTR("tapdance."), 9) != 0)
if (!::Focus.inputMatchesCommand(input, cmd_map))
return EventHandlerResult::OK;
if (strcmp_P(command + 9, PSTR("map")) == 0) {
if (::Focus.isEOL()) {
for (uint16_t i = 0; i < storage_size_; i += 2) {
Key k;
Runtime.storage().get(storage_base_ + i, k);
::Focus.send(k);
}
} else {
uint16_t pos = 0;
if (::Focus.isEOL()) {
for (uint16_t i = 0; i < storage_size_; i += 2) {
Key k;
Runtime.storage().get(storage_base_ + i, k);
::Focus.send(k);
}
} else {
uint16_t pos = 0;
while (!::Focus.isEOL()) {
Key k;
::Focus.read(k);
while (!::Focus.isEOL()) {
Key k;
::Focus.read(k);
Runtime.storage().put(storage_base_ + pos, k);
pos += 2;
}
Runtime.storage().commit();
updateDynamicTapDanceCache();
Runtime.storage().put(storage_base_ + pos, k);
pos += 2;
}
Runtime.storage().commit();
updateDynamicTapDanceCache();
}
return EventHandlerResult::EVENT_CONSUMED;

@ -31,7 +31,7 @@ namespace plugin {
class DynamicTapDance : public kaleidoscope::Plugin {
public:
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
void setup(uint8_t dynamic_offset, uint16_t size);

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/EEPROM-Keymap-Programmer.h"
#include <Arduino.h> // for PSTR, strcmp_P
#include <Arduino.h> // for PSTR
#include <Kaleidoscope-EEPROM-Keymap.h> // for EEPROMKeymap
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t, uint8_t
@ -106,13 +106,13 @@ EventHandlerResult EEPROMKeymapProgrammer::onKeyEvent(KeyEvent &event) {
return EventHandlerResult::EVENT_CONSUMED;
}
EventHandlerResult EEPROMKeymapProgrammer::onFocusEvent(const char *command) {
EventHandlerResult EEPROMKeymapProgrammer::onFocusEvent(const char *input) {
const char *cmd = PSTR("keymap.toggleProgrammer");
if (::Focus.handleHelp(command, cmd))
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);
if (strcmp_P(command, cmd) != 0)
if (!::Focus.inputMatchesCommand(input, cmd))
return EventHandlerResult::OK;
if (state_ == INACTIVE)

@ -41,7 +41,7 @@ class EEPROMKeymapProgrammer : public kaleidoscope::Plugin {
void cancel();
EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
private:
typedef enum {

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/EEPROM-Keymap.h"
#include <Arduino.h> // for PSTR, strcmp_P, F, __FlashStringHelper
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t, uint16_t
@ -101,14 +101,15 @@ void EEPROMKeymap::dumpKeymap(uint8_t layers, Key (*getkey)(uint8_t, KeyAddr)) {
}
}
EventHandlerResult EEPROMKeymap::onFocusEvent(const char *command) {
if (::Focus.handleHelp(command, PSTR("keymap.custom\r\nkeymap.default\r\nkeymap.onlyCustom")))
return EventHandlerResult::OK;
EventHandlerResult EEPROMKeymap::onFocusEvent(const char *input) {
const char *cmd_custom = PSTR("keymap.custom");
const char *cmd_default = PSTR("keymap.default");
const char *cmd_onlyCustom = PSTR("keymap.onlyCustom");
if (strncmp_P(command, PSTR("keymap."), 7) != 0)
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_custom, cmd_default, cmd_onlyCustom);
if (strcmp_P(command + 7, PSTR("onlyCustom")) == 0) {
if (::Focus.inputMatchesCommand(input, cmd_onlyCustom)) {
if (::Focus.isEOL()) {
::Focus.send((uint8_t)::EEPROMSettings.ignoreHardcodedLayers());
} else {
@ -128,7 +129,7 @@ EventHandlerResult EEPROMKeymap::onFocusEvent(const char *command) {
return EventHandlerResult::EVENT_CONSUMED;
}
if (strcmp_P(command + 7, PSTR("default")) == 0) {
if (::Focus.inputMatchesCommand(input, cmd_default)) {
// By using a cast to the appropriate function type,
// tell the compiler which overload of getKeyFromPROGMEM
// we actully want.
@ -138,7 +139,7 @@ EventHandlerResult EEPROMKeymap::onFocusEvent(const char *command) {
return EventHandlerResult::EVENT_CONSUMED;
}
if (strcmp_P(command + 7, PSTR("custom")) != 0)
if (!::Focus.inputMatchesCommand(input, cmd_custom))
return EventHandlerResult::OK;
if (::Focus.isEOL()) {

@ -35,7 +35,7 @@ class EEPROMKeymap : public kaleidoscope::Plugin {
EventHandlerResult onSetup();
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
static void setup(uint8_t max);

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/EEPROM-Settings.h"
#include <Arduino.h> // for PSTR, strcmp_P, F, __FlashStringHelper
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t, uint8_t
@ -156,7 +156,7 @@ void EEPROMSettings::update() {
}
/** Focus **/
EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *command) {
EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *input) {
enum {
DEFAULT_LAYER,
IS_VALID,
@ -164,19 +164,21 @@ EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *command) {
GET_CRC,
} sub_command;
if (::Focus.handleHelp(command, PSTR("settings.defaultLayer\r\nsettings.valid?\r\nsettings.version\r\nsettings.crc")))
return EventHandlerResult::OK;
const char *cmd_defaultLayer = PSTR("settings.defaultLayer");
const char *cmd_isValid = PSTR("settings.valid?");
const char *cmd_version = PSTR("settings.version");
const char *cmd_crc = PSTR("settings.crc");
if (strncmp_P(command, PSTR("settings."), 9) != 0)
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_defaultLayer, cmd_isValid, cmd_version, cmd_crc);
if (strcmp_P(command + 9, PSTR("defaultLayer")) == 0)
if (::Focus.inputMatchesCommand(input, cmd_defaultLayer))
sub_command = DEFAULT_LAYER;
else if (strcmp_P(command + 9, PSTR("valid?")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_isValid))
sub_command = IS_VALID;
else if (strcmp_P(command + 9, PSTR("version")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_version))
sub_command = GET_VERSION;
else if (strcmp_P(command + 9, PSTR("crc")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_crc))
sub_command = GET_CRC;
else
return EventHandlerResult::OK;
@ -206,21 +208,25 @@ EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *command) {
return EventHandlerResult::EVENT_CONSUMED;
}
EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) {
EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *input) {
enum {
CONTENTS,
FREE,
ERASE,
} sub_command;
if (::Focus.handleHelp(command, PSTR("eeprom.contents\r\neeprom.free\r\neeprom.erase")))
return EventHandlerResult::OK;
const char *cmd_contents = PSTR("eeprom.contents");
const char *cmd_free = PSTR("eeprom.free");
const char *cmd_erase = PSTR("eeprom.erase");
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_contents, cmd_free, cmd_erase);
if (strcmp_P(command, PSTR("eeprom.contents")) == 0)
if (::Focus.inputMatchesCommand(input, cmd_contents))
sub_command = CONTENTS;
else if (strcmp_P(command, PSTR("eeprom.free")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_free))
sub_command = FREE;
else if (strcmp_P(command, PSTR("eeprom.erase")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_erase))
sub_command = ERASE;
else
return EventHandlerResult::OK;

@ -86,12 +86,12 @@ class EEPROMSettings : public kaleidoscope::Plugin {
class FocusSettingsCommand : public kaleidoscope::Plugin {
public:
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
};
class FocusEEPROMCommand : public kaleidoscope::Plugin {
public:
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
};
} // namespace plugin

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/Escape-OneShot.h" // IWYU pragma: associated
#include <Arduino.h> // for PSTR, F, __FlashStringHelper, strcmp_P
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
@ -48,11 +48,12 @@ EventHandlerResult EscapeOneShotConfig::onNameQuery() {
return ::Focus.sendName(F("EscapeOneShot"));
}
EventHandlerResult EscapeOneShotConfig::onFocusEvent(const char *command) {
if (::Focus.handleHelp(command, PSTR("escape_oneshot.cancel_key")))
return EventHandlerResult::OK;
EventHandlerResult EscapeOneShotConfig::onFocusEvent(const char *input) {
const char *cmd_cancel_key = PSTR("escape_oneshot.cancel_key");
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_cancel_key);
if (strcmp_P(command, PSTR("escape_oneshot.cancel_key")) != 0)
if (!::Focus.inputMatchesCommand(input, cmd_cancel_key))
return EventHandlerResult::OK;
if (::Focus.isEOL()) {

@ -56,7 +56,7 @@ class EscapeOneShot : public kaleidoscope::Plugin {
class EscapeOneShotConfig : public Plugin {
public:
EventHandlerResult onSetup();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
EventHandlerResult onNameQuery();
private:

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/FingerPainter.h"
#include <Arduino.h> // for PSTR, strcmp_P, F, __FlashStringHelper
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <Kaleidoscope-LED-Palette-Theme.h> // for LEDPaletteTheme
#include <stdint.h> // for uint16_t, uint8_t
@ -94,21 +94,21 @@ EventHandlerResult FingerPainter::onKeyEvent(KeyEvent &event) {
return EventHandlerResult::EVENT_CONSUMED;
}
EventHandlerResult FingerPainter::onFocusEvent(const char *command) {
EventHandlerResult FingerPainter::onFocusEvent(const char *input) {
enum {
TOGGLE,
CLEAR,
} sub_command;
if (::Focus.handleHelp(command, PSTR("fingerpainter.toggle\r\nfingerpainter.clear")))
return EventHandlerResult::OK;
const char *cmd_toggle = PSTR("fingerpainter.toggle");
const char *cmd_clear = PSTR("fingerpainter.clear");
if (strncmp_P(command, PSTR("fingerpainter."), 14) != 0)
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_toggle, cmd_clear);
if (strcmp_P(command + 14, PSTR("toggle")) == 0)
if (::Focus.inputMatchesCommand(input, cmd_toggle))
sub_command = TOGGLE;
else if (strcmp_P(command + 14, PSTR("clear")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_clear))
sub_command = CLEAR;
else
return EventHandlerResult::OK;

@ -36,7 +36,7 @@ class FingerPainter : public LEDMode {
void toggle();
EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
EventHandlerResult onSetup();
EventHandlerResult onNameQuery();

@ -50,13 +50,13 @@ EventHandlerResult FirmwareDump::onSetup() {
return EventHandlerResult::OK;
}
EventHandlerResult FirmwareDump::onFocusEvent(const char *command) {
EventHandlerResult FirmwareDump::onFocusEvent(const char *input) {
const char *cmd = PSTR("firmware.dump");
if (::Focus.handleHelp(command, cmd))
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);
if (strcmp_P(command, cmd) != 0)
if (!::Focus.inputMatchesCommand(input, cmd))
return EventHandlerResult::OK;
uint16_t flash_size = (FLASHEND + 1L);

@ -34,7 +34,7 @@ namespace plugin {
class FirmwareDump : public kaleidoscope::Plugin {
public:
EventHandlerResult onSetup();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
private:
uint16_t bootloader_size_;

@ -21,7 +21,7 @@
#define KALEIDOSCOPE_FIRMWARE_VERSION "0.0.0"
#endif
#include <Arduino.h> // for PSTR, F, __FlashStringHelper, strcmp_P
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
#include "Kaleidoscope-FocusSerial.h" // for Focus, FocusSerial
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin
@ -31,11 +31,13 @@ namespace plugin {
class FirmwareVersion : public Plugin {
public:
EventHandlerResult onFocusEvent(const char *command) {
if (::Focus.handleHelp(command, PSTR("version")))
return EventHandlerResult::OK;
EventHandlerResult onFocusEvent(const char *input) {
const char *cmd_version = PSTR("version");
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_version);
if (strcmp_P(command, PSTR("version")) != 0)
if (!::Focus.inputMatchesCommand(input, cmd_version))
return EventHandlerResult::OK;
#ifdef KALEIDOSCOPE_FIRMWARE_VERSION

@ -24,8 +24,13 @@ class FocusTestCommand : public Plugin {
return ::Focus.sendName(F("FocusTestCommand"));
}
EventHandlerResult onFocusEvent(const char *command) {
if (strcmp_P(command, PSTR("test")) != 0)
EventHandlerResult onFocusEvent(const char *input) {
const char *cmd = PSTR("test");
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);
if (!::Focus.inputMatchesCommand(input, cmd))
return EventHandlerResult::OK;
::Focus.send(F("Congratulations, the test command works!"));
@ -47,6 +52,18 @@ void setup () {
The plugin provides the `Focus` object, with a couple of helper methods aimed at developers. Terminating the response with a dot on its own line is handled implicitly by `FocusSerial`, one does not need to do that explicitly.
### `.inputMatchesHelp(input)`
Returns `true` if the given `input` matches the `help` command. To be used at the top of `onFocusEvent()`, followed by `.printHelp(...)`.
### `.printHelp(...)`
Given a series of strings (stored in `PROGMEM`, via `PSTR()`), prints them one per line. Assumes it is run as part of handling the `help` command. Returns `EventHandlerResult::OK`.
### `.inputMatchesCommand(input, command)`
Returns `true` if the `input` matches the expected `command`, false otherwise. A convenience function over `strcmp_P()`.
### `.send(...)`
### `.sendRaw(...)`

@ -51,17 +51,17 @@ EventHandlerResult FocusSerial::afterEachCycle() {
if (c == SEPARATOR) {
break;
}
command_[buf_cursor_++] = c;
} while (buf_cursor_ < (sizeof(command_) - 1) && Runtime.serialPort().available());
input_[buf_cursor_++] = c;
} while (buf_cursor_ < (sizeof(input_) - 1) && Runtime.serialPort().available());
if ((c != SEPARATOR) && (Runtime.serialPort().peek() != NEWLINE) && buf_cursor_ < (sizeof(command_) - 1)) {
if ((c != SEPARATOR) && (Runtime.serialPort().peek() != NEWLINE) && buf_cursor_ < (sizeof(input_) - 1)) {
// We don't have enough command to work with yet.
// Let's leave the buffer around for another cycle
return EventHandlerResult::OK;
}
// Then process the command
Runtime.onFocusEvent(command_);
Runtime.onFocusEvent(input_);
while (Runtime.serialPort().available()) {
c = Runtime.serialPort().read();
if (c == NEWLINE) {
@ -73,28 +73,23 @@ EventHandlerResult FocusSerial::afterEachCycle() {
// End of command processing is signalled with a CRLF followed by a single period
Runtime.serialPort().println(F("\r\n."));
buf_cursor_ = 0;
memset(command_, 0, sizeof(command_));
memset(input_, 0, sizeof(input_));
return EventHandlerResult::OK;
}
bool FocusSerial::handleHelp(const char *command,
const char *help_message) {
if (strcmp_P(command, PSTR("help")) != 0)
return false;
EventHandlerResult FocusSerial::onFocusEvent(const char *input) {
const char *cmd_help = PSTR("help");
const char *cmd_reset = PSTR("device.reset");
const char *cmd_plugins = PSTR("plugins");
Runtime.serialPort().println((const __FlashStringHelper *)help_message);
return true;
}
EventHandlerResult FocusSerial::onFocusEvent(const char *command) {
if (handleHelp(command, PSTR("help\r\ndevice.reset\r\nplugins")))
return EventHandlerResult::OK;
if (inputMatchesHelp(input))
return printHelp(cmd_help, cmd_reset, cmd_plugins);
if (strcmp_P(command, PSTR("device.reset")) == 0) {
if (inputMatchesCommand(input, cmd_reset)) {
Runtime.device().rebootBootloader();
return EventHandlerResult::EVENT_CONSUMED;
}
if (strcmp_P(command, PSTR("plugins")) == 0) {
if (inputMatchesCommand(input, cmd_plugins)) {
kaleidoscope::Hooks::onNameQuery();
return EventHandlerResult::EVENT_CONSUMED;
}
@ -102,10 +97,27 @@ EventHandlerResult FocusSerial::onFocusEvent(const char *command) {
return EventHandlerResult::OK;
}
#ifndef NDEPRECATED
bool FocusSerial::handleHelp(const char *input, const char *help_message) {
if (!inputMatchesHelp(input)) return false;
printHelp(help_message);
return true;
}
#endif
void FocusSerial::printBool(bool b) {
Runtime.serialPort().print((b) ? F("true") : F("false"));
}
bool FocusSerial::inputMatchesHelp(const char *input) {
return inputMatchesCommand(input, PSTR("help"));
}
bool FocusSerial::inputMatchesCommand(const char *input, const char *expected) {
return strcmp_P(input, expected) == 0;
}
} // namespace plugin
} // namespace kaleidoscope

@ -26,6 +26,15 @@
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerResult::OK
#include "kaleidoscope/key_defs.h" // for Key
#include "kaleidoscope/plugin.h" // for Plugin
// -----------------------------------------------------------------------------
// Deprecation warning messages
#include "kaleidoscope_internal/deprecations.h" // for DEPRECATED
#define _DEPRECATED_MESSAGE_FOCUS_HANDLEHELP \
"The `Focus.handleHelp()` method is deprecated. Please use\n" \
"`Focus.inputMatchesHelp()` and `Focus.printHelp()` instead.\n" \
"This method will be removed after 2022-12-26."
// -----------------------------------------------------------------------------
// IWYU pragma: no_include "WString.h"
@ -37,8 +46,23 @@ class FocusSerial : public kaleidoscope::Plugin {
static constexpr char SEPARATOR = ' ';
static constexpr char NEWLINE = '\n';
bool handleHelp(const char *command,
const char *help_message);
#ifndef NDEPRECATED
DEPRECATED(FOCUS_HANDLEHELP)
bool handleHelp(const char *input, const char *help_message);
#endif
bool inputMatchesHelp(const char *input);
bool inputMatchesCommand(const char *input, const char *expected);
EventHandlerResult printHelp() {
return EventHandlerResult::OK;
}
template<typename... Vars>
EventHandlerResult printHelp(const char *h1, Vars... vars) {
Runtime.serialPort().println((const __FlashStringHelper *)h1);
delayAfterPrint();
return printHelp(vars...);
}
EventHandlerResult sendName(const __FlashStringHelper *name) {
Runtime.serialPort().print(name);
@ -113,10 +137,10 @@ class FocusSerial : public kaleidoscope::Plugin {
/* Hooks */
EventHandlerResult afterEachCycle();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
private:
char command_[32];
char input_[32];
uint8_t buf_cursor_ = 0;
void printBool(bool b);

@ -33,24 +33,37 @@ namespace raise {
#define RAISE_FIRMWARE_VERSION "<unknown>"
#endif
EventHandlerResult Focus::onFocusEvent(const char *command) {
if (::Focus.handleHelp(command, PSTR("hardware.version\r\nhardware.side_power\r\nhardware.side_ver\r\nhardware.sled_ver\r\nhardware.sled_current\r\nhardware.layout\r\nhardware.joint\r\nhardware.keyscan\r\nhardware.crc_errors\r\nhardware.firmware")))
return EventHandlerResult::OK;
if (strncmp_P(command, PSTR("hardware."), 9) != 0)
return EventHandlerResult::OK;
if (strcmp_P(command + 9, PSTR("version")) == 0) {
EventHandlerResult Focus::onFocusEvent(const char *input) {
const char *cmd_version = PSTR("hardware.version");
const char *cmd_side_power = PSTR("hardware.side_power");
const char *cmd_side_ver = PSTR("hardware.side_ver");
const char *cmd_sled_ver = PSTR("hardware.sled_ver");
const char *cmd_sled_current = PSTR("hardware.sled_current");
const char *cmd_layout = PSTR("hardware.layout");
const char *cmd_joint = PSTR("hardware.joint");
const char *cmd_keyscan = PSTR("hardware.keyscan");
const char *cmd_crc_errors = PSTR("hardware.crc_errors");
const char *cmd_firmware = PSTR("hardware.firmware");
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_version,
cmd_side_power,
cmd_side_ver,
cmd_sled_ver,
cmd_sled_current,
cmd_layout,
cmd_joint,
cmd_keyscan,
cmd_crc_errors,
cmd_firmware);
if (::Focus.inputMatchesCommand(input, cmd_version)) {
::Focus.send("Dygma Raise");
return EventHandlerResult::EVENT_CONSUMED;
}
if (strcmp_P(command + 9, PSTR("firmware")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_firmware)) {
::Focus.send(RAISE_FIRMWARE_VERSION);
return EventHandlerResult::EVENT_CONSUMED;
}
if (strcmp_P(command + 9, PSTR("side_power")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_side_power)) {
if (::Focus.isEOL()) {
::Focus.send(Runtime.device().side.getPower());
return EventHandlerResult::EVENT_CONSUMED;
@ -60,33 +73,25 @@ EventHandlerResult Focus::onFocusEvent(const char *command) {
Runtime.device().side.setPower(power);
return EventHandlerResult::EVENT_CONSUMED;
}
}
if (strcmp_P(command + 9, PSTR("side_ver")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_side_ver)) {
::Focus.send("left:");
::Focus.send(Runtime.device().side.leftVersion());
::Focus.send("\r\nright:");
::Focus.send(Runtime.device().side.rightVersion());
return EventHandlerResult::EVENT_CONSUMED;
}
if (strcmp_P(command + 9, PSTR("crc_errors")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_crc_errors)) {
::Focus.send("left:");
::Focus.send(Runtime.device().side.leftCRCErrors());
::Focus.send("\r\nright:");
::Focus.send(Runtime.device().side.rightCRCErrors());
return EventHandlerResult::EVENT_CONSUMED;
}
if (strcmp_P(command + 9, PSTR("sled_ver")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_sled_ver)) {
::Focus.send("left:");
::Focus.send(Runtime.device().side.leftSLEDVersion());
::Focus.send("\r\nright:");
::Focus.send(Runtime.device().side.rightSLEDVersion());
return EventHandlerResult::EVENT_CONSUMED;
}
if (strcmp_P(command + 9, PSTR("sled_current")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_sled_current)) {
if (::Focus.isEOL()) {
::Focus.send("left:");
::Focus.send(Runtime.device().side.leftSLEDCurrent());
@ -99,20 +104,14 @@ EventHandlerResult Focus::onFocusEvent(const char *command) {
Runtime.device().side.setSLEDCurrent(current);
return EventHandlerResult::EVENT_CONSUMED;
}
}
if (strcmp_P(command + 9, PSTR("layout")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_layout)) {
static const auto ANSI = Runtime.device().settings.Layout::ANSI;
::Focus.send(Runtime.device().settings.layout() == ANSI ? "ANSI" : "ISO");
return EventHandlerResult::EVENT_CONSUMED;
}
if (strcmp_P(command + 9, PSTR("joint")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_joint)) {
::Focus.send(Runtime.device().settings.joint());
return EventHandlerResult::EVENT_CONSUMED;
}
if (strcmp_P(command + 9, PSTR("keyscan")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_keyscan)) {
if (::Focus.isEOL()) {
::Focus.send(Runtime.device().settings.keyscanInterval());
return EventHandlerResult::EVENT_CONSUMED;

@ -29,7 +29,7 @@ namespace raise {
class Focus : public kaleidoscope::Plugin {
public:
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
};
} // namespace raise

@ -34,12 +34,14 @@ class SideFlash : public kaleidoscope::Plugin {
_Firmware firmware;
public:
EventHandlerResult onFocusEvent(const char *command) {
if (::Focus.handleHelp(command, PSTR("hardware.flash_left_side\nhardware.flash_right_side\nhardware.verify_left_side\nhardware.verify_right_side")))
return EventHandlerResult::OK;
EventHandlerResult onFocusEvent(const char *input) {
const char *cmd_flash_left = PSTR("hardware.flash_left_side");
const char *cmd_flash_right = PSTR("hardware.flash_right_side");
const char *cmd_verify_left = PSTR("hardware.verify_left_side");
const char *cmd_verify_right = PSTR("hardware.verify_right_side");
if (strncmp_P(command, PSTR("hardware."), 9) != 0)
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_flash_left, cmd_flash_right, cmd_verify_left, cmd_verify_right);
auto sideFlasher = Runtime.device().sideFlasher();
uint8_t left_boot_address = Runtime.device().side.left_boot_address;
@ -50,16 +52,16 @@ class SideFlash : public kaleidoscope::Plugin {
} sub_command;
uint8_t address = 0;
if (strcmp_P(command + 9, PSTR("flash_left_side")) == 0) {
if (::Focus.inputMatchesCommand(input, cmd_flash_left)) {
sub_command = FLASH;
address = left_boot_address;
} else if (strcmp_P(command + 9, PSTR("flash_right_side")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_flash_right)) {
sub_command = FLASH;
address = right_boot_address;
} else if (strcmp_P(command + 9, PSTR("verify_left_side")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_verify_left)) {
sub_command = VERIFY;
address = left_boot_address;
} else if (strcmp_P(command + 9, PSTR("verify_right_side")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_verify_right)) {
sub_command = VERIFY;
address = right_boot_address;
} else {

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/HostOS-Focus.h"
#include <Arduino.h> // for PSTR, strcmp_P
#include <Arduino.h> // for PSTR
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t
@ -27,12 +27,13 @@
namespace kaleidoscope {
namespace plugin {
EventHandlerResult FocusHostOSCommand::onFocusEvent(const char *command) {
EventHandlerResult FocusHostOSCommand::onFocusEvent(const char *input) {
const char *cmd = PSTR("hostos.type");
if (::Focus.handleHelp(command, cmd))
return EventHandlerResult::OK;
if (strcmp_P(command, cmd) != 0)
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);
if (!::Focus.inputMatchesCommand(input, cmd))
return EventHandlerResult::OK;
if (::Focus.isEOL()) {

@ -25,7 +25,7 @@ namespace plugin {
class FocusHostOSCommand : public kaleidoscope::Plugin {
public:
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
};
} // namespace plugin

@ -18,7 +18,7 @@
#include "kaleidoscope/plugin/IdleLEDs.h"
#include <Arduino.h> // for F, PSTR, __FlashStringHelper, strcmp_P
#include <Arduino.h> // for F, PSTR, __FlashStringHelper
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint32_t, uint16_t
@ -97,13 +97,13 @@ void PersistentIdleLEDs::setIdleTimeoutSeconds(uint32_t new_limit) {
Runtime.storage().commit();
}
EventHandlerResult PersistentIdleLEDs::onFocusEvent(const char *command) {
EventHandlerResult PersistentIdleLEDs::onFocusEvent(const char *input) {
const char *cmd = PSTR("idleleds.time_limit");
if (::Focus.handleHelp(command, cmd))
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);
if (strcmp_P(command, cmd) != 0)
if (!::Focus.inputMatchesCommand(input, cmd))
return EventHandlerResult::OK;
if (::Focus.isEOL()) {

@ -46,7 +46,7 @@ class PersistentIdleLEDs : public IdleLEDs {
public:
EventHandlerResult onSetup();
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
static void setIdleTimeoutSeconds(uint32_t new_limit);

@ -24,7 +24,7 @@ class TestLEDMode : public LEDMode {
void setup() final;
void update() final;
kaleidoscope::EventHandlerResult onFocusEvent(const char *command);
kaleidoscope::EventHandlerResult onFocusEvent(const char *input);
private:
static uint16_t map_base_;
@ -41,8 +41,8 @@ void TestLEDMode::update() {
}
kaleidoscope::EventHandlerResult
TestLEDMode::onFocusEvent(const char *command) {
return LEDPaletteTheme.themeFocusEvent(command, PSTR("testLedMode.map"), map_base_, 1);
TestLEDMode::onFocusEvent(const char *input) {
return LEDPaletteTheme.themeFocusEvent(input, PSTR("testLedMode.map"), map_base_, 1);
}
}

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/LED-Palette-Theme.h"
#include <Arduino.h> // for strcmp_P, PSTR
#include <Arduino.h> // for PSTR
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t, uint16_t
@ -122,16 +122,16 @@ bool LEDPaletteTheme::isThemeUninitialized(uint16_t theme_base, uint8_t max_them
return paletteEmpty && themeEmpty;
}
EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) {
EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *input) {
if (!Runtime.has_leds)
return EventHandlerResult::OK;
const char *cmd = PSTR("palette");
if (::Focus.handleHelp(command, cmd))
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);
if (strcmp_P(command, cmd) != 0)
if (!::Focus.inputMatchesCommand(input, cmd))
return EventHandlerResult::OK;
if (::Focus.isEOL()) {
@ -159,17 +159,17 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) {
return EventHandlerResult::EVENT_CONSUMED;
}
EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command,
const char *expected_command,
EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *input,
const char *expected_input,
uint16_t theme_base,
uint8_t max_themes) {
if (!Runtime.has_leds)
return EventHandlerResult::OK;
if (::Focus.handleHelp(command, expected_command))
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(expected_input);
if (strcmp_P(command, expected_command) != 0)
if (!::Focus.inputMatchesCommand(input, expected_input))
return EventHandlerResult::OK;
uint16_t max_index = (max_themes * Runtime.device().led_count) / 2;

@ -40,9 +40,9 @@ class LEDPaletteTheme : public kaleidoscope::Plugin {
static void updatePaletteColor(uint8_t palette_index, cRGB color);
static const cRGB lookupPaletteColor(uint8_t palette_index);
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult themeFocusEvent(const char *command,
const char *expected_command,
EventHandlerResult onFocusEvent(const char *input);
EventHandlerResult themeFocusEvent(const char *input,
const char *expected_input,
uint16_t theme_base,
uint8_t max_themes);
static bool isThemeUninitialized(uint16_t theme_base, uint8_t max_themes);

@ -18,7 +18,7 @@
#include "kaleidoscope/plugin/LayerFocus.h"
#include <Arduino.h> // for PSTR, strcmp_P, F, __FlashStringHelper
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t
@ -32,39 +32,45 @@ EventHandlerResult LayerFocus::onNameQuery() {
return ::Focus.sendName(F("LayerFocus"));
}
EventHandlerResult LayerFocus::onFocusEvent(const char *command) {
if (::Focus.handleHelp(command, PSTR("layer.activate\r\nlayer.deactivate\r\nlayer.isActive"
"\r\nlayer.moveTo\r\nlayer.state")))
return EventHandlerResult::OK;
EventHandlerResult LayerFocus::onFocusEvent(const char *input) {
const char *cmd_activate = PSTR("layer.activate");
const char *cmd_deactivate = PSTR("layer.deactivate");
const char *cmd_isActive = PSTR("layer.isActive");
const char *cmd_moveTo = PSTR("layer.moveTo");
const char *cmd_state = PSTR("layer.state");
if (strncmp_P(command, PSTR("layer."), 6) != 0)
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_activate,
cmd_deactivate,
cmd_isActive,
cmd_moveTo,
cmd_state);
if (strcmp_P(command + 6, PSTR("activate")) == 0) {
if (::Focus.inputMatchesCommand(input, cmd_activate)) {
if (!::Focus.isEOL()) {
uint8_t layer;
::Focus.read(layer);
::Layer.activate(layer);
}
} else if (strcmp_P(command + 6, PSTR("deactivate")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_deactivate)) {
if (!::Focus.isEOL()) {
uint8_t layer;
::Focus.read(layer);
::Layer.deactivate(layer);
}
} else if (strcmp_P(command + 6, PSTR("isActive")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_isActive)) {
if (!::Focus.isEOL()) {
uint8_t layer;
::Focus.read(layer);
::Focus.send(::Layer.isActive(layer));
}
} else if (strcmp_P(command + 6, PSTR("moveTo")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_moveTo)) {
if (!::Focus.isEOL()) {
uint8_t layer;
::Focus.read(layer);
::Layer.move(layer);
}
} else if (strcmp_P(command + 6, PSTR("state")) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_state)) {
if (::Focus.isEOL()) {
for (uint8_t i = 0; i < 32; i++) {
::Focus.send(::Layer.isActive(i) ? 1 : 0);
@ -80,6 +86,8 @@ EventHandlerResult LayerFocus::onFocusEvent(const char *command) {
::Layer.activate(i);
}
}
} else {
return EventHandlerResult::OK;
}
return EventHandlerResult::EVENT_CONSUMED;

@ -27,7 +27,7 @@ namespace plugin {
class LayerFocus : public kaleidoscope::Plugin {
public:
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
};
} // namespace plugin

@ -16,7 +16,7 @@
#include "kaleidoscope/plugin/LayerNames.h"
#include <Arduino.h> // for delay, PSTR, strcmp_P, F, __FlashStri...
#include <Arduino.h> // for delay, PSTR, F, __FlashStri...
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
@ -31,11 +31,13 @@ EventHandlerResult LayerNames::onNameQuery() {
return ::Focus.sendName(F("LayerNames"));
}
EventHandlerResult LayerNames::onFocusEvent(const char *command) {
if (::Focus.handleHelp(command, PSTR("keymap.layerNames")))
return EventHandlerResult::OK;
EventHandlerResult LayerNames::onFocusEvent(const char *input) {
const char *cmd_layerNames = PSTR("keymap.layerNames");
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_layerNames);
if (strcmp_P(command, PSTR("keymap.layerNames")) != 0)
if (!::Focus.inputMatchesCommand(input, cmd_layerNames))
return EventHandlerResult::OK;
if (::Focus.isEOL()) {

@ -27,7 +27,7 @@ namespace plugin {
class LayerNames : public kaleidoscope::Plugin {
public:
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
void reserve_storage(uint16_t size);

@ -18,7 +18,7 @@
#include "kaleidoscope/plugin/PersistentLEDMode.h"
#include <Arduino.h> // for PSTR, strcmp_P, F, __FlashStringHelper
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t, uint16_t

@ -142,7 +142,7 @@ class SpaceCadet : public kaleidoscope::Plugin {
class SpaceCadetConfig : public kaleidoscope::Plugin {
public:
EventHandlerResult onSetup();
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
void disableSpaceCadetIfUnconfigured();

@ -19,7 +19,7 @@
#include "SpaceCadet.h"
#include "kaleidoscope/plugin/SpaceCadet.h"
#include <Arduino.h> // for F, __FlashStringHelper
#include <Arduino.h> // for PSTR
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <stdint.h> // for uint16_t, int8_t, uint8_t
@ -47,19 +47,14 @@ void SpaceCadetConfig::disableSpaceCadetIfUnconfigured() {
::SpaceCadet.disable();
}
EventHandlerResult SpaceCadetConfig::onFocusEvent(const char *command) {
EventHandlerResult SpaceCadetConfig::onFocusEvent(const char *input) {
const char *cmd_mode = PSTR("spacecadet.mode");
const char *cmd_timeout = PSTR("spacecadet.timeout");
// Note: These two calls are intentionally separate, because we want the side
// effects. If we were to use `||`, only one of them would run.
bool help_handled = ::Focus.handleHelp(command, cmd_mode);
help_handled |= ::Focus.handleHelp(command, cmd_timeout);
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_mode, cmd_timeout);
if (help_handled)
return EventHandlerResult::OK;
if (strcmp_P(command, cmd_mode) == 0) {
if (::Focus.inputMatchesCommand(input, cmd_mode)) {
if (::Focus.isEOL()) {
::Focus.send(::SpaceCadet.settings_.mode);
} else {
@ -81,7 +76,7 @@ EventHandlerResult SpaceCadetConfig::onFocusEvent(const char *command) {
Runtime.storage().put(settings_base_, ::SpaceCadet.settings_);
Runtime.storage().commit();
}
} else if (strcmp_P(command, cmd_timeout) == 0) {
} else if (::Focus.inputMatchesCommand(input, cmd_timeout)) {
if (::Focus.isEOL()) {
::Focus.send(::SpaceCadet.settings_.timeout);
} else {

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/TypingBreaks.h"
#include <Arduino.h> // for PSTR, strcmp_P, F, __FlashStringHelper
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint32_t, uint16_t
@ -139,7 +139,7 @@ EventHandlerResult TypingBreaks::onSetup() {
"typingbreaks.leftMaxKeys\r\n" \
"typingbreaks.rightMaxKeys")
EventHandlerResult TypingBreaks::onFocusEvent(const char *command) {
EventHandlerResult TypingBreaks::onFocusEvent(const char *input) {
enum {
IDLE_TIME_LIMIT,
LOCK_TIMEOUT,
@ -148,24 +148,27 @@ EventHandlerResult TypingBreaks::onFocusEvent(const char *command) {
RIGHT_MAX,
} subCommand;
if (::Focus.handleHelp(command, PSTR("typingbreaks.idleTimeLimit\r\n"
"typingbreaks.lockTimeOut\r\n"
"typingbreaks.lockLength\r\n"
"typingbreaks.leftMaxKeys\r\n"
"typingbreaks.rightMaxKeys")))
return EventHandlerResult::OK;
if (strncmp_P(command, PSTR("typingbreaks."), 13) != 0)
return EventHandlerResult::OK;
if (strcmp_P(command + 13, PSTR("idleTimeLimit")) == 0)
const char *cmd_idleTimeLimit = PSTR("typingbreaks.idleTimeLimit");
const char *cmd_lockTimeOut = PSTR("typingbreaks.lockTimeOut");
const char *cmd_lockLength = PSTR("typingbreaks.lockLength");
const char *cmd_leftMaxKeys = PSTR("typingbreaks.leftMaxKeys");
const char *cmd_rightMaxKeys = PSTR("typingbreaks.rightMaxKeys");
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_idleTimeLimit,
cmd_lockTimeOut,
cmd_lockLength,
cmd_leftMaxKeys,
cmd_rightMaxKeys);
if (::Focus.inputMatchesCommand(input, cmd_idleTimeLimit))
subCommand = IDLE_TIME_LIMIT;
else if (strcmp_P(command + 13, PSTR("lockTimeOut")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_lockTimeOut))
subCommand = LOCK_TIMEOUT;
else if (strcmp_P(command + 13, PSTR("lockLength")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_lockLength))
subCommand = LOCK_LENGTH;
else if (strcmp_P(command + 13, PSTR("leftMaxKeys")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_leftMaxKeys))
subCommand = LEFT_MAX;
else if (strcmp_P(command + 13, PSTR("rightMaxKeys")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_rightMaxKeys))
subCommand = RIGHT_MAX;
else
return EventHandlerResult::OK;

@ -40,7 +40,7 @@ class TypingBreaks : public kaleidoscope::Plugin {
EventHandlerResult onNameQuery();
EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
EventHandlerResult onSetup();
private:

@ -132,8 +132,8 @@ class Runtime_ {
return (elapsed_time >= ttl);
}
EventHandlerResult onFocusEvent(const char *command) {
return kaleidoscope::Hooks::onFocusEvent(command);
EventHandlerResult onFocusEvent(const char *input) {
return kaleidoscope::Hooks::onFocusEvent(input);
}
/** Handle a physical keyswitch event

@ -199,8 +199,8 @@ class SignatureCheckDummy {};
_CURRENT_IMPLEMENTATION, __NL__ \
_ABORTABLE, __NL__ \
(),(),(), /* non template */ __NL__ \
(const char *command), __NL__ \
(command), ##__VA_ARGS__) __NL__ \
(const char *input), __NL__ \
(input), ##__VA_ARGS__) __NL__ \
__NL__ \
/* Called when the layer state changes. Which layes changed are */ __NL__ \
/* not passed as arguments. If one needs that info, they should */ __NL__ \

@ -16,7 +16,7 @@
#include "kaleidoscope/plugin/LEDControl.h"
#include <Arduino.h> // for PSTR, strcmp_P, strncmp_P
#include <Arduino.h> // for PSTR, strncmp_P
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include "kaleidoscope/KeyAddrMap.h" // for KeyAddrMap<>::Iterator, KeyAddrMap
@ -212,7 +212,7 @@ EventHandlerResult LEDControl::afterEachCycle() {
return EventHandlerResult::OK;
}
EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
EventHandlerResult FocusLEDCommand::onFocusEvent(const char *input) {
enum {
SETALL,
MODE,
@ -224,24 +224,28 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
if (!Runtime.has_leds)
return EventHandlerResult::OK;
if (::Focus.handleHelp(command, PSTR("led.at\r\n"
"led.setAll\r\n"
"led.mode\r\n"
"led.brightness\r\n"
"led.theme")))
return EventHandlerResult::OK;
const char *cmd_at = PSTR("led.at");
const char *cmd_setAll = PSTR("led.setAll");
const char *cmd_mode = PSTR("led.mode");
const char *cmd_brightness = PSTR("led.brightness");
const char *cmd_theme = PSTR("led.theme");
if (strncmp_P(command, PSTR("led."), 4) != 0)
return EventHandlerResult::OK;
if (strcmp_P(command + 4, PSTR("at")) == 0)
if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_at,
cmd_setAll,
cmd_mode,
cmd_brightness,
cmd_theme);
if (::Focus.inputMatchesCommand(input, cmd_at))
subCommand = AT;
else if (strcmp_P(command + 4, PSTR("setAll")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_setAll))
subCommand = SETALL;
else if (strcmp_P(command + 4, PSTR("mode")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_mode))
subCommand = MODE;
else if (strcmp_P(command + 4, PSTR("theme")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_theme))
subCommand = THEME;
else if (strcmp_P(command + 4, PSTR("brightness")) == 0)
else if (::Focus.inputMatchesCommand(input, cmd_brightness))
subCommand = BRIGHTNESS;
else
return EventHandlerResult::OK;

@ -132,7 +132,7 @@ class FocusLEDCommand : public Plugin {
public:
FocusLEDCommand() {}
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onFocusEvent(const char *input);
};
} // namespace plugin

Loading…
Cancel
Save