From a16d617279214b979e47da7123765571a4e36953 Mon Sep 17 00:00:00 2001 From: DriftKingTW Date: Wed, 18 Dec 2024 02:22:53 +0800 Subject: [PATCH] feat: rotary encoder macro support --- src/main.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6e60faa..11987d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -624,26 +624,88 @@ void encoderTask(void *pvParameters) { if (direction.equals("CCW")) { resetIdle(); + // USB mode if (isUsbMode && !isOutputLocked) { - usbKeyboard.release(onboardRotaryEncoders[0].rotaryCCW); - usbKeyboard.write(onboardRotaryEncoders[0].rotaryCCW); + if (onboardRotaryEncoders[0].rotaryCCWInfo.startsWith( + "MACRO_")) { + size_t index = + onboardRotaryEncoders[0] + .rotaryCCWInfo + .substring(6, sizeof(onboardRotaryEncoders[0] + .rotaryCCWInfo) - + 1) + .toInt(); + macroPress(macroMap[index]); + } else { + usbKeyboard.release(onboardRotaryEncoders[0].rotaryCCW); + usbKeyboard.write(onboardRotaryEncoders[0].rotaryCCW); + } + // BLE mode } else if (!isOutputLocked) { - bleKeyboard.release(onboardRotaryEncoders[0].rotaryCCW); - bleKeyboard.write(onboardRotaryEncoders[0].rotaryCCW); + if (onboardRotaryEncoders[0].rotaryCCWInfo.startsWith( + "MACRO_")) { + size_t index = + onboardRotaryEncoders[0] + .rotaryCCWInfo + .substring(6, sizeof(onboardRotaryEncoders[0] + .rotaryCCWInfo) - + 1) + .toInt(); + macroPress(macroMap[index]); + } else { + bleKeyboard.release(onboardRotaryEncoders[0].rotaryCCW); + bleKeyboard.write(onboardRotaryEncoders[0].rotaryCCW); + } + } + if (!onboardRotaryEncoders[0].rotaryCCWInfo.startsWith( + "MACRO_")) { + updateKeyInfo = true; + currentKeyInfo = onboardRotaryEncoders[0].rotaryCCWInfo; } - updateKeyInfo = true; - currentKeyInfo = onboardRotaryEncoders[0].rotaryCCWInfo; } else if (direction.equals("CW")) { resetIdle(); + // USB mode if (isUsbMode && !isOutputLocked) { - usbKeyboard.release(onboardRotaryEncoders[0].rotaryCW); - usbKeyboard.write(onboardRotaryEncoders[0].rotaryCW); + if (onboardRotaryEncoders[0].rotaryCWInfo.startsWith( + "MACRO_")) { + size_t index = + onboardRotaryEncoders[0] + .rotaryCWInfo + .substring( + 6, + sizeof( + onboardRotaryEncoders[0].rotaryCWInfo) - + 1) + .toInt(); + macroPress(macroMap[index]); + } else { + usbKeyboard.release(onboardRotaryEncoders[0].rotaryCW); + usbKeyboard.write(onboardRotaryEncoders[0].rotaryCW); + } + // BLE mode } else if (!isOutputLocked) { - bleKeyboard.release(onboardRotaryEncoders[0].rotaryCW); - bleKeyboard.write(onboardRotaryEncoders[0].rotaryCW); + if (onboardRotaryEncoders[0].rotaryCWInfo.startsWith( + "MACRO_")) { + size_t index = + onboardRotaryEncoders[0] + .rotaryCWInfo + .substring( + 6, + sizeof( + onboardRotaryEncoders[0].rotaryCWInfo) - + 1) + .toInt(); + macroPress(macroMap[index]); + } else { + bleKeyboard.release(onboardRotaryEncoders[0].rotaryCW); + bleKeyboard.write(onboardRotaryEncoders[0].rotaryCW); + } + } + if (!onboardRotaryEncoders[0].rotaryCWInfo.startsWith( + "MACRO_")) { + updateKeyInfo = true; + currentKeyInfo = onboardRotaryEncoders[0].rotaryCWInfo; } - updateKeyInfo = true; - currentKeyInfo = onboardRotaryEncoders[0].rotaryCWInfo; } }