Merge pull request #172 from keyboardio/h/update-key-cache-on-layer-change

Update the key cache on layer change and at keyboard setup
pull/175/head
Jesse Vincent 7 years ago committed by GitHub
commit 1c7cc32b2f

@ -14,6 +14,9 @@ Kaleidoscope_::setup(void) {
// A workaround, so that the compiler does not optimize this out...
handleKeyswitchEvent(Key_NoKey, 255, 255, 0);
// Update the key cache, so we start with a non-empty state.
Layer.updateKeyCache();
}
void

@ -80,6 +80,15 @@ Layer_::updateKeyCache(byte row, byte col) {
}
}
void
Layer_::updateKeyCache(void) {
for (byte row = 0; row < ROWS; row++) {
for (byte col = 0; col < COLS; col++) {
updateKeyCache(row, col);
}
}
}
uint8_t Layer_::top(void) {
for (int8_t i = 31; i >= 0; i--) {
if (bitRead(LayerState, i))
@ -97,12 +106,20 @@ void Layer_::on(uint8_t layer) {
bitSet(LayerState, layer);
if (layer > highestLayer)
highestLayer = layer;
// Update the key cache, so that if anything depends on knowing the active
// layout, the layout will be in sync.
updateKeyCache();
}
void Layer_::off(uint8_t layer) {
bitClear(LayerState, layer);
if (layer == highestLayer)
highestLayer = top();
// Update the key cache, so that if anything depends on knowing the active
// layout, the layout will be in sync.
updateKeyCache();
}
boolean Layer_::isOn(uint8_t layer) {

@ -33,6 +33,7 @@ class Layer_ {
static Key getKeyFromPROGMEM(uint8_t layer, byte row, byte col);
static void updateKeyCache(byte row, byte col);
static void updateKeyCache(void);
private:
static uint8_t highestLayer;

Loading…
Cancel
Save