Skip to content

Commit

Permalink
added support for all keyboard keys
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintSampo committed Aug 16, 2024
1 parent dce6e2c commit 633f487
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 2 deletions.
123 changes: 123 additions & 0 deletions Keys.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#ifndef KEY_H
#define KEY_H

#include <inttypes.h>

// 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
15 changes: 14 additions & 1 deletion PestoLink-Receive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(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;
}
3 changes: 3 additions & 0 deletions PestoLink-Receive.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <inttypes.h>
#include <String.h>
#include <ArduinoBLE.h>
#include "Keys.h"

class PestoLinkParser {
public:
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=PestoLink-Receive
version=1.0.3
version=1.0.4
author=Alfredo Systems
maintainer=Jacob Williams ([email protected])
sentence=Library for communicating over BLE to PestoLink-Online.
Expand Down

0 comments on commit 633f487

Please sign in to comment.