You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.4 KiB
C++

#include <USBComposite.h>
int key_L1 = 4; // braille dot 1 - binary 32
int key_L2 = 5; // dot 2 - binary 16
int key_L3 = 6; // dot 3 - binary 8
int key_R1 = 7; // dot 4 - binary 4
int key_R2 = 8; // dot 5 - binary 2
int key_R3 = 9; // dot 6 - binary 1
int key_SPACE = 10;
int key_SHIFT = 11; // TODO: probably should support differentiation of L/R shift
/*
the keyMap uses a braille alphabet (6-bit values) from ASCII Braille
// TODO: add other keyMaps for other braille or alternative
// chording/encoding systems
*/
char keyMap[65];
int lastKey = -1;
USBHID HID;
HIDKeyboard Keyboard(HID);
void setup() {
pinMode(key_L1, INPUT_PULLUP);
pinMode(key_L2, INPUT_PULLUP);
pinMode(key_L3, INPUT_PULLUP);
pinMode(key_R1, INPUT_PULLUP);
pinMode(key_R2, INPUT_PULLUP);
pinMode(key_R3, INPUT_PULLUP);
// TODO: there is probably a more RAM-saving way to do this with #DEFINE or
// similar preprocessor magic
keyMap[0] = ' ';
keyMap[0b100] = '@';
keyMap[0b100000] = 'a';
keyMap[0b110000] = 'b';
keyMap[0b100100] = 'c';
keyMap[0b100110] = 'd';
keyMap[0b100010] = 'e';
keyMap[0b110100] = 'f';
keyMap[0b110110] = 'g';
keyMap[0b110010] = 'h';
keyMap[0b10100] = 'i';
keyMap[0b10110] = 'j';
keyMap[0b101000] = 'k';
keyMap[0b111000] = 'l';
keyMap[0b101100] = 'm';
keyMap[0b101110] = 'n';
keyMap[0b101010] = 'o';
keyMap[0b111100] = 'p';
keyMap[0b111110] = 'q';
keyMap[0b111010] = 'r';
keyMap[0b11100] = 's';
keyMap[0b11110] = 't';
keyMap[0b101001] = 'u';
keyMap[0b111001] = 'v';
keyMap[0b10111] = 'w';
keyMap[0b101101] = 'x';
keyMap[0b101111] = 'y';
keyMap[0b101011] = 'z';
keyMap[0b10101] = '[';
keyMap[0b110011] = '\\';
keyMap[0b110111] = ']';
keyMap[0b110] = '^';
keyMap[0b111] = '_';
keyMap[0b11101] = '!';
keyMap[0b10] = '"';
keyMap[0b1111] = '#';
keyMap[0b110101] = '$';
keyMap[0b100101] = '%';
keyMap[0b111101] = '&';
keyMap[0b1000] = '\'';
keyMap[0b111011] = '(';
keyMap[0b11111] = ')';
keyMap[0b100001] = '*';
keyMap[0b1101] = '+';
keyMap[0b1] = ',';
keyMap[0b1001] = '-';
keyMap[0b101] = '.';
keyMap[0b1100] = '/';
keyMap[0b1011] = '0';
keyMap[0b10000] = '1';
keyMap[0b11000] = '2';
keyMap[0b10010] = '3';
keyMap[0b10011] = '4';
keyMap[0b10001] = '5';
keyMap[0b11010] = '6';
keyMap[0b11011] = '7';
keyMap[0b11001] = '8';
keyMap[0b1010] = '9';
keyMap[0b100011] = ':';
keyMap[0b11] = ';';
keyMap[0b110001] = '<';
keyMap[0b111111] = '=';
keyMap[0b1110] = '>';
keyMap[0b100111] = '?';
HID.begin(HID_KEYBOARD);
while (!USBComposite);
Keyboard.begin();
}
void loop() {
int key = -1;
if (digitalRead(key_L1) == LOW) {
key += 32;
}
if (digitalRead(key_L2) == LOW) {
key += 16;
}
if (digitalRead(key_L3) == LOW) {
key += 8;
}
if (digitalRead(key_R1) == LOW) {
key += 4;
}
if (digitalRead(key_R2) == LOW) {
key += 2;
}
if (digitalRead(key_R3) == LOW) {
key += 1;
}
if (digitalRead(key_SPACE) == LOW) {
key = 0;
}
if ((key != lastKey) && (key != -1)) {
char key_out = keyMap[key];
// check for shift
// TODO: either use STD::TOUPPER or make this more proper for extended chars
if (digitalRead(key_SHIFT) == LOW) {
key_out &= ~' ';
}
// TODO: send proper keydown and keyup so key-repeat works on OS level.
Keyboard.print(key_out);
}
lastKey = key;
delay(100);
}