Skip to content

Commit

Permalink
Merge pull request #186 from UltimateHackingKeyboard/action-cache
Browse files Browse the repository at this point in the history
Extend the behavior of keys upon layer changes to keymap changes
  • Loading branch information
mondalaci authored Oct 6, 2018
2 parents f61acc4 + 06e34fd commit dba61c6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
2 changes: 0 additions & 2 deletions right/src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "config_parser/parse_keymap.h"
#include "config_parser/config_globals.h"
#include "macros.h"
#include "usb_report_updater.h"

keymap_reference_t AllKeymaps[MAX_KEYMAP_NUM] = {
{
Expand All @@ -25,7 +24,6 @@ void SwitchKeymapById(uint8_t index)
ValidatedUserConfigBuffer.offset = AllKeymaps[index].offset;
ParseKeymap(&ValidatedUserConfigBuffer, index, AllKeymapsCount, AllMacrosCount);
LedDisplay_UpdateText();
KeymapChanged = true;
}

bool SwitchKeymapByAbbreviation(uint8_t length, char *abbrev)
Expand Down
13 changes: 4 additions & 9 deletions right/src/usb_report_updater.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ static uint16_t DoubleTapSwitchLayerReleaseTimeout = 200;

static bool activeMouseStates[ACTIVE_MOUSE_STATES_COUNT];
bool TestUsbStack = false;
bool KeymapChanged = false;
static uint8_t layerCache[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
static key_action_t actionCache[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];

volatile uint8_t UsbReportUpdateSemaphore = 0;

Expand Down Expand Up @@ -335,8 +334,6 @@ static void updateActiveUsbReports(void)
if (layerChanged) {
stickyModifiers = 0;
}
bool keymapChangedLastCycle = KeymapChanged;
KeymapChanged = false;
LedDisplay_SetLayer(activeLayer);

if (TestUsbStack) {
Expand Down Expand Up @@ -383,16 +380,14 @@ static void updateActiveUsbReports(void)
secondaryRoleState = SecondaryRoleState_Triggered;
keyState->current = false;
} else {
layerCache[slotId][keyId] = activeLayer;
actionCache[slotId][keyId] = CurrentKeymap[activeLayer][slotId][keyId];
}
}

action = &CurrentKeymap[layerCache[slotId][keyId]][slotId][keyId];
action = &actionCache[slotId][keyId];

if (keyState->current) {
if ((KeymapChanged || keymapChangedLastCycle) && keyState->previous) {
keyState->suppressed = true;
} else if (action->type == KeyActionType_Keystroke && action->keystroke.secondaryRole) {
if (action->type == KeyActionType_Keystroke && action->keystroke.secondaryRole) {
// Press released secondary role key.
if (!keyState->previous && secondaryRoleState == SecondaryRoleState_Released) {
secondaryRoleState = SecondaryRoleState_Pressed;
Expand Down
1 change: 0 additions & 1 deletion right/src/usb_report_updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
extern uint32_t UsbReportUpdateCounter;
extern volatile uint8_t UsbReportUpdateSemaphore;
extern bool TestUsbStack;
extern bool KeymapChanged;

// Functions:

Expand Down

0 comments on commit dba61c6

Please sign in to comment.