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);
}
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
EEPROMKeymap::focusKeymap (const char *command) {
enum {
@ -95,12 +121,7 @@ namespace KaleidoscopePlugins {
{
uint16_t i = 0;
while ((Serial.peek () != '\n') && (i < ROWS * COLS * maxLayers)) {
Key key;
key.flags = Serial.parseInt ();
key.keyCode = Serial.parseInt ();
updateKey (i, key);
updateKey (i, parseKey ());
i++;
}
break;
@ -114,9 +135,7 @@ namespace KaleidoscopePlugins {
Key k = getKey (layer, row, col);
Serial.print (k.flags);
Serial.print (F(" "));
Serial.println (k.keyCode);
printKey (k);
break;
}
@ -128,18 +147,7 @@ namespace KaleidoscopePlugins {
for (uint8_t col = 0; col < COLS; col++) {
Key k = getKey (layer, row, col);
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);
printKey (k);
if (col < COLS - 1)
Serial.print (F(" | "));
@ -156,12 +164,9 @@ namespace KaleidoscopePlugins {
uint8_t layer = Serial.parseInt ();
uint8_t row = 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);
updateKey (pos, key);
updateKey (pos, parseKey ());
break;
}

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

Loading…
Cancel
Save