-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboardScreen.ino
More file actions
executable file
·83 lines (65 loc) · 1.77 KB
/
KeyboardScreen.ino
File metadata and controls
executable file
·83 lines (65 loc) · 1.77 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
72
73
74
75
76
77
78
79
80
81
82
const char *keys = "1234567890qwertyuiopasdfghjkl;zxcvbnm,./ ";
const char *extra = "!@#$%^&*()QWERTYUIOPASDFGHJKL:ZXCVBNM<>? ";
int kml;
int kStartX = 0;
int kStartY = 0;
#define keyWidth 24
#define keySpace 5
void setKeyboardMaxLength(int l){
kml = l;
}
void drawKeyboard(void){
tft.fillScreen(LIGHTGRAY);
keyboardSL = 0;
for (int j = 0; j < 4; j++){
for (int i = 0; i < 10; i++){
int y = 90 + (keyWidth + keySpace) * j;
int x = i * (keyWidth + keySpace) + (j % 2) * 12 + 12;
int w = keyWidth;
int h = keyWidth;
char arr[2];
arr[0] = keys[j * 10 + i];
arr[1] = '\0';
Button *b = makeButton(x, y, w, h, DARKGRAY, WHITE, WHITE, arr, keyPress, j * 10 + i);
drawButton(b);
}
}
Button *b = makeButton(60, 208, 200, 24, DARKGRAY, WHITE, WHITE, " Space\0", keyPress, 40);
drawButton(b);
Button *e = makeButton(270, 208, 40, 24, DARKGRAY, WHITE, WHITE, "Exit\0", exitKeyboard, 0);
drawButton(e);
int maxX = 25;
if (kml < 25){
maxX = kml;
}
kStartX = 160 - maxX * 6;
kStartY = 10;
fillRect(kStartX, kStartY, maxX * 12 + 3, ((kml / 25) + 1) * 20, BLACK);
kStartX += 2;
kStartY += 2;
}
void exitKeyboard(int rip){
popState(0);
}
void keyPress(int num){
if (isNewTouch() && keyboardSL < kml){
keyboardS[keyboardSL] = keys[num];
char arr[2];
arr[0] = keys[num];
arr[1] = '\0';
drawText((keyboardSL % 25) * 12 + kStartX, (keyboardSL / 25) * 16 + kStartY, 2, arr, WHITE);
keyboardSL++;
}
}
void runKeyboard(void){
TSPoint p = getTouchPoint();
if (p.z == 500){
for (int i = 0; i < buttons->size(); i++){
Button *b = buttons->at(i);
if (p.x >= b->x && p.x < b->x + b->w && p.y >= b->y && p.y < b->y + b->h){
b->callFunc(b->p);
break;
}
}
}
}