Skip to content

Commit

Permalink
feat: momentary layer support
Browse files Browse the repository at this point in the history
  • Loading branch information
DriftKingTW committed Mar 20, 2023
1 parent cf24f96 commit 7c1ab90
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ byte layoutLength = 0;
String currentLayout = "";
// For maximum 10 layers
const short jsonDocSize = 16384;
size_t tapToggleOrginalLayerIndex = 0;
bool isTemporaryToggled = false;

byte inputs[] = {23, 19, 18, 5, 32, 33, 25}; // declaring inputs and outputs
const int inputCount = sizeof(inputs) / sizeof(inputs[0]);
Expand Down Expand Up @@ -655,11 +657,25 @@ void loop() {
.substring(6, sizeof(keyMap[r][c].keyInfo) - 1)
.toInt();
macroPress(macroMap[index]);
} else if (keyMap[r][c].keyInfo.startsWith("TT_")) {
// Tap-Toggle press
if (!isTemporaryToggled) {
size_t index =
keyMap[r][c]
.keyInfo
.substring(3, sizeof(keyMap[r][c].keyInfo) - 1)
.toInt();
tapToggleActive(index);
}
} else {
// Standard key press
keyPress(keyMap[r][c]);
}
} else {
if (keyMap[r][c].keyInfo.startsWith("TT_") &&
isTemporaryToggled) {
tapToggleRelease(tapToggleOrginalLayerIndex);
}
keyRelease(keyMap[r][c]);
}
delayMicroseconds(10);
Expand Down Expand Up @@ -884,6 +900,29 @@ void macroPress(Macro &macro) {
delay(100);
}

/**
* Tap toggle layer
*
* @param {size_t} index of the layer to be toggled
*/
void tapToggleActive(size_t index) {
isTemporaryToggled = true;
tapToggleOrginalLayerIndex = currentLayoutIndex;
currentLayoutIndex = index;
initKeys();
}

/**
* Tap toggle layer release
*
* @param {size_t} original layer index of the layer to be restored
*/
void tapToggleRelease(size_t orginalLayerIndex) {
isTemporaryToggled = false;
currentLayoutIndex = orginalLayerIndex;
initKeys();
}

/**
* Switch keymap layout
*
Expand Down
2 changes: 2 additions & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ bool keyPress(uint8_t keyStroke, String keyInfo, bool keyState);
void keyRelease(Key &key);
bool keyRelease(uint8_t keyStroke, String keyInfo, bool keyState);
void macroPress(Macro &macro);
void tapToggleActive(size_t index);
void tapToggleRelease(size_t orginalLayerIndex);
void switchLayout();
void switchLayout(int layoutIndex);
int findLayoutIndex(String layoutName);
Expand Down

0 comments on commit 7c1ab90

Please sign in to comment.