From a0a162ae9e3468364f7e37911870599761d3bce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Fri, 3 Nov 2017 03:17:46 +0100 Subject: [PATCH] Extend key states to include not only the current state but also the previous state and suppressed state. --- right/src/key_matrix_instance.h | 1 + right/src/key_states.c | 2 +- right/src/key_states.h | 10 +++++++++- right/src/main.c | 4 +++- right/src/slave_drivers/uhk_module_driver.c | 7 +++++-- right/src/usb_report_updater.c | 4 ++-- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/right/src/key_matrix_instance.h b/right/src/key_matrix_instance.h index 1541809..eec60e3 100644 --- a/right/src/key_matrix_instance.h +++ b/right/src/key_matrix_instance.h @@ -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: diff --git a/right/src/key_states.c b/right/src/key_states.c index 38d8cf2..3df46eb 100644 --- a/right/src/key_states.c +++ b/right/src/key_states.c @@ -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]; diff --git a/right/src/key_states.h b/right/src/key_states.h index 669ff0c..5ad3515 100644 --- a/right/src/key_states.h +++ b/right/src/key_states.h @@ -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 diff --git a/right/src/main.c b/right/src/main.c index b39cc31..45528d7 100644 --- a/right/src/main.c +++ b/right/src/main.c @@ -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(); diff --git a/right/src/slave_drivers/uhk_module_driver.c b/right/src/slave_drivers/uhk_module_driver.c index 40c7ed4..d2a3f6a 100644 --- a/right/src/slave_drivers/uhk_module_driver.c +++ b/right/src/slave_drivers/uhk_module_driver.c @@ -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; keyIdfeatures.keyCount; keyId++) { + KeyStates[slotId][keyId].current = keyStatesBuffer[keyId]; + } } status = kStatus_Uhk_NoTransfer; *uhkModulePhase = UhkModulePhase_JumpToBootloader; diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index 25f5ea9..4dfa536 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -78,7 +78,7 @@ uint8_t getActiveLayer(void) uint8_t activeLayer = LayerId_Base; for (uint8_t slotId=0; slotId