Some small code optimizations

Lifted out a few things from the main `focusKeymap` method, to make code
size smaller.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent 80178956e4
commit 33f5d8d9de

@ -64,6 +64,32 @@ namespace KaleidoscopePlugins {
EEPROM.update (keymapBase + basePos * 2 + 1, key.keyCode); EEPROM.update (keymapBase + basePos * 2 + 1, key.keyCode);
} }
Key
EEPROMKeymap::parseKey (void) {
Key key;
key.flags = Serial.parseInt ();
key.keyCode = Serial.parseInt ();
return key;
}
void
EEPROMKeymap::printKey (Key k) {
if (k.flags < 10)
Serial.print (F(" "));
if (k.flags < 100)
Serial.print (F(" "));
Serial.print (k.flags);
Serial.print (F(" "));
if (k.keyCode < 10)
Serial.print (F(" "));
if (k.keyCode < 100)
Serial.print (F(" "));
Serial.print (k.keyCode);
}
bool bool
EEPROMKeymap::focusKeymap (const char *command) { EEPROMKeymap::focusKeymap (const char *command) {
enum { enum {
@ -95,12 +121,7 @@ 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)) {
Key key; updateKey (i, parseKey ());
key.flags = Serial.parseInt ();
key.keyCode = Serial.parseInt ();
updateKey (i, key);
i++; i++;
} }
break; break;
@ -114,9 +135,7 @@ namespace KaleidoscopePlugins {
Key k = getKey (layer, row, col); Key k = getKey (layer, row, col);
Serial.print (k.flags); printKey (k);
Serial.print (F(" "));
Serial.println (k.keyCode);
break; break;
} }
@ -128,18 +147,7 @@ namespace KaleidoscopePlugins {
for (uint8_t col = 0; col < COLS; col++) { for (uint8_t col = 0; col < COLS; col++) {
Key k = getKey (layer, row, col); Key k = getKey (layer, row, col);
if (k.flags < 10) printKey (k);
Serial.print (F(" "));
if (k.flags < 100)
Serial.print (F(" "));
Serial.print (k.flags);
Serial.print (F(" "));
if (k.keyCode < 10)
Serial.print (F(" "));
if (k.keyCode < 100)
Serial.print (F(" "));
Serial.print (k.keyCode);
if (col < COLS - 1) if (col < COLS - 1)
Serial.print (F(" | ")); Serial.print (F(" | "));
@ -156,12 +164,9 @@ 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 ();
Key key;
key.flags = Serial.parseInt ();
key.keyCode = Serial.parseInt ();
uint16_t pos = ((layer * ROWS * COLS) + (row * COLS) + col); uint16_t pos = ((layer * ROWS * COLS) + (row * COLS) + col);
updateKey (pos, key); updateKey (pos, parseKey ());
break; break;
} }

@ -37,6 +37,8 @@ namespace KaleidoscopePlugins {
static uint8_t maxLayers; static uint8_t maxLayers;
static void updateKey (uint16_t basePos, Key key); static void updateKey (uint16_t basePos, Key key);
static Key parseKey (void);
static void printKey (Key key);
}; };
}; };

Loading…
Cancel
Save