Started sketching on keyboard lookup
This commit is contained in:
parent
4176eac3cd
commit
5b31f9bfa2
2
software/.clang-format
Normal file
2
software/.clang-format
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
BasedOnStyle: LLVM
|
@ -1,8 +1,15 @@
|
|||||||
|
#include "keyboardmap.h"
|
||||||
#include "keyboardstate.h"
|
#include "keyboardstate.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
const char *keyConfig1 = "§12345"
|
||||||
|
"\tQWERT"
|
||||||
|
"\177ASDFG"
|
||||||
|
"\129<ZXCV"
|
||||||
|
"\128\131\130 ";
|
||||||
|
|
||||||
constexpr size_t width = 6;
|
constexpr size_t width = 6;
|
||||||
constexpr size_t height = 5;
|
constexpr size_t height = 5;
|
||||||
|
|
||||||
@ -12,8 +19,18 @@ const std::array<char, height> yPins = {};
|
|||||||
typedef KeyboardState<width, height> keyboard_state_t;
|
typedef KeyboardState<width, height> keyboard_state_t;
|
||||||
keyboard_state_t state;
|
keyboard_state_t state;
|
||||||
|
|
||||||
|
KeyboardMap keyboardMap(width, height, keyConfig1);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void writeKeyRelease(char key) {
|
||||||
|
// Implement this
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeKeyPress(char key) {
|
||||||
|
// Implement this
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
for (auto pin : xPins) {
|
for (auto pin : xPins) {
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
@ -33,7 +50,7 @@ void readRowPins(keyboard_state_t &keyboardState, size_t x) {
|
|||||||
auto &keyState = keyboardState.state(x, y);
|
auto &keyState = keyboardState.state(x, y);
|
||||||
|
|
||||||
if (keyState != value) {
|
if (keyState != value) {
|
||||||
// Todo: Handle this
|
keyboardMap.publishEvent(x, y, keyState);
|
||||||
Serial.print("key is changed");
|
Serial.print("key is changed");
|
||||||
keyState = value;
|
keyState = value;
|
||||||
}
|
}
|
||||||
|
31
software/arduino/keyboard/keyboardmap.h
Normal file
31
software/arduino/keyboard/keyboardmap.h
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
4
software/arduino/keyboard/keyboardwritefunctions.h
Normal file
4
software/arduino/keyboard/keyboardwritefunctions.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void writeKeyRelease(char key);
|
||||||
|
void writeKeyPress(char key);
|
40
software/arduino/keyboard/keys.h
Normal file
40
software/arduino/keyboard/keys.h
Normal file
@ -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,
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user