|
|
|
@ -4,8 +4,9 @@ static uint8_t DefaultLayer;
|
|
|
|
|
static uint32_t LayerState;
|
|
|
|
|
|
|
|
|
|
uint8_t Layer_::highestLayer;
|
|
|
|
|
uint8_t Layer_::keyMap[ROWS][COLS];
|
|
|
|
|
Key Layer_::keyMap[ROWS][COLS];
|
|
|
|
|
Key(*Layer_::getKey)(uint8_t layer, byte row, byte col) = Layer.getKeyFromPROGMEM;
|
|
|
|
|
bool Layer_::repeat_first_press = true;
|
|
|
|
|
|
|
|
|
|
static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) {
|
|
|
|
|
if (keymapEntry.keyCode >= MOMENTARY_OFFSET) {
|
|
|
|
@ -44,7 +45,8 @@ static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) {
|
|
|
|
|
* ignore held keys after releasing a layer key, until they are pressed
|
|
|
|
|
* again, to avoid the aforementioned issue.
|
|
|
|
|
*/
|
|
|
|
|
KeyboardHardware.maskHeldKeys();
|
|
|
|
|
if (!Layer.repeat_first_press)
|
|
|
|
|
KeyboardHardware.maskHeldKeys();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// switch keymap and stay there
|
|
|
|
@ -79,38 +81,21 @@ Layer_::getKeyFromPROGMEM(uint8_t layer, byte row, byte col) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Layer_::mergeLayers(void) {
|
|
|
|
|
Layer_::updateKeyCache(byte row, byte col) {
|
|
|
|
|
int8_t layer = highestLayer;
|
|
|
|
|
|
|
|
|
|
memset(keyMap, DefaultLayer, ROWS * COLS);
|
|
|
|
|
for (layer = highestLayer; layer >= DefaultLayer; layer--) {
|
|
|
|
|
if (Layer.isOn(layer)) {
|
|
|
|
|
Key mappedKey = (*getKey)(layer, row, col);
|
|
|
|
|
|
|
|
|
|
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 = (*getKey)(layer, r, c);
|
|
|
|
|
|
|
|
|
|
if (mappedKey != Key_Transparent) {
|
|
|
|
|
keyMap[r][c] = layer;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
layer--;
|
|
|
|
|
if (mappedKey != Key_Transparent) {
|
|
|
|
|
keyMap[row][col] = mappedKey;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Key Layer_::lookup(byte row, byte col) {
|
|
|
|
|
uint8_t layer = keyMap[row][col];
|
|
|
|
|
|
|
|
|
|
return (*getKey)(layer, row, col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t Layer_::top(void) {
|
|
|
|
|
for (int8_t i = 31; i >= 0; i--) {
|
|
|
|
|
if (bitRead(LayerState, i))
|
|
|
|
@ -128,14 +113,12 @@ 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) {
|
|
|
|
|