diff --git a/software/.clang-format b/software/.clang-format new file mode 100644 index 0000000..8eebeaf --- /dev/null +++ b/software/.clang-format @@ -0,0 +1,2 @@ + +BasedOnStyle: LLVM diff --git a/software/arduino/keyboard/keyboard.ino b/software/arduino/keyboard/keyboard.ino index 423aeba..a9cfe27 100644 --- a/software/arduino/keyboard/keyboard.ino +++ b/software/arduino/keyboard/keyboard.ino @@ -1,8 +1,15 @@ +#include "keyboardmap.h" #include "keyboardstate.h" #include namespace { +const char *keyConfig1 = "ยง12345" + "\tQWERT" + "\177ASDFG" + "\129 yPins = {}; typedef KeyboardState keyboard_state_t; keyboard_state_t state; +KeyboardMap keyboardMap(width, height, keyConfig1); + } // namespace +void writeKeyRelease(char key) { + // Implement this +} + +void writeKeyPress(char key) { + // Implement this +} + void setup() { for (auto pin : xPins) { pinMode(pin, OUTPUT); @@ -33,7 +50,7 @@ void readRowPins(keyboard_state_t &keyboardState, size_t x) { auto &keyState = keyboardState.state(x, y); if (keyState != value) { - // Todo: Handle this + keyboardMap.publishEvent(x, y, keyState); Serial.print("key is changed"); keyState = value; } diff --git a/software/arduino/keyboard/keyboardmap.h b/software/arduino/keyboard/keyboardmap.h new file mode 100644 index 0000000..ec1b651 --- /dev/null +++ b/software/arduino/keyboard/keyboardmap.h @@ -0,0 +1,31 @@ + +#pragma once + +#include "keyboardwritefunctions.h" +#include "keys.h" + + +//! A class for translating key coordinates to scancodes +class KeyboardMap { + size_t _width; + size_t _height; + size_t _size; + const char *_translation; + +public: + KeyboardMap(size_t width, size_t height, const char *values) + : _width(width), _height(height), _size(width * height), + _translation(values) {} + + void publishEvent(size_t x, size_t y, bool keyValue) { + size_t index = x + y * _width; + if (index < _size) { + auto out = _translation[index]; + if (keyValue) { + writeKeyPress(out); + } else { + writeKeyRelease(out); + } + } + } +}; \ No newline at end of file diff --git a/software/arduino/keyboard/keyboardwritefunctions.h b/software/arduino/keyboard/keyboardwritefunctions.h new file mode 100644 index 0000000..88d6519 --- /dev/null +++ b/software/arduino/keyboard/keyboardwritefunctions.h @@ -0,0 +1,4 @@ +#pragma once + +void writeKeyRelease(char key); +void writeKeyPress(char key); \ No newline at end of file diff --git a/software/arduino/keyboard/keys.h b/software/arduino/keyboard/keys.h new file mode 100644 index 0000000..0813cf9 --- /dev/null +++ b/software/arduino/keyboard/keys.h @@ -0,0 +1,40 @@ +#pragma once +// Special keys: https://www.arduino.cc/en/Reference/KeyboardModifiers + +enum Keys { + LEFT_CTRL = 128, + LEFT_SHIFT = 129, + LEFT_ALT = 130, + LEFT_GUI = 131, + RIGHT_CTRL = 132, + RIGHT_SHIFT = 133, + RIGHT_ALT = 134, + RIGHT_GUI = 135, + UP_ARROW = 218, + DOWN_ARROW = 217, + LEFT_ARROW = 216, + RIGHT_ARROW = 215, + BACKSPACE = 178, + TAB = 179, + RETURN = 176, + ESC = 177, + INSERT = 209, + DELETE = 212, + PAGE_UP = 211, + PAGE_DOWN = 214, + HOME = 210, + END = 213, + CAPS_LOCK = 193, + F1 = 194, + F2 = 195, + F3 = 196, + F4 = 197, + F5 = 198, + F6 = 199, + F7 = 200, + F8 = 201, + F9 = 202, + F10 = 203, + F11 = 204, + F12 = 205, +}; \ No newline at end of file