From 0c387ce1c3edf221c1db0185165da21238431c04 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 19 Mar 2017 11:27:21 +0100 Subject: [PATCH] Focus: Lift out keymap.transfer The keymap.transfer command is only useful if we have both PROGMEM & EEPROM keymaps, which will rarely be a case, and likely only temporarily, too. As such, lift that out of the `focusKeymap` function, into its own. This makes the command optional, and can save us some 140 bytes of program space (even more if documentation is enabled). Signed-off-by: Gergely Nagy --- examples/EEPROM-Keymap/EEPROM-Keymap.ino | 1 + src/Kaleidoscope/EEPROM-Keymap-Focus.h | 11 +++++---- src/Kaleidoscope/EEPROM-Keymap.cpp | 30 ++++++++++++------------ src/Kaleidoscope/EEPROM-Keymap.h | 1 + 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/examples/EEPROM-Keymap/EEPROM-Keymap.ino b/examples/EEPROM-Keymap/EEPROM-Keymap.ino index f1127a23..30d39015 100644 --- a/examples/EEPROM-Keymap/EEPROM-Keymap.ino +++ b/examples/EEPROM-Keymap/EEPROM-Keymap.ino @@ -50,6 +50,7 @@ void setup () { Focus.addHook (FOCUS_HOOK_SETTINGS); Focus.addHook (FOCUS_HOOK_KEYMAP); + Focus.addHook (FOCUS_HOOK_KEYMAP_TRANSFER); Focus.addHook (FOCUS_HOOK_HELP); Focus.addHook (FOCUS_HOOK_VERSION); diff --git a/src/Kaleidoscope/EEPROM-Keymap-Focus.h b/src/Kaleidoscope/EEPROM-Keymap-Focus.h index 72103329..39ffbdc0 100644 --- a/src/Kaleidoscope/EEPROM-Keymap-Focus.h +++ b/src/Kaleidoscope/EEPROM-Keymap-Focus.h @@ -29,7 +29,10 @@ "-------------------------------\n" \ "Uploads a new keymap to EEPROM." \ "Starts at layer 0, row 0, column 0, " \ - "and continues as long as there is data on the line.\n\n" \ - "keymap.transfer layer\n" \ - "---------------------\n" \ - "Transfers the `layer` from PROGMEM to EEPROM.") + "and continues as long as there is data on the line.") + + +#define FOCUS_HOOK_KEYMAP_TRANSFER FOCUS_HOOK(EEPROMKeymap.focusKeymapTransfer, \ + "keymap.transfer layer\n" \ + "---------------------\n" \ + "Transfers the `layer` from PROGMEM to EEPROM.") diff --git a/src/Kaleidoscope/EEPROM-Keymap.cpp b/src/Kaleidoscope/EEPROM-Keymap.cpp index 41efc99f..126c0e77 100644 --- a/src/Kaleidoscope/EEPROM-Keymap.cpp +++ b/src/Kaleidoscope/EEPROM-Keymap.cpp @@ -86,7 +86,6 @@ namespace KaleidoscopePlugins { enum { UPLOAD, DUMP, - TRANSFER, } subCommand; if (strncmp_P (command, PSTR ("keymap."), 7) != 0) @@ -96,8 +95,6 @@ namespace KaleidoscopePlugins { subCommand = UPLOAD; else if (strcmp_P (command + 7, PSTR ("dump")) == 0) subCommand = DUMP; - else if (strcmp_P (command + 7, PSTR ("transfer")) == 0) - subCommand = TRANSFER; else return false; @@ -131,22 +128,25 @@ namespace KaleidoscopePlugins { break; } - case TRANSFER: - { - uint8_t layer = Serial.parseInt (); + } - for (uint8_t row = 0; row < ROWS; row++) { - for (uint8_t col = 0; col < COLS; col++) { - Key k = Layer.getKeyFromPROGMEM (layer, row, col); - uint16_t pos = ((layer * ROWS * COLS) + (row * COLS) + col); + return true; + } - updateKey (pos, k); - } - } + bool + EEPROMKeymap::focusKeymapTransfer (const char *command) { + if (strcmp_P (command, PSTR ("keymap.transfer")) != 0) + return false; - break; - } + uint8_t layer = Serial.parseInt (); + + for (uint8_t row = 0; row < ROWS; row++) { + for (uint8_t col = 0; col < COLS; col++) { + Key k = Layer.getKeyFromPROGMEM (layer, row, col); + uint16_t pos = ((layer * ROWS * COLS) + (row * COLS) + col); + updateKey (pos, k); + } } return true; diff --git a/src/Kaleidoscope/EEPROM-Keymap.h b/src/Kaleidoscope/EEPROM-Keymap.h index 14b5493c..02043a55 100644 --- a/src/Kaleidoscope/EEPROM-Keymap.h +++ b/src/Kaleidoscope/EEPROM-Keymap.h @@ -34,6 +34,7 @@ namespace KaleidoscopePlugins { static Key getKey (uint8_t layer, byte row, byte col); static bool focusKeymap (const char *command); + static bool focusKeymapTransfer (const char *command); private: static uint16_t keymapBase;