Extend key states to include not only the current state but also the previous state and suppressed state.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#define KEYBOARD_MATRIX_COLS_NUM 7
|
||||
#define KEYBOARD_MATRIX_ROWS_NUM 5
|
||||
#define KEYBOARD_MATRIX_KEY_COUNT (KEYBOARD_MATRIX_COLS_NUM * KEYBOARD_MATRIX_ROWS_NUM)
|
||||
|
||||
// Variables:
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#include "key_states.h"
|
||||
|
||||
uint8_t KeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||
key_state_t KeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||
|
||||
@@ -7,8 +7,16 @@
|
||||
#include "slot.h"
|
||||
#include "module.h"
|
||||
|
||||
// Typedefs:
|
||||
|
||||
typedef struct {
|
||||
bool previous;
|
||||
bool current;
|
||||
bool suppressed;
|
||||
} key_state_t;
|
||||
|
||||
// Variables:
|
||||
|
||||
extern uint8_t KeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||
extern key_state_t KeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,7 +28,9 @@ void UpdateUsbReports(void)
|
||||
KeyMatrix_Scan(&KeyMatrix);
|
||||
#endif
|
||||
|
||||
memcpy(KeyStates[SlotId_RightKeyboardHalf], KeyMatrix.keyStates, MAX_KEY_COUNT_PER_MODULE);
|
||||
for (uint8_t keyId=0; keyId < KEYBOARD_MATRIX_KEY_COUNT; keyId++) {
|
||||
KeyStates[SlotId_RightKeyboardHalf][keyId].current = KeyMatrix.keyStates[keyId];
|
||||
}
|
||||
|
||||
ResetActiveUsbBasicKeyboardReport();
|
||||
ResetActiveUsbMediaKeyboardReport();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "key_states.h"
|
||||
|
||||
uhk_module_state_t UhkModuleStates[UHK_MODULE_MAX_COUNT];
|
||||
|
||||
static uint8_t keyStatesBuffer[MAX_KEY_COUNT_PER_MODULE];
|
||||
static i2c_message_t txMessage;
|
||||
|
||||
static uhk_module_i2c_addresses_t moduleIdsToI2cAddresses[] = {
|
||||
@@ -172,7 +172,10 @@ status_t UhkModuleSlaveDriver_Update(uint8_t uhkModuleDriverId)
|
||||
case UhkModulePhase_ProcessKeystates:
|
||||
if (CRC16_IsMessageValid(rxMessage)) {
|
||||
uint8_t slotId = uhkModuleDriverId + 1;
|
||||
BoolBitsToBytes(rxMessage->data, KeyStates[slotId], uhkModuleState->features.keyCount);
|
||||
BoolBitsToBytes(rxMessage->data, keyStatesBuffer, uhkModuleState->features.keyCount);
|
||||
for (uint8_t keyId=0; keyId<uhkModuleState->features.keyCount; keyId++) {
|
||||
KeyStates[slotId][keyId].current = keyStatesBuffer[keyId];
|
||||
}
|
||||
}
|
||||
status = kStatus_Uhk_NoTransfer;
|
||||
*uhkModulePhase = UhkModulePhase_JumpToBootloader;
|
||||
|
||||
@@ -78,7 +78,7 @@ uint8_t getActiveLayer(void)
|
||||
uint8_t activeLayer = LayerId_Base;
|
||||
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
|
||||
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
|
||||
if (KeyStates[slotId][keyId]) {
|
||||
if (KeyStates[slotId][keyId].current) {
|
||||
key_action_t action = CurrentKeymap[LayerId_Base][slotId][keyId];
|
||||
if (action.type == KeyActionType_SwitchLayer) {
|
||||
activeLayer = action.switchLayer.layer;
|
||||
@@ -111,7 +111,7 @@ void UpdateActiveUsbReports(void)
|
||||
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
|
||||
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
|
||||
|
||||
if (!KeyStates[slotId][keyId]) {
|
||||
if (!KeyStates[slotId][keyId].current) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user