Skip to content

Commit 42a9d87

Browse files
committed
Refactor key life log to last seen mechanics.
1 parent eb8826a commit 42a9d87

7 files changed

Lines changed: 35 additions & 21 deletions

File tree

right/src/debug.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,26 @@
2828

2929
#define DEBUG_BLE_LATENCY_STATS false
3030

31+
#include <stdint.h>
32+
#include "timer.h"
33+
34+
// Last-seen timestamps of the key event pipeline stages; printed by Hid_DumpTransportState.
35+
typedef struct {
36+
uint32_t scan;
37+
uint32_t queued;
38+
uint32_t forceQueued;
39+
uint32_t applied;
40+
uint32_t action;
41+
uint32_t delivered;
42+
} key_life_times_t;
43+
44+
extern key_life_times_t KeyLifeTimes;
45+
3146
#define DEBUG_KEY_LIFE_ENABLED true
3247
#if DEBUG_KEY_LIFE_ENABLED
33-
#define DEBUG_KEY_LIFE(ARG) ARG
48+
#define DEBUG_KEY_LIFE(STAGE) (KeyLifeTimes.STAGE = Timer_GetCurrentTime())
3449
#else
35-
#define DEBUG_KEY_LIFE(ARG)
50+
#define DEBUG_KEY_LIFE(STAGE)
3651
#endif
3752

3853
#ifdef __ZEPHYR__

right/src/hid/transport.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ extern "C" void Hid_DumpTransportState(void)
6161
(int)command_app::usb_handle().has_transport());
6262
c2usb_log(" powerMode=%d usbUp=%d usbAwake=%d\n",
6363
(int)CurrentPowerMode, (int)UsbState_IsTransportUp(), (int)UsbState_IsAwake());
64+
uint32_t now = Timer_GetCurrentTime();
65+
c2usb_log(" key life (ms ago): scan=%u queued=%u/forceQueued=%u/applied=%u action=%u delivered=%u\n",
66+
now - KeyLifeTimes.scan, now - KeyLifeTimes.queued, now - KeyLifeTimes.forceQueued,
67+
now - KeyLifeTimes.applied, now - KeyLifeTimes.action, now - KeyLifeTimes.delivered);
6468
c2usb_log(" semaphore (inFlight/retries/needsResend): kb=%d/%d/%d ctl=%d/%d/%d mouse=%d/%d/%d givenUp=%d\n",
6569
(int)UsbSemaphore.keyboard.inFlight, (int)UsbSemaphore.keyboard.retries, (int)UsbSemaphore.keyboard.needsResending,
6670
(int)UsbSemaphore.controls.inFlight, (int)UsbSemaphore.controls.retries, (int)UsbSemaphore.controls.needsResending,

right/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void CopyRightKeystateMatrix(void)
116116
}
117117

118118
if (KeyStates[SlotId_RightKeyboardHalf][targetKeyId].hardwareSwitchState != RightKeyMatrix.keyStates[keyId]) {
119-
DEBUG_KEY_LIFE(LOG_INF("%s %d scan\n", Utils_KeyStateToKeyAbbreviation(Utils_KeyIdToKeyState(targetKeyId)), RightKeyMatrix.keyStates[keyId]));
119+
DEBUG_KEY_LIFE(scan);
120120
KeyStates[SlotId_RightKeyboardHalf][targetKeyId].hardwareSwitchState = RightKeyMatrix.keyStates[keyId];
121121
stateChanged = true;
122122
}

right/src/slave_drivers/uhk_module_driver.c

Lines changed: 1 addition & 1 deletion
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(LOG_INF("%s %d scan\n", Utils_KeyStateToKeyAbbreviation(Utils_KeyIdToKeyState(slotId*64 + targetKeyId)), keyStatesBuffer[keyId]));
176+
DEBUG_KEY_LIFE(scan);
177177
KeyStates[slotId][targetKeyId].hardwareSwitchState = keyStatesBuffer[keyId];
178178
stateChanged = true;
179179
}

right/src/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void Trace_Print(log_target_t additionalLogTargets, const char* reason) {
5050
LogTo(targetDeviceId, targetInterface, "Uptime: %d ms, Last main: %d ms ago\n", currentTime, lastMain);
5151

5252
#ifndef __ZEPHYR__
53-
Trace_PrintUhk60ReasonRegisters(targetDeviceId, targetInterface);
53+
// Trace_PrintUhk60ReasonRegisters(targetDeviceId, targetInterface);
5454
#endif
5555

5656
LogTo(targetDeviceId, targetInterface, "Trace:\n");

right/src/usb_report_updater.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ static key_action_cached_t actionCache[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
7575
uint32_t UsbReportUpdater_LastActivityTime;
7676
uint32_t UsbReportUpdater_LastMouseActivityTime;
7777

78+
key_life_times_t KeyLifeTimes;
79+
7880

7981

8082

@@ -638,15 +640,13 @@ static void commitKeyState(key_state_t *keyState, bool active, uint8_t pressTime
638640

639641
if (PostponerCore_EventsShouldBeQueued() || forcePostponer) {
640642
PostponerCore_TrackKeyEvent(keyState, active, 255);
641-
if (DEBUG_KEY_LIFE_ENABLED) {
642-
if (forcePostponer) {
643-
LOG_INF(" %s %d force queued\n", Utils_KeyStateToKeyAbbreviation(keyState), active);
644-
} else {
645-
LOG_INF(" %s %d queued\n", Utils_KeyStateToKeyAbbreviation(keyState), active);
646-
}
643+
if (forcePostponer) {
644+
DEBUG_KEY_LIFE(forceQueued);
645+
} else {
646+
DEBUG_KEY_LIFE(queued);
647647
}
648648
} else {
649-
DEBUG_KEY_LIFE(LOG_INF(" %s %d applied\n", Utils_KeyStateToKeyAbbreviation(keyState), active));
649+
DEBUG_KEY_LIFE(applied);
650650
KEY_TIMING(KeyTiming_RecordKeystroke(keyState, active, Timer_GetCurrentTime(), Timer_GetCurrentTime()));
651651
keyState->current = active;
652652
}
@@ -759,13 +759,8 @@ static void updateActionStates() {
759759
if (KeyState_NonZero(keyState)) {
760760
Trace_Printc("w2");
761761

762-
if (DEBUG_KEY_LIFE_ENABLED) {
763-
if (KeyState_ActivatedNow(keyState)) {
764-
LOG_INF(" %s %d action\n", Utils_KeyStateToKeyAbbreviation(keyState), 1);
765-
}
766-
if (KeyState_DeactivatedNow(keyState)) {
767-
LOG_INF(" %s %d action\n", Utils_KeyStateToKeyAbbreviation(keyState), 0);
768-
}
762+
if (KeyState_ActivatedNow(keyState) || KeyState_DeactivatedNow(keyState)) {
763+
DEBUG_KEY_LIFE(action);
769764
}
770765

771766
if (KeyState_ActivatedNow(keyState)) {

right/src/usb_semaphore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ void UsbSemaphore_Clear(void) {
5151
}
5252

5353
void UsbSemaphore_Release(report_send_state_t* st) {
54-
if (DEBUG_KEY_LIFE_ENABLED && st == &UsbSemaphore.keyboard) {
55-
LOG_INF(" '%s' delivered\n", Utils_GetUsbReportString(ActiveKeyboardReport));
54+
if (st == &UsbSemaphore.keyboard) {
55+
DEBUG_KEY_LIFE(delivered);
5656
}
5757

5858
st->switchActiveReport();

0 commit comments

Comments
 (0)