summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-12-01 18:25:42 +0000
committerAmaury Pouly <amaury.pouly@gmail.com>2014-09-08 11:21:54 +0200
commit8146b40e73bb999001787fbf414c96acf5dce2a8 (patch)
treee3a1b2f951fd439c71d82e387d04df10d926b4e9 /firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c
parent847106cdb20a0297dc9a10f212f0e3c8e6f3d58c (diff)
downloadrockbox-8146b40e73bb999001787fbf414c96acf5dce2a8.tar.gz
rockbox-8146b40e73bb999001787fbf414c96acf5dce2a8.zip
Fuze+: add a configurable deadzone area for touchpad buttons
To stop erroneous button presses, allow users to add a deadzone between the button via the Settings > General > System menu > Touch Dead Zone. The configuration was chosen this way: the touchpad has the same DPI in both direction so the setting applies the same on both the X and Y axis. The setting ranges from 0 to 100 and is internally multiplied by 2 giving a maximum deadzone of 2*100 = 200 around each button, which account for 400 total (once around each button), effectively reducing each virtual button from 1000x600 to 600x200 when using the maximum value. Change-Id: I8683c63d2950200eb32d1dda0a00bbd92d83d5be Reviewed-on: http://gerrit.rockbox.org/677 Reviewed-by: Benjamin Brown <foolshperson@gmail.com> Tested: Benjamin Brown <foolshperson@gmail.com> Reviewed-by: Amaury Pouly <amaury.pouly@gmail.com>
Diffstat (limited to 'firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c')
-rw-r--r--firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c66
1 files changed, 38 insertions, 28 deletions
diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c b/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c
index f4166d0c2c..ea4aa083e5 100644
--- a/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c
+++ b/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c
@@ -192,33 +192,22 @@ bool button_debug_screen(void)
192 return true; 192 return true;
193} 193}
194 194
195struct button_area_t 195/* we emulate a 3x3 grid, this gives the button mapping */
196int button_mapping[3][3] =
196{ 197{
197 /* define a rectangle region */ 198 {BUTTON_BOTTOMLEFT, BUTTON_LEFT, BUTTON_BACK},
198 int lx, ly; 199 {BUTTON_DOWN, BUTTON_SELECT, BUTTON_UP},
199 int rx, ry; 200 {BUTTON_BOTTOMRIGHT, BUTTON_RIGHT, BUTTON_PLAYPAUSE},
200 int button;
201};
202
203static struct button_area_t button_areas[] =
204{
205 {1003, 658, 2006, 1316, BUTTON_SELECT},
206 {0, 658, 1003, 1316, BUTTON_LEFT},
207 {2006, 658, 3009, 1316, BUTTON_RIGHT},
208 {1003, 0 , 2006, 658, BUTTON_DOWN},
209 {1003, 1316, 2006, 1974, BUTTON_UP},
210 {2006, 1316, 3009, 1974, BUTTON_PLAYPAUSE},
211 {0, 1316, 1003, 1974, BUTTON_BACK},
212 {0, 0 , 1003, 658, BUTTON_BOTTOMLEFT},
213 {2006, 0 , 3009, 658, BUTTON_BOTTOMRIGHT},
214 {0, 0, 0, 0, 0},
215}; 201};
216 202
217#define RMI_INTERRUPT 1 203#define RMI_INTERRUPT 1
218#define RMI_SET_SENSITIVITY 2 204#define RMI_SET_SENSITIVITY 2
219#define RMI_SET_SLEEP_MODE 3 205#define RMI_SET_SLEEP_MODE 3
220/* timeout before lowering touchpad power from lack of activity */ 206/* timeout before lowering touchpad power from lack of activity */
221#define ACTIVITY_TMO (5 * HZ) 207#define ACTIVITY_TMO (5 * HZ)
208#define TOUCHPAD_WIDTH 3010
209#define TOUCHPAD_HEIGHT 1975
210#define DEADZONE_MULTIPLIER 2 /* deadzone multiplier */
222 211
223static int touchpad_btns = 0; 212static int touchpad_btns = 0;
224static long rmi_stack [DEFAULT_STACK_SIZE/sizeof(long)]; 213static long rmi_stack [DEFAULT_STACK_SIZE/sizeof(long)];
@@ -226,17 +215,38 @@ static const char rmi_thread_name[] = "rmi";
226static struct event_queue rmi_queue; 215static struct event_queue rmi_queue;
227static unsigned last_activity = 0; 216static unsigned last_activity = 0;
228static bool t_enable = true; 217static bool t_enable = true;
218static int deadzone;
219
220/* Ignore deadzone function. If outside of the pad, project to border. */
221static int find_button_no_deadzone(int x, int y)
222{
223 /* compute grid coordinate */
224 int gx = MAX(MIN(x * 3 / TOUCHPAD_WIDTH, 2), 0);
225 int gy = MAX(MIN(y * 3 / TOUCHPAD_HEIGHT, 2), 0);
226
227 return button_mapping[gx][gy];
228}
229 229
230static int find_button(int x, int y) 230static int find_button(int x, int y)
231{ 231{
232 struct button_area_t *area = button_areas; 232 /* find button ignoring deadzones */
233 for(; area->button != 0; area++) 233 int btn = find_button_no_deadzone(x, y);
234 { 234 /* To check if we are in a deadzone, we try to shift the coordinates
235 if(area->lx <= x && x <= area->rx && 235 * and see if we get the same button. Not that we do not want to apply
236 area->ly <= y && y <= area->ry) 236 * the deadzone in the borders ! The code works even in the borders because
237 return area->button; 237 * the find_button_no_deadzone() project out-of-bound coordinates to the
238 } 238 * borders */
239 return 0; 239 if(find_button_no_deadzone(x + deadzone, y) != btn ||
240 find_button_no_deadzone(x - deadzone, y) != btn ||
241 find_button_no_deadzone(x, y + deadzone) != btn ||
242 find_button_no_deadzone(x, y - deadzone) != btn)
243 return 0;
244 return btn;
245}
246
247void touchpad_set_deadzone(int touchpad_deadzone)
248{
249 deadzone = touchpad_deadzone * DEADZONE_MULTIPLIER;
240} 250}
241 251
242static int touchpad_read_device(void) 252static int touchpad_read_device(void)