Fixed formatting

This commit is contained in:
Mattias Lasersköld 2020-03-14 10:56:54 +01:00
parent e053a7b4b0
commit 0f26e38b84
11 changed files with 122 additions and 111 deletions

View File

@ -1,2 +1,17 @@
BasedOnStyle: LLVM 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

View File

@ -23,8 +23,6 @@ keyboard_state_t state;
KeyboardMap keyboardMap(width, height, keyConfig1); KeyboardMap keyboardMap(width, height, keyConfig1);
void setup() { void setup() {
for (auto pin : xPins) { for (auto pin : xPins) {
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
@ -61,5 +59,3 @@ void loop() {
readRowPins(state, x); readRowPins(state, x);
} }
} }

View File

@ -4,7 +4,6 @@
#include "keyboardwritefunctions.h" #include "keyboardwritefunctions.h"
#include "keys.h" #include "keys.h"
//! A class for translating key coordinates to scancodes //! A class for translating key coordinates to scancodes
class KeyboardMap { class KeyboardMap {
size_t _width; size_t _width;
@ -15,7 +14,8 @@ class KeyboardMap {
public: public:
KeyboardMap(size_t width, size_t height, const char *values) KeyboardMap(size_t width, size_t height, const char *values)
: _width(width), _height(height), _size(width * height), : _width(width), _height(height), _size(width * height),
_translation(values) {} _translation(values) {
}
void publishEvent(size_t x, size_t y, bool keyValue) { void publishEvent(size_t x, size_t y, bool keyValue) {
size_t index = x + y * _width; size_t index = x + y * _width;
@ -23,7 +23,8 @@ public:
auto out = _translation[index]; auto out = _translation[index];
if (keyValue) { if (keyValue) {
writeKeyPress(out); writeKeyPress(out);
} else { }
else {
writeKeyRelease(out); writeKeyRelease(out);
} }
} }

View File

@ -8,6 +8,10 @@ public:
typedef char state_t; typedef char state_t;
// Todo: Bounds check // 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) const {
state_t &state(size_t x, size_t y) { return _state[y * width + x]; } return _state[y * width + x];
}
state_t &state(size_t x, size_t y) {
return _state[y * width + x];
}
}; };

View File

@ -12,6 +12,3 @@ constexpr size_t height = 5;
const char xPins[width] = {1, 2, 3, 4, 5, 6}; const char xPins[width] = {1, 2, 3, 4, 5, 6};
const char yPins[height] = {8, 9, 10, 11, 12}; const char yPins[height] = {8, 9, 10, 11, 12};

View File

@ -8,12 +8,14 @@
#include <iostream> #include <iostream>
using namespace std; using namespace std;
std::string scanCodeLookup(int code); // Defined in main
void writeKeyRelease(char key) { void writeKeyRelease(char key) {
cout << "Key released " << key << endl; cout << "Key released " << key << endl;
} }
void writeKeyPress(char key) { 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;
} }

View File

@ -8,12 +8,12 @@
#include "keys.h" #include "keys.h"
#include "matgui/application.h" #include "matgui/application.h"
#include "matgui/window.h"
#include "matgui/button.h" #include "matgui/button.h"
#include "matgui/window.h"
// Simulator // Simulator
#include "simio.h"
#include "keyboardwritefunctions.h" #include "keyboardwritefunctions.h"
#include "simio.h"
// The code // The code
#include "io.h" #include "io.h"
@ -23,6 +23,10 @@
using namespace std; using namespace std;
using namespace MatGui; using namespace MatGui;
std::string scanCodeLookup(int code) {
return Application::GetKeyNameFromScancode(code);
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
Application app(argc, argv); Application app(argc, argv);
@ -48,12 +52,7 @@ int main(int argc, char **argv) {
window.addChild(std::move(layout)); window.addChild(std::move(layout));
} }
window.frameUpdate.connect([]() { window.frameUpdate.connect([]() { loop(); });
loop();
});
app.mainLoop(); app.mainLoop();
} }

View File

@ -25,9 +25,8 @@
static class SerialPort { static class SerialPort {
public: public:
template <class T> template <class T>
void print(const T& value); void print(const T &value);
} Serial; } Serial;
@ -35,9 +34,8 @@ void digitalWrite(uint8_t pin, uint8_t value);
int digitalRead(uint8_t pin); int digitalRead(uint8_t pin);
void pinMode(uint8_t pin, uint8_t mode); void pinMode(uint8_t pin, uint8_t mode);
template<class T> template <class T>
inline void SerialPort::print(const T& value) inline void SerialPort::print(const T &value) {
{
std::cout << value << std::endl; std::cout << value << std::endl;
} }
@ -46,4 +44,3 @@ namespace simio {
void setSimKey(size_t x, size_t y, uint8_t state); void setSimKey(size_t x, size_t y, uint8_t state);
} }