Amaury Pouly | d42b43c | 2016-10-20 18:21:00 +0200 | [diff] [blame] | 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" |
Amaury Pouly | 0a22906 | 2016-10-31 17:50:16 +0100 | [diff] [blame] | 22 | #include "nwz_plattools.h" |
Amaury Pouly | d42b43c | 2016-10-20 18:21:00 +0200 | [diff] [blame] | 23 | |
Amaury Pouly | 0a22906 | 2016-10-31 17:50:16 +0100 | [diff] [blame] | 24 | int NWZ_TOOL_MAIN(test_ts)(int argc, char **argv) |
Amaury Pouly | d42b43c | 2016-10-20 18:21:00 +0200 | [diff] [blame] | 25 | { |
| 26 | /* clear screen and display welcome message */ |
| 27 | nwz_lcdmsg(true, 0, 0, "test_ts"); |
Amaury Pouly | 794104d | 2016-10-26 20:40:53 +0200 | [diff] [blame] | 28 | nwz_lcdmsg(false, 0, 2, "BACK: quit"); |
Amaury Pouly | d42b43c | 2016-10-20 18:21:00 +0200 | [diff] [blame] | 29 | /* open input device */ |
| 30 | int key_fd = nwz_key_open(); |
| 31 | if(key_fd < 0) |
| 32 | { |
| 33 | nwz_lcdmsg(false, 3, 4, "Cannot open key device"); |
| 34 | sleep(2); |
| 35 | return 1; |
| 36 | } |
| 37 | int ts_fd = nwz_ts_open(); |
| 38 | if(ts_fd < 0) |
| 39 | { |
Amaury Pouly | 0a22906 | 2016-10-31 17:50:16 +0100 | [diff] [blame] | 40 | nwz_key_close(key_fd); |
Amaury Pouly | d42b43c | 2016-10-20 18:21:00 +0200 | [diff] [blame] | 41 | nwz_lcdmsg(false, 3, 4, "Cannot open touch screen device"); |
| 42 | sleep(2); |
| 43 | return 1; |
| 44 | } |
| 45 | /* init state and print maximum information */ |
| 46 | struct nwz_ts_state_t ts_state; |
| 47 | if(nwz_ts_state_init(ts_fd, &ts_state) < 0) |
| 48 | { |
Amaury Pouly | 0a22906 | 2016-10-31 17:50:16 +0100 | [diff] [blame] | 49 | nwz_key_close(key_fd); |
| 50 | nwz_ts_close(ts_fd); |
Amaury Pouly | d42b43c | 2016-10-20 18:21:00 +0200 | [diff] [blame] | 51 | nwz_lcdmsg(false, 3, 4, "Cannot init touch screen device"); |
| 52 | sleep(2); |
| 53 | return 1; |
| 54 | } |
| 55 | /* display static information */ |
| 56 | nwz_lcdmsgf(false, 1, 6, "size: %d, %d ", ts_state.max_x, ts_state.max_y); |
| 57 | /* display input state in a loop */ |
| 58 | while(1) |
| 59 | { |
| 60 | /* wait for event */ |
| 61 | int fds[2] = {key_fd, ts_fd}; |
| 62 | int ret = nwz_wait_fds(fds, 2, -1); |
| 63 | if(ret & 1) /* key_fd */ |
| 64 | { |
| 65 | struct input_event evt; |
| 66 | if(nwz_key_read_event(key_fd, &evt) == 1) |
| 67 | { |
Amaury Pouly | 794104d | 2016-10-26 20:40:53 +0200 | [diff] [blame] | 68 | if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_BACK && |
Amaury Pouly | d42b43c | 2016-10-20 18:21:00 +0200 | [diff] [blame] | 69 | nwz_key_event_is_press(&evt)) |
| 70 | break; /* quit */ |
| 71 | } |
| 72 | } |
| 73 | if(ret & 2) /* ts_fd */ |
| 74 | { |
| 75 | #define NR_TS_EVTS 16 |
| 76 | struct input_event evts[NR_TS_EVTS]; |
| 77 | int nr = nwz_ts_read_events(ts_fd, evts, NR_TS_EVTS); |
| 78 | for(int i = 0; i < nr; i++) |
| 79 | if(nwz_ts_state_update(&ts_state, &evts[i]) == 1) |
| 80 | { |
| 81 | nwz_lcdmsgf(false, 1, 7, "touch: %s ", ts_state.touch ? "yes" : "no"); |
| 82 | nwz_lcdmsgf(false, 1, 8, "pos: %d, %d ", ts_state.x, ts_state.y); |
| 83 | nwz_lcdmsgf(false, 1, 9, "pressure: %d ", ts_state.pressure); |
| 84 | nwz_lcdmsgf(false, 1, 10, "width: %d ", ts_state.tool_width); |
| 85 | nwz_lcdmsgf(false, 1, 11, "flick: %s ", ts_state.flick ? "yes" : "no"); |
| 86 | nwz_lcdmsgf(false, 1, 12, "flick vec: %d, %d ", ts_state.flick_x, ts_state.flick_y); |
| 87 | /* process touch */ |
| 88 | nwz_ts_state_post_syn(&ts_state); |
| 89 | } |
| 90 | #undef NR_TS_EVTS |
| 91 | } |
| 92 | } |
| 93 | /* close input device */ |
| 94 | nwz_key_close(key_fd); |
| 95 | nwz_ts_close(ts_fd); |
| 96 | /* finish nicely */ |
| 97 | return 0; |
| 98 | } |