-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.ino
106 lines (76 loc) · 2.64 KB
/
board.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//#include <Keyboard.h>
//#include "keyboard.h"
#include "config.h"
#include "keyboard_arduino.h"
#include "layouts.h"
#include <HardwareSerial.h>
using namespace Z;
const int dummy = 0;
// Teensy 3.0 has the LED on pin 13
const int ledPin = 13;
//This is ugly but it fixes an undefined reference to an STD function.
//Perhaps something should be logged
namespace std
{
void __throw_bad_function_call()
{
}
}
//uint8_t COL_PINS_RAW[WIDTH] = {7, 6, 8, 10, 11, 12};
uint8_t COL_PINS_RAW[WIDTH] = {12, 11, 10, 8, 6, 7};
uint8_t ROW_PINS_RAW[HEIGHT] = {2, 3, 4, 5};
auto COL_PINS =BoundedArray<uint8_t, WIDTH>(COL_PINS_RAW);
auto ROW_PINS =BoundedArray<uint8_t, HEIGHT>(ROW_PINS_RAW);
void setup()
{
// initialize the digital pin as an output.
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(115200);
Serial3.setTX(20);
//Serial3.setRX(7);
Serial1.begin(9600);
Serial3.begin(9600);
//keyboard.setup();
init_pins<WIDTH, HEIGHT>(ROW_PINS, COL_PINS);
delay(10); //Wait a while for the pull-up resistors to get ready
}
void loop()
{
auto old_packet = KeyPacket();
auto current_state = KeyboardState::NORMAL;
while(true)
{
auto self_keys = read_pressed_keys(ROW_PINS, COL_PINS);
#ifdef IS_SLAVE
auto bytes = coords_to_bytes(self_keys);
send_uart_bytes(bytes);
digitalWrite(ledPin, HIGH);
#else
//auto read_keys = read_pressed_keys(ROW_PINS, COL_PINS);
auto read_bytes = read_uart_byte_stream<(WIDTH * HEIGHT)*2 + 1>();
auto decoded_coordinates = decode_coordinates_from_bytes<WIDTH * HEIGHT>(read_bytes);
if(decoded_coordinates.error != CoordsFromBytesError::SUCCESS)
{
Serial.println("Got invalid bytes");
continue;
}
auto other_read_keys = decoded_coordinates.keys;
auto keymap = get_current_keymap(current_state);
auto full_coordinates = merge_coordinates(self_keys, other_read_keys,
[](KeyCoordinate coord) {
return KeyCoordinate(coord.x + WIDTH, coord.y);
});
auto translated = translate_coordinates<FULL_WIDTH, HEIGHT>(full_coordinates, keymap);
auto keytypes = keycodes_to_keytypes(translated);
keytypes.modifiers.push(get_state_modifier(current_state));
current_state = get_new_state(current_state, keytypes);
auto packet = keytypes_to_packet(keytypes, old_packet);
old_packet = packet;
send_packet(packet);
//state_manager.update_current_layer(keytypes);
digitalWrite(ledPin, HIGH);
#endif
delayMicroseconds(16000);
}
}