summaryrefslogtreecommitdiff
path: root/utils/nwztools/plattools/test_ts.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/nwztools/plattools/test_ts.c')
-rw-r--r--utils/nwztools/plattools/test_ts.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/utils/nwztools/plattools/test_ts.c b/utils/nwztools/plattools/test_ts.c
new file mode 100644
index 0000000000..73e729a093
--- /dev/null
+++ b/utils/nwztools/plattools/test_ts.c
@@ -0,0 +1,94 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "nwz_lib.h"
22
23int main(int argc, char **argv)
24{
25 /* clear screen and display welcome message */
26 nwz_lcdmsg(true, 0, 0, "test_ts");
27 nwz_lcdmsg(false, 0, 2, "PWR OFF: quit");
28 /* open input device */
29 int key_fd = nwz_key_open();
30 if(key_fd < 0)
31 {
32 nwz_lcdmsg(false, 3, 4, "Cannot open key device");
33 sleep(2);
34 return 1;
35 }
36 int ts_fd = nwz_ts_open();
37 if(ts_fd < 0)
38 {
39 nwz_lcdmsg(false, 3, 4, "Cannot open touch screen device");
40 sleep(2);
41 return 1;
42 }
43 /* init state and print maximum information */
44 struct nwz_ts_state_t ts_state;
45 if(nwz_ts_state_init(ts_fd, &ts_state) < 0)
46 {
47 nwz_lcdmsg(false, 3, 4, "Cannot init touch screen device");
48 sleep(2);
49 return 1;
50 }
51 /* display static information */
52 nwz_lcdmsgf(false, 1, 6, "size: %d, %d ", ts_state.max_x, ts_state.max_y);
53 /* display input state in a loop */
54 while(1)
55 {
56 /* wait for event */
57 int fds[2] = {key_fd, ts_fd};
58 int ret = nwz_wait_fds(fds, 2, -1);
59 if(ret & 1) /* key_fd */
60 {
61 struct input_event evt;
62 if(nwz_key_read_event(key_fd, &evt) == 1)
63 {
64 if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_OPTION &&
65 nwz_key_event_is_press(&evt))
66 break; /* quit */
67 }
68 }
69 if(ret & 2) /* ts_fd */
70 {
71#define NR_TS_EVTS 16
72 struct input_event evts[NR_TS_EVTS];
73 int nr = nwz_ts_read_events(ts_fd, evts, NR_TS_EVTS);
74 for(int i = 0; i < nr; i++)
75 if(nwz_ts_state_update(&ts_state, &evts[i]) == 1)
76 {
77 nwz_lcdmsgf(false, 1, 7, "touch: %s ", ts_state.touch ? "yes" : "no");
78 nwz_lcdmsgf(false, 1, 8, "pos: %d, %d ", ts_state.x, ts_state.y);
79 nwz_lcdmsgf(false, 1, 9, "pressure: %d ", ts_state.pressure);
80 nwz_lcdmsgf(false, 1, 10, "width: %d ", ts_state.tool_width);
81 nwz_lcdmsgf(false, 1, 11, "flick: %s ", ts_state.flick ? "yes" : "no");
82 nwz_lcdmsgf(false, 1, 12, "flick vec: %d, %d ", ts_state.flick_x, ts_state.flick_y);
83 /* process touch */
84 nwz_ts_state_post_syn(&ts_state);
85 }
86#undef NR_TS_EVTS
87 }
88 }
89 /* close input device */
90 nwz_key_close(key_fd);
91 nwz_ts_close(ts_fd);
92 /* finish nicely */
93 return 0;
94}