From 0e5ec2943384f33bff0f6eb0895b262e8e07c973 Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Sun, 22 Jul 2018 21:22:48 -0700 Subject: [PATCH] Tweak the logic of the USB stack test --- right/src/usb_report_updater.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index f317792..2d82754 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -323,24 +323,23 @@ static void updateActiveUsbReports(void) bool layerGotReleased = previousLayer != LayerId_Base && activeLayer == LayerId_Base; LedDisplay_SetLayer(activeLayer); - static bool simulateKeypresses = false; - static bool isEven = false; - static bool isEvenMedia = false; - static uint32_t mediaCounter = 0; + if (TestUsbStack) { + static bool simulateKeypresses, isEven, isEvenMedia; + static uint32_t mediaCounter = 0; + key_state_t *testKeyState = &KeyStates[SlotId_LeftKeyboardHalf][0]; - key_state_t *testKeyState = &KeyStates[SlotId_LeftKeyboardHalf][0]; - if (TestUsbStack && !testKeyState->previous && testKeyState->current && activeLayer == LayerId_Fn) { - simulateKeypresses = !simulateKeypresses; - } - - if (simulateKeypresses) { - isEven = !isEven; - ActiveUsbBasicKeyboardReport->scancodes[basicScancodeIndex++] = isEven ? HID_KEYBOARD_SC_A : HID_KEYBOARD_SC_BACKSPACE; - if (++mediaCounter % 200 == 0) { - isEvenMedia = !isEvenMedia; - ActiveUsbMediaKeyboardReport->scancodes[mediaScancodeIndex++] = isEvenMedia ? MEDIA_VOLUME_DOWN : MEDIA_VOLUME_UP; + if (activeLayer == LayerId_Fn && testKeyState->current && !testKeyState->previous) { + simulateKeypresses = !simulateKeypresses; + } + if (simulateKeypresses) { + isEven = !isEven; + ActiveUsbBasicKeyboardReport->scancodes[basicScancodeIndex++] = isEven ? HID_KEYBOARD_SC_A : HID_KEYBOARD_SC_BACKSPACE; + if (++mediaCounter % 200 == 0) { + isEvenMedia = !isEvenMedia; + ActiveUsbMediaKeyboardReport->scancodes[mediaScancodeIndex++] = isEvenMedia ? MEDIA_VOLUME_DOWN : MEDIA_VOLUME_UP; + } + MouseMoveState.xOut = isEven ? -1 : 1; } - MouseMoveState.xOut = isEven ? -1 : 1; } for (uint8_t slotId=0; slotId