Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #341 from UltimateHackingKeyboard/fix_commit_state…
Browse files Browse the repository at this point in the history
…_race

Fix a possible race on key commitment.
  • Loading branch information
mondalaci authored Oct 23, 2024
2 parents 9c1ce33 + ebad54d commit 64c668d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions right/src/usb_report_updater.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,16 @@ static void commitKeyState(key_state_t *keyState, bool active)
static inline void preprocessKeyState(key_state_t *keyState)
{
uint8_t debounceTime = keyState->previous ? Cfg.DebounceTimePress : Cfg.DebounceTimeRelease;
if (keyState->debouncing && (uint8_t)(CurrentTime - keyState->timestamp) > debounceTime) {
if (keyState->debouncing && (uint8_t)(CurrentTime - keyState->timestamp) >= debounceTime) {
keyState->debouncing = false;
}

if (!keyState->debouncing && keyState->debouncedSwitchState != keyState->hardwareSwitchState) {
// read just once! Otherwise the key might get stuck
bool hardwareState = keyState->hardwareSwitchState;
if (!keyState->debouncing && keyState->debouncedSwitchState != hardwareState) {
keyState->timestamp = CurrentTime;
keyState->debouncing = true;
keyState->debouncedSwitchState = keyState->hardwareSwitchState;
keyState->debouncedSwitchState = hardwareState;

commitKeyState(keyState, keyState->debouncedSwitchState);
}
Expand Down

0 comments on commit 64c668d

Please sign in to comment.