Fixed formatting
This commit is contained in:
parent
e053a7b4b0
commit
0f26e38b84
@ -1,2 +1,17 @@
|
||||
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
SortIncludes: true
|
||||
AccessModifierOffset: -4
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
|
||||
AlwaysBreakAfterReturnType: None
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000000
|
@ -23,43 +23,39 @@ keyboard_state_t state;
|
||||
|
||||
KeyboardMap keyboardMap(width, height, keyConfig1);
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
for (auto pin : xPins) {
|
||||
pinMode(pin, OUTPUT);
|
||||
}
|
||||
for (auto pin : xPins) {
|
||||
pinMode(pin, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
//! Turn on one column pin and turn of the rest
|
||||
void changeColumnPin(size_t column) {
|
||||
for (size_t i = 0; i < width; ++i) {
|
||||
digitalWrite(xPins[i], i == column);
|
||||
}
|
||||
for (size_t i = 0; i < width; ++i) {
|
||||
digitalWrite(xPins[i], i == column);
|
||||
}
|
||||
}
|
||||
|
||||
void readRowPins(keyboard_state_t &keyboardState, size_t x) {
|
||||
for (size_t y = 0; y < height; ++y) {
|
||||
int value = digitalRead(yPins[y]);
|
||||
auto &storedKeyState = keyboardState.state(x, y);
|
||||
for (size_t y = 0; y < height; ++y) {
|
||||
int value = digitalRead(yPins[y]);
|
||||
auto &storedKeyState = keyboardState.state(x, y);
|
||||
|
||||
if (storedKeyState != value) {
|
||||
Serial.print("readRowPins: key is changed ");
|
||||
Serial.print(x);
|
||||
Serial.print(y);
|
||||
keyboardMap.publishEvent(x, y, value);
|
||||
storedKeyState = value;
|
||||
if (storedKeyState != value) {
|
||||
Serial.print("readRowPins: key is changed ");
|
||||
Serial.print(x);
|
||||
Serial.print(y);
|
||||
keyboardMap.publishEvent(x, y, value);
|
||||
storedKeyState = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Cycle through columns
|
||||
for (size_t x = 0; x < width; ++x) {
|
||||
changeColumnPin(x);
|
||||
// Cycle through columns
|
||||
for (size_t x = 0; x < width; ++x) {
|
||||
changeColumnPin(x);
|
||||
|
||||
readRowPins(state, x);
|
||||
}
|
||||
readRowPins(state, x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,9 +3,9 @@
|
||||
#include "io.h"
|
||||
|
||||
void writeKeyRelease(char key) {
|
||||
// Implement this
|
||||
// Implement this
|
||||
}
|
||||
|
||||
void writeKeyPress(char key) {
|
||||
// Implement this
|
||||
}
|
||||
// Implement this
|
||||
}
|
||||
|
@ -4,28 +4,29 @@
|
||||
#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;
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -2,12 +2,16 @@
|
||||
|
||||
template <size_t width, size_t height>
|
||||
class KeyboardState {
|
||||
char _state[width * height] = {};
|
||||
char _state[width * height] = {};
|
||||
|
||||
public:
|
||||
typedef char state_t;
|
||||
typedef char state_t;
|
||||
|
||||
// Todo: Bounds check
|
||||
state_t state(size_t x, size_t y) const { return _state[y * width + x]; }
|
||||
state_t &state(size_t x, size_t y) { return _state[y * width + x]; }
|
||||
// Todo: Bounds check
|
||||
state_t state(size_t x, size_t y) const {
|
||||
return _state[y * width + x];
|
||||
}
|
||||
state_t &state(size_t x, size_t y) {
|
||||
return _state[y * width + x];
|
||||
}
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void writeKeyRelease(char key);
|
||||
void writeKeyPress(char key);
|
||||
void writeKeyPress(char key);
|
||||
|
@ -2,39 +2,39 @@
|
||||
// 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,
|
||||
};
|
||||
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,
|
||||
};
|
||||
|
@ -12,6 +12,3 @@ constexpr size_t height = 5;
|
||||
|
||||
const char xPins[width] = {1, 2, 3, 4, 5, 6};
|
||||
const char yPins[height] = {8, 9, 10, 11, 12};
|
||||
|
||||
|
||||
|
||||
|
@ -8,12 +8,14 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
std::string scanCodeLookup(int code); // Defined in main
|
||||
|
||||
void writeKeyRelease(char key) {
|
||||
cout << "Key released " << key << endl;
|
||||
}
|
||||
|
||||
void writeKeyPress(char key) {
|
||||
cout << "keyboard.cpp: key pressed " << key << ", " << static_cast<unsigned>(key) << endl;
|
||||
cout << "keyboard.cpp: key pressed " << key << ", "
|
||||
<< static_cast<unsigned>(key) << endl;
|
||||
cout << "that is: " << scanCodeLookup(key) << endl;
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,12 +8,12 @@
|
||||
#include "keys.h"
|
||||
|
||||
#include "matgui/application.h"
|
||||
#include "matgui/window.h"
|
||||
#include "matgui/button.h"
|
||||
#include "matgui/window.h"
|
||||
|
||||
// Simulator
|
||||
#include "simio.h"
|
||||
#include "keyboardwritefunctions.h"
|
||||
#include "simio.h"
|
||||
|
||||
// The code
|
||||
#include "io.h"
|
||||
@ -23,6 +23,10 @@
|
||||
using namespace std;
|
||||
using namespace MatGui;
|
||||
|
||||
std::string scanCodeLookup(int code) {
|
||||
return Application::GetKeyNameFromScancode(code);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Application app(argc, argv);
|
||||
|
||||
@ -48,12 +52,7 @@ int main(int argc, char **argv) {
|
||||
window.addChild(std::move(layout));
|
||||
}
|
||||
|
||||
window.frameUpdate.connect([]() {
|
||||
loop();
|
||||
});
|
||||
window.frameUpdate.connect([]() { loop(); });
|
||||
|
||||
app.mainLoop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#define HIGH 0x1
|
||||
#define LOW 0x0
|
||||
#define LOW 0x0
|
||||
|
||||
#define INPUT 0x0
|
||||
#define OUTPUT 0x1
|
||||
@ -25,9 +25,8 @@
|
||||
|
||||
static class SerialPort {
|
||||
public:
|
||||
|
||||
template <class T>
|
||||
void print(const T& value);
|
||||
void print(const T &value);
|
||||
|
||||
} Serial;
|
||||
|
||||
@ -35,9 +34,8 @@ void digitalWrite(uint8_t pin, uint8_t value);
|
||||
int digitalRead(uint8_t pin);
|
||||
void pinMode(uint8_t pin, uint8_t mode);
|
||||
|
||||
template<class T>
|
||||
inline void SerialPort::print(const T& value)
|
||||
{
|
||||
template <class T>
|
||||
inline void SerialPort::print(const T &value) {
|
||||
std::cout << value << std::endl;
|
||||
}
|
||||
|
||||
@ -46,4 +44,3 @@ namespace simio {
|
||||
void setSimKey(size_t x, size_t y, uint8_t state);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user