Skip to content

Commit ec58f01

Browse files
authored
Update core.ino
1 parent f0d0e7a commit ec58f01

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

core.ino

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22
#include <SPI.h>
33
#include <SD.h>
44
unsigned int d=500;
5-
const int c=31;
6-
String key[c]={"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"};
7-
uint8_t val[c]={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};
8-
void setup() {
9-
String dip = "";
10-
for (;dip.length()<8;dip+=!digitalRead(dip.length()+2))pinMode(dip.length() + 2, INPUT_PULLUP);
11-
if (!SD.begin(10))return;
12-
File file = SD.open(dip + ".txt");
13-
if (file) {
5+
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"};
6+
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};
7+
void setup(){
8+
String dip ="";
9+
for(;dip.length()<8;dip+=!digitalRead(dip.length()+2))pinMode(dip.length()+2,INPUT_PULLUP);
10+
if(!SD.begin(10))return;
11+
File file=SD.open(dip+".txt");
12+
if(file){
1413
Keyboard.begin();
1514
delay(500);
16-
String line = "";
17-
while (file.available()) {
18-
char m = file.read();
19-
if (m == 10) {
15+
String line="";
16+
while(file.available()){
17+
char m=file.read();
18+
if (m==10){
2019
Line(line);
21-
line = "";
20+
line="";
2221
}
23-
else if ((int)m != 13)line += m;
22+
else if((int)m!=13)line+=m;
2423
}
2524
Line(line);
2625
file.close();
@@ -29,39 +28,39 @@ void setup() {
2928
}
3029
}
3130
void Line(String l) {
32-
int sp = l.indexOf(" ");
33-
if (sp == -1)Press(l);
34-
else if (l.substring(0, sp) == "STRING")Keyboard.print(l.substring(sp + 1));
35-
else if (l.substring(0, sp) == "STRINGLN")Keyboard.println(l.substring(sp + 1));
36-
else if (l.substring(0, sp) == "DEFAULT_DELAY")d = l.substring(sp + 1).toInt();
37-
else if (l.substring(0, sp) == "DELAY")delay((l.substring(sp + 1) == "") ? d : l.substring(sp + 1).toInt());
38-
else if (l.substring(0, sp) == "REM");
31+
int sp=l.indexOf(" ");
32+
if(sp==-1)press(l);
33+
else if(l.substring(0,sp)=="STRING")Keyboard.print(l.substring(sp+1));
34+
else if(l.substring(0,sp)=="STRINGLN")Keyboard.println(l.substring(sp+1));
35+
else if(l.substring(0,sp)=="DEFAULT_DELAY")d=l.substring(sp+1).toInt();
36+
else if(l.substring(0,sp)=="DELAY")delay((l.substring(sp+1)=="")?d:l.substring(sp+1).toInt());
37+
else if(l.substring(0,sp)=="REM");
3938
else {
40-
String rest = l;
41-
while (rest.length() > 0) {
42-
int spx = rest.indexOf(" ");
43-
if (spx == -1) {
44-
Press(rest);
45-
rest = "";
46-
} else {
47-
Press(rest.substring(0, spx));
48-
rest = rest.substring(spx + 1);
39+
String rest=l;
40+
while(rest.length()>0){
41+
int spx=rest.indexOf(" ");
42+
if(spx==-1) {
43+
press(rest);
44+
rest="";
45+
}else{
46+
press(rest.substring(0,spx));
47+
rest=rest.substring(spx+1);
4948
}
5049
delay(500);
5150
}
5251
}
5352
Keyboard.releaseAll();
5453
}
55-
void Press(String b) {
54+
void press(String b) {
5655
if(b.length()==1)Keyboard.press(b[0]);
57-
else if (b.startsWith("BLK")){
56+
else if(b.startsWith("BLK")){
5857
Keyboard.press(0x80);
5958
Keyboard.press(0x81);
6059
if(b.endsWith("100"))Keyboard.print("u2588");
6160
else if(b.endsWith("75"))Keyboard.print("u2593");
6261
else if(b.endsWith("50"))Keyboard.print("u2592");
6362
else if(b.endsWith("25"))Keyboard.print("u2591");
6463
Keyboard.releaseAll();
65-
}else for(int i=0;i<c;i++)if(b.equals(key[i]))Keyboard.press(val[i]);
64+
}else for(int i=0;i<31;i++)if(b.equals(key[i]))Keyboard.press(val[i]);
6665
}
6766
void loop() {}

0 commit comments

Comments
 (0)