Skip to content

Commit 7c1ab90

Browse files
committed
feat: momentary layer support
1 parent cf24f96 commit 7c1ab90

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/main.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ byte layoutLength = 0;
5656
String currentLayout = "";
5757
// For maximum 10 layers
5858
const short jsonDocSize = 16384;
59+
size_t tapToggleOrginalLayerIndex = 0;
60+
bool isTemporaryToggled = false;
5961

6062
byte inputs[] = {23, 19, 18, 5, 32, 33, 25}; // declaring inputs and outputs
6163
const int inputCount = sizeof(inputs) / sizeof(inputs[0]);
@@ -655,11 +657,25 @@ void loop() {
655657
.substring(6, sizeof(keyMap[r][c].keyInfo) - 1)
656658
.toInt();
657659
macroPress(macroMap[index]);
660+
} else if (keyMap[r][c].keyInfo.startsWith("TT_")) {
661+
// Tap-Toggle press
662+
if (!isTemporaryToggled) {
663+
size_t index =
664+
keyMap[r][c]
665+
.keyInfo
666+
.substring(3, sizeof(keyMap[r][c].keyInfo) - 1)
667+
.toInt();
668+
tapToggleActive(index);
669+
}
658670
} else {
659671
// Standard key press
660672
keyPress(keyMap[r][c]);
661673
}
662674
} else {
675+
if (keyMap[r][c].keyInfo.startsWith("TT_") &&
676+
isTemporaryToggled) {
677+
tapToggleRelease(tapToggleOrginalLayerIndex);
678+
}
663679
keyRelease(keyMap[r][c]);
664680
}
665681
delayMicroseconds(10);
@@ -884,6 +900,29 @@ void macroPress(Macro &macro) {
884900
delay(100);
885901
}
886902

903+
/**
904+
* Tap toggle layer
905+
*
906+
* @param {size_t} index of the layer to be toggled
907+
*/
908+
void tapToggleActive(size_t index) {
909+
isTemporaryToggled = true;
910+
tapToggleOrginalLayerIndex = currentLayoutIndex;
911+
currentLayoutIndex = index;
912+
initKeys();
913+
}
914+
915+
/**
916+
* Tap toggle layer release
917+
*
918+
* @param {size_t} original layer index of the layer to be restored
919+
*/
920+
void tapToggleRelease(size_t orginalLayerIndex) {
921+
isTemporaryToggled = false;
922+
currentLayoutIndex = orginalLayerIndex;
923+
initKeys();
924+
}
925+
887926
/**
888927
* Switch keymap layout
889928
*

src/main.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ bool keyPress(uint8_t keyStroke, String keyInfo, bool keyState);
9191
void keyRelease(Key &key);
9292
bool keyRelease(uint8_t keyStroke, String keyInfo, bool keyState);
9393
void macroPress(Macro &macro);
94+
void tapToggleActive(size_t index);
95+
void tapToggleRelease(size_t orginalLayerIndex);
9496
void switchLayout();
9597
void switchLayout(int layoutIndex);
9698
int findLayoutIndex(String layoutName);

0 commit comments

Comments
 (0)