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

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

Loading…
Cancel
Save