Skip to content

Commit

Permalink
Merge pull request #1396 from keyboardio/f/size-optimization
Browse files Browse the repository at this point in the history
Size-optimizations
  • Loading branch information
obra authored Feb 26, 2024
2 parents 60874bc + 799e9b1 commit 2f62e3a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ EventHandlerResult FocusSerial::onFocusEvent(const char *input) {
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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@
#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"

Expand All @@ -46,11 +37,6 @@ class FocusSerial : public kaleidoscope::Plugin {
static constexpr char SEPARATOR = ' ';
static constexpr char NEWLINE = '\n';

#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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ EventHandlerResult LEDBrightnessConfig::onSetup() {
EventHandlerResult LEDBrightnessConfig::onFocusEvent(const char *command) {
const char *cmd = PSTR("led.brightness");

if (::Focus.handleHelp(command, cmd))
return EventHandlerResult::OK;
if (::Focus.inputMatchesHelp(command))
return ::Focus.printHelp(cmd);

if (strcmp_P(command, cmd) != 0)
return EventHandlerResult::OK;
if (strcmp_P(command, cmd) != 0) return EventHandlerResult::OK;

if (::Focus.isEOL()) {
::Focus.send(settings_.brightness);
Expand Down
71 changes: 34 additions & 37 deletions plugins/Kaleidoscope-Macros/src/kaleidoscope/plugin/Macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,35 @@ void Macros::play(const macro_t *macro_p) {
if (macro_p == MACRO_NONE)
return;


// Define a lambda function for common key operations to reduce redundancy
auto setKeyAndAction = [this, &key, &macro, &macro_p]() {
// Keycode variants of actions don't have flags to set, but we want to make sure
// we're still initializing them properly.

key.setFlags((macro == MACRO_ACTION_STEP_KEYCODEDOWN || macro == MACRO_ACTION_STEP_KEYCODEUP || macro == MACRO_ACTION_STEP_TAPCODE) ? 0
: pgm_read_byte(macro_p++));
key.setKeyCode(pgm_read_byte(macro_p++));

switch (macro) {
case MACRO_ACTION_STEP_KEYCODEDOWN:
case MACRO_ACTION_STEP_KEYDOWN:
this->press(key);
break;
case MACRO_ACTION_STEP_KEYCODEUP:
case MACRO_ACTION_STEP_KEYUP:
this->release(key);
break;
case MACRO_ACTION_STEP_TAP:
case MACRO_ACTION_STEP_TAPCODE:
this->tap(key);
break;
default:
break;
}
};


while (true) {
switch (macro = pgm_read_byte(macro_p++)) {
// These are unlikely to be useful now that we have KeyEvent. I think the
Expand All @@ -72,53 +101,21 @@ void Macros::play(const macro_t *macro_p) {
}

case MACRO_ACTION_STEP_KEYDOWN:
key.setFlags(pgm_read_byte(macro_p++));
key.setKeyCode(pgm_read_byte(macro_p++));
press(key);
break;
case MACRO_ACTION_STEP_KEYUP:
key.setFlags(pgm_read_byte(macro_p++));
key.setKeyCode(pgm_read_byte(macro_p++));
release(key);
break;
case MACRO_ACTION_STEP_TAP:
key.setFlags(pgm_read_byte(macro_p++));
key.setKeyCode(pgm_read_byte(macro_p++));
tap(key);
break;

case MACRO_ACTION_STEP_KEYCODEDOWN:
key.setFlags(0);
key.setKeyCode(pgm_read_byte(macro_p++));
press(key);
break;
case MACRO_ACTION_STEP_KEYCODEUP:
key.setFlags(0);
key.setKeyCode(pgm_read_byte(macro_p++));
release(key);
break;
case MACRO_ACTION_STEP_TAPCODE:
key.setFlags(0);
key.setKeyCode(pgm_read_byte(macro_p++));
tap(key);
setKeyAndAction();
break;

case MACRO_ACTION_STEP_TAP_SEQUENCE: {
while (true) {
key.setFlags(pgm_read_byte(macro_p++));
key.setKeyCode(pgm_read_byte(macro_p++));
if (key == Key_NoKey)
break;
tap(key);
delay(interval);
}
break;
}
case MACRO_ACTION_STEP_TAP_SEQUENCE:
case MACRO_ACTION_STEP_TAP_CODE_SEQUENCE: {
bool isKeycodeSequence = macro == MACRO_ACTION_STEP_TAP_CODE_SEQUENCE;
while (true) {
key.setFlags(0);
key.setFlags(isKeycodeSequence ? 0 : pgm_read_byte(macro_p++));
key.setKeyCode(pgm_read_byte(macro_p++));
if (key.getKeyCode() == 0)
if (key == Key_NoKey)
break;
tap(key);
delay(interval);
Expand Down

0 comments on commit 2f62e3a

Please sign in to comment.