-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathxpt.c
64 lines (53 loc) · 1.3 KB
/
xpt.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include "xpt2046.h"
#define SPI_CHANNEL 0 // /dev/spidev0.0
//#define SPI_CHANNEL 1 // /dev/spidev0.1
#define GPIO_PEN 6
#define CALIBRATIO 0
int main (int argc, char **argv){
int x, y;
int xpos, ypos;
int pen_irq;
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);
#if(CALIBRATIO)
int xmin=99999;
int xmax=0;
int ymin=99999;
int ymax=0;
#endif
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 */
// Get physically position
xptGetxy(SPI_CHANNEL, &x, &y);
// Get scrren position
xpos = xptScrren(x);
ypos = yptScrren(y);
printf("touch !! x=%5d(%3d) y=%5d(%3d)\n", x, xpos, y, ypos);
#if(CALIBRATIO)
if (xmin > x) xmin=x;
if (xmax < x) xmax=x;
if (ymin > y) ymin=y;
if (ymax < y) ymax=y;
printf("touch !! xmin=%5d xmax=%5d\n", xmin, xmax);
printf("touch !! ymin=%5d ymax=%5d\n", ymin, ymax);
#endif
} else { /* pen is up */
}
} // end for
}