-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtouch.c
191 lines (167 loc) · 4.2 KB
/
touch.c
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include "tft_lib.h"
#include "xpt2046.h"
#include "driver/ili9341.h"
#define SPI_CHANNEL 0 // /dev/spidev0.0
//#define SPI_CHANNEL 1 // /dev/spidev0.1
#define GPIO_PEN 6
#define _DEBUG_ 0
FontxFile fxG32[2];
FontxFile fxM32[2];
FontxFile fxG24[2];
FontxFile fxM24[2];
FontxFile fxG16[2];
FontxFile fxM16[2];
TouchInfo tinfo;
int main(int argc, char **argv){
int i,j;
uint16_t xpos,ypos;
uint16_t color;
uint8_t utf[64];
int XMAX,YMAX;
int XMAX2,YMAX2;
if (wiringPiSPISetup(SPI_CHANNEL, 500000) < 0) {
printf("wiringPiSPISetup failed:\n");
return -1;
}
if (wiringPiSetup() < 0) {
printf("wiringPiSetup failed:\n");
return -1;
}
pinMode(GPIO_PEN,INPUT);
char base[128];
strcpy(base, argv[0]);
for(i=strlen(base);i>0;i--) {
if (base[i-1] == '/') {
base[i] = 0;
break;
}
}
//printf("base=%s\n",base);
// You can change font file
// 32Dot Gothic
char G32[2][128];
strcpy(G32[0],base);
strcpy(G32[1],base);
strcat(G32[0],"fontx/ILGH32XB.FNT");
strcat(G32[1],"fontx/ILGZ32XB.FNT");
//printf("%s\n",G32[0]);
//printf("%s\n",G32[1]);
Fontx_init(fxG32,G32[0],G32[1]);
// 32Dot Mincho
char M32[2][128];
strcpy(M32[0],base);
strcpy(M32[1],base);
strcat(M32[0],"fontx/ILMH32XF.FNT");
strcat(M32[1],"fontx/ILMZ32XF.FNT");
//printf("%s\n",M32[0]);
//printf("%s\n",M32[1]);
Fontx_init(fxM32,M32[0],M32[1]);
// 24Dot Gothic
char G24[2][128];
strcpy(G24[0],base);
strcpy(G24[1],base);
strcat(G24[0],"fontx/ILGH24XB.FNT");
strcat(G24[1],"fontx/ILGZ24XB.FNT");
//printf("%s\n",G24[0]);
//printf("%s\n",G24[1]);
Fontx_init(fxG24,G24[0],G24[1]);
// 24Dot Mincho
char M24[2][128];
strcpy(M24[0],base);
strcpy(M24[1],base);
strcat(M24[0],"fontx/ILMH24XF.FNT");
strcat(M24[1],"fontx/ILMZ24XF.FNT");
//printf("%s\n",M24[0]);
//printf("%s\n",M24[1]);
Fontx_init(fxM24,M24[0],M24[1]);
#if 0
// 32Dot Gothic
Fontx_init(fxG32,"./fontx/ILGH32XB.FNT","./fontx/ILGZ32XB.FNT");
// 32Dot Mincho
Fontx_init(fxM32,"./fontx/ILMH32XF.FNT","./fontx/ILMZ32XF.FNT");
// 24Dot Gothic
Fontx_init(fxG24,"./fontx/ILGH24XB.FNT","./fontx/ILGZ24XB.FNT");
// 24Dot Mincho
Fontx_init(fxM24,"./fontx/ILMH24XF.FNT","./fontx/ILMZ24XF.FNT");
// 16Dot Gothic
Fontx_init(fxG16,"./fontx/ILGH16XB.FNT","./fontx/ILGZ16XB.FNT");
// 16Dot Mincho
Fontx_init(fxM16,"./fontx/ILMH16XB.FNT","./fontx/ILMZ16XF.FNT");
#endif
char ppath[128];
strcpy(ppath,base);
strcat(ppath,"pin.conf");
//printf("ppath=%s\n",ppath);
struct stat buffer;
if (stat(ppath, &buffer) != 0) {
printf("pin.conf [%s] not found\n",ppath);
return 1;
}
xptInit(&tinfo);
TFT_t dev;
lcdInterface(&dev, ppath);
lcdReset(&dev);
XMAX = 240;
YMAX = 320;
ili9341_lcdInit(&dev, XMAX, YMAX, 0, 0);
XMAX2 = XMAX - 1;
YMAX2 = YMAX - 1;
//drawString
lcdFillScreen(&dev, WHITE);
lcdSetFontDirection(&dev, DIRECTION90);
xpos = 180;
ypos = YMAX2-(32*1);
for (i=0;i<5;i++) {
lcdDrawRect(&dev, xpos-8, ypos+16, xpos+40, ypos-32, BLACK);
xptSetPoint(&tinfo, xpos-8 ,ypos+16 ,xpos+40, ypos-32, i);
xptDump(&tinfo);
color = BLACK;
//strcpy(utf,"1");
utf[0] = i + 48;
utf[1] = 0;
ypos = lcdDrawUTF8String(&dev, fxG32, xpos, ypos, utf, color);
ypos = ypos - 32;
}
xpos = 120;
ypos = YMAX2-(32*1);
for (i=0;i<5;i++) {
lcdDrawRect(&dev, xpos-8, ypos+16, xpos+40, ypos-32, BLACK);
xptSetPoint(&tinfo, xpos-8 ,ypos+16 ,xpos+40, ypos-32, i+5);
xptDump(&tinfo);
color = BLACK;
//strcpy(utf,"1");
utf[0] = i + 53;
utf[1] = 0;
ypos = lcdDrawUTF8String(&dev, fxG32, xpos, ypos, utf, color);
ypos = ypos - 32;
}
// read xpt2046
int x, y;
int pen_irq;
int id;
xpos = 40;
ypos = YMAX2-(32*1);
color = RED;
for (;;) {
usleep(10000); /* do it anyway ; settle time when pen goes up */
pen_irq = digitalRead(GPIO_PEN);
if (pen_irq == LOW) { /* PenIRQ is LOW : touch! pen is down */
id = xptGetPoint(SPI_CHANNEL, &tinfo);
if (id != -1) {
if(_DEBUG_)printf("id=%d\n",id);
ili9341_lcdInit(&dev, XMAX, YMAX, 0, 0);
lcdSetFontDirection(&dev, DIRECTION90);
utf[0] = id + 48;
ypos = lcdDrawUTF8String(&dev, fxG32, xpos, ypos, utf, color);
}
}
} // end for
}