From 633f487dd27c7cbe8f1122bad53419f21e9fb5e1 Mon Sep 17 00:00:00 2001 From: Jacob Williams <47766188+BotSpace@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:40:28 -0400 Subject: [PATCH] added support for all keyboard keys --- Keys.h | 123 ++++++++++++++++++++++++++++++++++++++++++ PestoLink-Receive.cpp | 15 +++++- PestoLink-Receive.h | 3 ++ library.properties | 2 +- 4 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 Keys.h diff --git a/Keys.h b/Keys.h new file mode 100644 index 0000000..4571c74 --- /dev/null +++ b/Keys.h @@ -0,0 +1,123 @@ +#ifndef KEY_H +#define KEY_H + +#include + +// For key name clarification, see https://w3c.github.io/uievents-code/#keyboard-key-codes +enum class Key : uint8_t { + // Alphanumeric + Backquote = 0, + Backslash = 1, + BracketLeft = 2, + BracketRight = 3, + Comma = 4, + Digit0 = 5, + Digit1 = 6, + Digit2 = 7, + Digit3 = 8, + Digit4 = 9, + Digit5 = 10, + Digit6 = 11, + Digit7 = 12, + Digit8 = 13, + Digit9 = 14, + Equal = 15, + IntlBackslash = 16, + IntlRo = 17, + IntlYen = 18, + A = 19, // KeyA + B = 20, // KeyB + C = 21, // KeyC + D = 22, // KeyD + E = 23, // KeyE + F = 24, // KeyF + G = 25, // KeyG + H = 26, // KeyH + I = 27, // KeyI + J = 28, // KeyJ + K = 29, // KeyK + L = 30, // KeyL + M = 31, // KeyM + N = 32, // KeyN + O = 33, // KeyO + P = 34, // KeyP + Q = 35, // KeyQ + R = 36, // KeyR + S = 37, // KeyS + T = 38, // KeyT + U = 39, // KeyU + V = 40, // KeyV + W = 41, // KeyW + X = 42, // KeyX + Y = 43, // KeyY + Z = 44, // KeyZ + Minus = 45, + Period = 46, + Quote = 47, + Semicolon = 48, + Slash = 49, + + // Functional + AltLeft = 50, + AltRight = 51, + Backspace = 52, + CapsLock = 53, + ContextMenu = 54, + ControlLeft = 55, + ControlRight = 56, + Enter = 57, + MetaLeft = 58, + MetaRight = 59, + ShiftLeft = 60, + ShiftRight = 61, + Space = 62, + Tab = 63, + + // Control Pad + Delete = 64, + End = 65, + Help = 66, + Home = 67, + Insert = 68, + PageDown = 69, + PageUp = 70, + ArrowDown = 71, + ArrowLeft = 72, + ArrowRight = 73, + ArrowUp = 74, + + // Numpad + NumLock = 75, + Numpad0 = 76, + Numpad1 = 77, + Numpad2 = 78, + Numpad3 = 79, + Numpad4 = 80, + Numpad5 = 81, + Numpad6 = 82, + Numpad7 = 83, + Numpad8 = 84, + Numpad9 = 85, + NumpadAdd = 86, + NumpadBackspace = 87, + NumpadClear = 88, + NumpadClearEntry = 89, + NumpadComma = 90, + NumpadDecimal = 91, + NumpadDivide = 92, + NumpadEnter = 93, + NumpadEqual = 94, + NumpadHash = 95, + NumpadMemoryAdd = 96, + NumpadMemoryClear = 97, + NumpadMemoryRecall = 98, + NumpadMemoryStore = 99, + NumpadMemorySubtract = 100, + NumpadMultiply = 101, + NumpadParenLeft = 102, + NumpadParenRight = 103, + NumpadStar = 104, + NumpadSubtract = 105, +}; + +#endif \ No newline at end of file diff --git a/PestoLink-Receive.cpp b/PestoLink-Receive.cpp index ecf4d0f..5e172cf 100644 --- a/PestoLink-Receive.cpp +++ b/PestoLink-Receive.cpp @@ -81,8 +81,21 @@ bool PestoLinkParser::buttonHeld(uint8_t button_num) { return (bool)((raw_buttons >> (button_num)) & 0x01); } +bool PestoLinkParser::keyHeld(Key key) { + + // Start checking from the 7th byte (index 7) to the 17th byte (index 17) + for (int i = 7; i < 18; ++i) { + uint8_t keyNum = (uint8_t)*(CharacteristicGamepad.value() + i); + if (keyNum == static_cast(key)) { + return true; + } + } + + // If the key is not found in the last 11 bytes, return false + return false; +} + void PestoLinkParser::setBatteryVal(float battery_val){ uint8_t batteryByte = 255.0 * battery_val / 12.0; - this->_batteryVal = batteryByte; } \ No newline at end of file diff --git a/PestoLink-Receive.h b/PestoLink-Receive.h index c402622..ffbc2ef 100644 --- a/PestoLink-Receive.h +++ b/PestoLink-Receive.h @@ -5,6 +5,7 @@ #include #include #include +#include "Keys.h" class PestoLinkParser { public: @@ -14,6 +15,8 @@ class PestoLinkParser { uint8_t getRawAxis(uint8_t button_num); bool buttonHeld(uint8_t button_num); void setBatteryVal(float battery_val); + bool keyHeld(Key key); + private: uint8_t _batteryVal = 0; diff --git a/library.properties b/library.properties index 69e9613..ff97f2f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PestoLink-Receive -version=1.0.3 +version=1.0.4 author=Alfredo Systems maintainer=Jacob Williams (jrw4561@gmail.com) sentence=Library for communicating over BLE to PestoLink-Online.