-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.ino
More file actions
71 lines (71 loc) · 2.47 KB
/
core.ino
File metadata and controls
71 lines (71 loc) · 2.47 KB
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
#include <Keyboard.h>
#include <SPI.h>
#include <SD.h>
unsigned int d = 500;
String key[31] = {"ENTER", "CTRL", "SHIFT", "ALT", "GUI", "UP", "DOWN", "LEFT", "RIGHT", "PAGEUP", "PAGEDOWN", "CAPSLOCK", "DELETE", "HOME", "ESC", "INSERT", "TAB", "END", "BACKSPACE", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12"};
uint8_t val[31] = {0xB0, 0x80, 0x81, 0x82, 0x83, 0xDA, 0xD9, 0xD8, 0xD7, 0xD3, 0xD6, 0xC1, 0xD4, 0xD2, 0xB1, 0xD1, 0xB3, 0xD5, 0xB2, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD};
void setup() {
String dip = "";
for (; dip.length() < 8; dip += !digitalRead(dip.length() + 2))pinMode(dip.length() + 2, INPUT_PULLUP);
delay(5000);
if (!SD.begin(10))return;
File file = SD.open(dip + ".txt");
if (file) {
Keyboard.begin();
delay(500);
String line = "";
while (file.available()) {
char m = file.read();
if (m == 10) {
xec(line);
line = "";
}
else if ((int)m != 13)line += m;
}
xec(line);
file.close();
Keyboard.end();
SD.end();
}
}
void xec(String l) {
int sp = l.indexOf(" ");
if (sp == -1)press(l);
else if (l.substring(0, sp) == "STRING")Keyboard.print(l.substring(sp + 1));
else if (l.substring(0, sp) == "STRINGLN")Keyboard.println(l.substring(sp + 1));
else if (l.substring(0, sp) == "DEFAULT_DELAY")d = l.substring(sp + 1).toInt();
else if (l.substring(0, sp) == "DELAY")delay((l.substring(sp + 1) == "") ? d : l.substring(sp + 1).toInt());
else if (l.substring(0, sp) == "REPEAT"){
int ll=l.substring(sp+1).indexOf(" "),rep=(l.substring(sp+1,ll)).toInt();
for(;rep>0;rep--)xec(l.substring(ll+1));
}
else if (l.substring(0, sp) == "REM");
else {
String rest = l;
while (rest.length() > 0) {
int spx = rest.indexOf(" ");
if (spx == -1) {
press(rest);
rest = "";
} else {
press(rest.substring(0, spx));
rest = rest.substring(spx + 1);
}
delay(500);
}
}
Keyboard.releaseAll();
}
void press(String b) {
if (b.length() == 1)Keyboard.press(b[0]);
else if (b.startsWith("BLK")) {
Keyboard.press(0x80);
Keyboard.press(0x81);
if (b.endsWith("100"))Keyboard.print("u2588");
else if (b.endsWith("75"))Keyboard.print("u2593");
else if (b.endsWith("50"))Keyboard.print("u2592");
else if (b.endsWith("25"))Keyboard.print("u2591");
Keyboard.releaseAll();
} else for (int i = 0; i < 31; i++)if (b.equals(key[i]))Keyboard.press(val[i]);
}
void loop() {}