Merge pull request #108 from algernon/f/layers/caching

Cache the keymap when changing layers
pull/110/head
Jesse Vincent 8 years ago committed by GitHub
commit ea11db914b

@ -5,6 +5,7 @@ static uint8_t DefaultLayer;
static uint32_t LayerState;
uint8_t Layer_::highestLayer;
uint8_t Layer_::keyMap[ROWS][COLS];
static void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.keyCode >= MOMENTARY_OFFSET) {
@ -51,18 +52,39 @@ Layer_::Layer_ (void) {
defaultLayer (0);
}
Key Layer_::lookup(byte row, byte col) {
Key mappedKey;
void
Layer_::mergeLayers(void) {
memset (keyMap, DefaultLayer, ROWS * COLS);
if (LayerState == (uint32_t)(1 << DefaultLayer))
return;
for (uint8_t r = 0; r < ROWS; r++) {
for (uint8_t c = 0; c < COLS; c++) {
int8_t layer = highestLayer;
mappedKey.raw = Key_Transparent.raw;
while (layer > DefaultLayer) {
if (Layer.isOn (layer)) {
Key mappedKey;
while (mappedKey.raw == Key_Transparent.raw &&
layer >= DefaultLayer) {
if (Layer.isOn (layer))
mappedKey.raw = pgm_read_word(&(keymaps[layer][row][col]));
mappedKey.raw = pgm_read_word(&(keymaps[layer][r][c]));
if (mappedKey != Key_Transparent) {
keyMap[r][c] = layer;
break;
}
}
layer--;
}
}
}
}
Key Layer_::lookup(byte row, byte col) {
uint8_t layer = keyMap[row][col];
Key mappedKey;
mappedKey.raw = pgm_read_word(&(keymaps[layer][row][col]));
return mappedKey;
}
@ -84,12 +106,14 @@ void Layer_::on (uint8_t layer) {
bitSet (LayerState, layer);
if (layer > highestLayer)
highestLayer = layer;
mergeLayers();
}
void Layer_::off (uint8_t layer) {
bitClear (LayerState, layer);
if (layer == highestLayer)
highestLayer = top();
mergeLayers();
}
boolean Layer_::isOn (uint8_t layer) {

@ -3,6 +3,7 @@
#include <Arduino.h>
#include "key_defs.h"
#include "plugin.h"
#include KALEIDOSCOPE_HARDWARE_H
class Layer_ {
public:
@ -28,6 +29,9 @@ class Layer_ {
private:
static uint8_t highestLayer;
static uint8_t keyMap[ROWS][COLS];
static void mergeLayers(void);
};
extern Layer_ Layer;

Loading…
Cancel
Save