-
Notifications
You must be signed in to change notification settings - Fork 9
/
touch.c
83 lines (71 loc) · 2.42 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
/*
* touch.c:
* Simple example how to use lib_XPT2046.h
* Copyright (c) 2013 Linus Pithan
*
*
***********************************************************************
* This file is part of lib_PD161704A:
* http://projects.pithan.net/lcd-touch-module/
*
* lib_PD161704A is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* lib_PD161704A is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with lib_PD161704A.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
//includes
#include "lib/lib_PD161704A.h"
#include "lib/lib_XPT2046.h"
#include <stdio.h>
void printPos(void)
{
unsigned short int x,y;
deactivate_irq();
if(get_touch_position(&x, &y)==1)
{
printf("Touch event at postion x=%i y=%i \n",x,y);
//draw dot
lcd_draw_dot(RED,x,y);
if(x<130 & x>60 & y<20)
{
lcd_clear_screen(GRAY);
lcd_draw_rect(BLACK,60, 0, 130, 20);
//write string to display
unsigned char str[16] = "press to clear!";
lcd_display_string_col_row(str,RED,BLACK,8,0);
unsigned char str2[11] = "draw here!";
lcd_display_string_col_row(str2,BLUE,GRAY,8,10);
}
}
reactivate_irq();
}
void main()
{
lcd_init(LIGHTBLUE);
init_touch();
set_touch_calib(0.133630, -18.240534, 0.178472, -22.353598); // To find the right parameter for your screen please use the touch_calibration app
lcd_draw_rect(BLACK,60, 0, 130, 20);
//write string to display
unsigned char str[16] = "press to clear!";
lcd_display_string_col_row(str,RED,BLACK,8,0);
unsigned char str2[11] = "draw here!";
lcd_display_string_col_row(str2,GREEN,BLUE,8,10);
if(register_touch_isr(&printPos)<0)
{printf("Unable to register touch isr\n");}
else{
printf("exit program with ctrl c !\n");
for (;;)
{;}
}
deactivate_irq();
}