Code optimalization

Lift out the key updating code into a private method.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent 73c0f86d37
commit 00b836d0ac

@ -58,6 +58,12 @@ namespace KaleidoscopePlugins {
return keymapBase; return keymapBase;
} }
void
EEPROMKeymap::updateKey (uint16_t basePos, Key key) {
EEPROM.update (keymapBase + basePos * 2, key.flags);
EEPROM.update (keymapBase + basePos * 2 + 1, key.keyCode);
}
bool bool
EEPROMKeymap::focusKeymap (const char *command) { EEPROMKeymap::focusKeymap (const char *command) {
enum { enum {
@ -89,11 +95,12 @@ namespace KaleidoscopePlugins {
{ {
uint16_t i = 0; uint16_t i = 0;
while ((Serial.peek () != '\n') && (i < ROWS * COLS * maxLayers)) { while ((Serial.peek () != '\n') && (i < ROWS * COLS * maxLayers)) {
uint8_t flags = Serial.parseInt (); Key key;
uint8_t keyCode = Serial.parseInt ();
uint16_t pos = i * 2; key.flags = Serial.parseInt ();
EEPROM.update (keymapBase + pos, flags); key.keyCode = Serial.parseInt ();
EEPROM.update (keymapBase + pos + 1, keyCode); updateKey (i, key);
i++; i++;
} }
break; break;
@ -149,13 +156,12 @@ namespace KaleidoscopePlugins {
uint8_t layer = Serial.parseInt (); uint8_t layer = Serial.parseInt ();
uint8_t row = Serial.parseInt (); uint8_t row = Serial.parseInt ();
uint8_t col = Serial.parseInt (); uint8_t col = Serial.parseInt ();
uint8_t flags = Serial.parseInt (); Key key;
uint8_t keyCode = Serial.parseInt (); key.flags = Serial.parseInt ();
key.keyCode = Serial.parseInt ();
uint16_t pos = ((layer * ROWS * COLS) + (row * COLS) + col) * 2;
EEPROM.update (keymapBase + pos, flags); uint16_t pos = ((layer * ROWS * COLS) + (row * COLS) + col);
EEPROM.update (keymapBase + pos + 1, keyCode); updateKey (pos, key);
break; break;
} }
@ -167,10 +173,9 @@ namespace KaleidoscopePlugins {
for (uint8_t row = 0; row < ROWS; row++) { for (uint8_t row = 0; row < ROWS; row++) {
for (uint8_t col = 0; col < COLS; col++) { for (uint8_t col = 0; col < COLS; col++) {
Key k = Layer.getKeyFromPROGMEM (layer, row, col); Key k = Layer.getKeyFromPROGMEM (layer, row, col);
uint16_t pos = ((layer * ROWS * COLS) + (row * COLS) + col) * 2; uint16_t pos = ((layer * ROWS * COLS) + (row * COLS) + col);
EEPROM.update (keymapBase + pos, k.flags); updateKey (pos, k);
EEPROM.update (keymapBase + pos + 1, k.keyCode);
} }
} }

@ -55,6 +55,8 @@ namespace KaleidoscopePlugins {
private: private:
static uint16_t keymapBase; static uint16_t keymapBase;
static uint8_t maxLayers; static uint8_t maxLayers;
static void updateKey (uint16_t basePos, Key key);
}; };
}; };

Loading…
Cancel
Save