diff options
Diffstat (limited to 'firmware/target/hosted/sonynwz/button-nwz.c')
-rw-r--r-- | firmware/target/hosted/sonynwz/button-nwz.c | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/firmware/target/hosted/sonynwz/button-nwz.c b/firmware/target/hosted/sonynwz/button-nwz.c index 0cbb3c5869..3be74fc924 100644 --- a/firmware/target/hosted/sonynwz/button-nwz.c +++ b/firmware/target/hosted/sonynwz/button-nwz.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <fcntl.h> | 35 | #include <fcntl.h> |
36 | #include <string.h> | 36 | #include <string.h> |
37 | #include <stdlib.h> | 37 | #include <stdlib.h> |
38 | #include <system.h> | ||
38 | 39 | ||
39 | /* device types */ | 40 | /* device types */ |
40 | #define DEV_KEY 0 /* icx_keys driver */ | 41 | #define DEV_KEY 0 /* icx_keys driver */ |
@@ -70,64 +71,64 @@ static bool touch_detect; | |||
70 | /* get touchscreen information and init state */ | 71 | /* get touchscreen information and init state */ |
71 | int ts_init_state(int fd) | 72 | int ts_init_state(int fd) |
72 | { | 73 | { |
73 | memset(state, 0, sizeof(struct nwz_ts_state_t)); | 74 | memset(&ts_state, 0, sizeof(ts_state)); |
74 | struct input_absinfo info; | 75 | struct input_absinfo info; |
75 | if(ioctl(fd, EVIOCGABS(ABS_X), &info) < 0) | 76 | if(ioctl(fd, EVIOCGABS(ABS_X), &info) < 0) |
76 | return -1; | 77 | return -1; |
77 | state->max_x = info.maximum; | 78 | ts_state.max_x = info.maximum; |
78 | if(ioctl(fd, EVIOCGABS(ABS_Y), &info) < 0) | 79 | if(ioctl(fd, EVIOCGABS(ABS_Y), &info) < 0) |
79 | return -1; | 80 | return -1; |
80 | state->max_y = info.maximum; | 81 | ts_state.max_y = info.maximum; |
81 | if(ioctl(fd, EVIOCGABS(ABS_PRESSURE), &info) < 0) | 82 | if(ioctl(fd, EVIOCGABS(ABS_PRESSURE), &info) < 0) |
82 | return -1; | 83 | return -1; |
83 | state->max_pressure = info.maximum; | 84 | ts_state.max_pressure = info.maximum; |
84 | if(ioctl(fd, EVIOCGABS(ABS_TOOL_WIDTH), &info) < 0) | 85 | if(ioctl(fd, EVIOCGABS(ABS_TOOL_WIDTH), &info) < 0) |
85 | return -1; | 86 | return -1; |
86 | state->max_tool_width = info.maximum; | 87 | ts_state.max_tool_width = info.maximum; |
87 | touch_detect = false; | 88 | touch_detect = false; |
88 | return 0; | 89 | return 0; |
89 | } | 90 | } |
90 | 91 | ||
91 | void handle_touch(struct input_event *evt) | 92 | void handle_touch(struct input_event evt) |
92 | { | 93 | { |
93 | switch(evt->type) | 94 | switch(evt.type) |
94 | { | 95 | { |
95 | case EV_SYN: | 96 | case EV_SYN: |
96 | /* on SYN, we copy the state to the rockbox state */ | 97 | /* on SYN, we copy the state to the rockbox state */ |
97 | touch_x = ts_state->x; | 98 | touch_x = ts_state.x; |
98 | touch_y = ts_state->y; | 99 | touch_y = ts_state.y; |
99 | /* map coordinate to screen */ | 100 | /* map coordinate to screen */ |
100 | x = x * LCD_WIDTH / ts_state->max_x; | 101 | touch_x = touch_x * LCD_WIDTH / ts_state.max_x; |
101 | y = y * LCD_HEIGHT / ts_state->max_y; | 102 | touch_y = touch_y * LCD_HEIGHT / ts_state.max_y; |
102 | /* don't trust driver reported ranges */ | 103 | /* don't trust driver reported ranges */ |
103 | x = MAX(0, MIN(x, LCD_WIDTH - 1)); | 104 | touch_x = MAX(0, MIN(touch_x, LCD_WIDTH - 1)); |
104 | y = MAX(0, MIN(y, LCD_HEIGHT - 1)); | 105 | touch_y = MAX(0, MIN(touch_y, LCD_HEIGHT - 1)); |
105 | touch_detect = ts_state->touch; | 106 | touch_detect = ts_state.touch; |
106 | /* reset flick */ | 107 | /* reset flick */ |
107 | state->flick = false; | 108 | ts_state.flick = false; |
108 | break; | 109 | break; |
109 | case EV_REL: | 110 | case EV_REL: |
110 | if(evt->code == REL_RX) | 111 | if(evt.code == REL_RX) |
111 | state->flick_x = evt->value; | 112 | ts_state.flick_x = evt.value; |
112 | else if(evt->code == REL_RY) | 113 | else if(evt.code == REL_RY) |
113 | state->flick_y = evt->value; | 114 | ts_state.flick_y = evt.value; |
114 | else | 115 | else |
115 | break; | 116 | break; |
116 | state->flick = true; | 117 | ts_state.flick = true; |
117 | break; | 118 | break; |
118 | case EV_ABS: | 119 | case EV_ABS: |
119 | if(evt->code == ABS_X) | 120 | if(evt.code == ABS_X) |
120 | state->x = evt->value; | 121 | ts_state.x = evt.value; |
121 | else if(evt->code == ABS_Y) | 122 | else if(evt.code == ABS_Y) |
122 | state->y = evt->value; | 123 | ts_state.y = evt.value; |
123 | else if(evt->code == ABS_PRESSURE) | 124 | else if(evt.code == ABS_PRESSURE) |
124 | state->pressure = evt->value; | 125 | ts_state.pressure = evt.value; |
125 | else if(evt->code == ABS_TOOL_WIDTH) | 126 | else if(evt.code == ABS_TOOL_WIDTH) |
126 | state->tool_width = evt->value; | 127 | ts_state.tool_width = evt.value; |
127 | break; | 128 | break; |
128 | case EV_KEY: | 129 | case EV_KEY: |
129 | if(evt->code == BTN_TOUCH) | 130 | if(evt.code == BTN_TOUCH) |
130 | state->touch = evt->value; | 131 | ts_state.touch = evt.value; |
131 | break; | 132 | break; |
132 | default: | 133 | default: |
133 | break; | 134 | break; |
@@ -296,7 +297,8 @@ int button_read_device( | |||
296 | } | 297 | } |
297 | } | 298 | } |
298 | #ifdef HAVE_TOUCHSCREEN | 299 | #ifdef HAVE_TOUCHSCREEN |
299 | button_bitmap |= touchscreen_to_pixels(touch_x, touch_y, data); | 300 | if(touch_detect) |
301 | button_bitmap |= touchscreen_to_pixels(touch_x, touch_y, data); | ||
300 | #endif | 302 | #endif |
301 | return hold_status ? 0 : button_bitmap; | 303 | return hold_status ? 0 : button_bitmap; |
302 | } | 304 | } |