Skip to content

Commit 7f785b3

Browse files
committed
Add a possible race fix.
1 parent 809b59d commit 7f785b3

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

right/src/slave_drivers/uhk_module_driver.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void UhkModuleSlaveDriver_ProcessKeystates(uint8_t uhkModuleDriverId, uhk_module
173173
}
174174

175175
if (KeyStates[slotId][targetKeyId].hardwareSwitchState != keyStatesBuffer[keyId]) {
176-
DEBUG_KEY_LIFE(scan);
176+
DEBUG_KEY_LIFE_SCAN(keyStatesBuffer[keyId]);
177177
KeyStates[slotId][targetKeyId].hardwareSwitchState = keyStatesBuffer[keyId];
178178
stateChanged = true;
179179
}
@@ -596,7 +596,18 @@ void UhkModuleSlaveDriver_Disconnect(uint8_t uhkModuleDriverId)
596596
uint8_t slotId = UhkModuleSlaveDriver_DriverIdToSlotId(uhkModuleDriverId);
597597

598598
if (IS_VALID_MODULE_SLOT(slotId)) {
599-
memset(KeyStates[slotId], 0, MAX_KEY_COUNT_PER_MODULE * sizeof(key_state_t));
599+
bool stateChanged = false;
600+
for (uint8_t keyId = 0; keyId < MAX_KEY_COUNT_PER_MODULE; keyId++) {
601+
if (KeyStates[slotId][keyId].hardwareSwitchState) {
602+
DEBUG_KEY_LIFE_SCAN(0);
603+
KeyStates[slotId][keyId].hardwareSwitchState = false;
604+
stateChanged = true;
605+
}
606+
}
607+
if (stateChanged) {
608+
EventVector_Set(EventVector_StateMatrix);
609+
EventVector_WakeMain();
610+
}
600611
}
601612

602613
EventScheduler_Schedule(Timer_GetCurrentTime() + MODULE_CONNECTION_TIMEOUT, EventSchedulerEvent_ModuleConnectionStatusUpdate, "ModuleConnectionStatusUpdate");

0 commit comments

Comments
 (0)