Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* size of touchpad area, it will be evenly divided for the buttons */
- #define TOUCHPAD_WIDTH 3010
- #define TOUCHPAD_HEIGHT 1975
- #define DEADZONE_XMUL 50 /* x deadzone multiplier */
- #define DEADZONE_YMUL 40 /* y deadzone multiplier */
- /* we emulate a 3x3 grid, this gives the button mapping
- * WARNING: the y-axis is reversed ! */
- int button_mapping[3][3] =
- {
- {BUTTON_BOTTOMLEFT, BUTTON_DOWN, BUTTON_BOTTOMRIGHT},
- {BUTTON_LEFT, BUTTON_SELECT, BUTTON_RIGHT},
- {BUTTON_TOPLEFT, BUTTON_UP, BUTTON_TOPRIGHT},
- };
- int x_deadzone, y_deadzone;
- /* Ignore deadzone function */
- static int find_button_no_deadzone(int x, int y)
- {
- /* compute grid coordinate */
- int gx = x * 3 / TOUCHPAD_WIDTH;
- int gy = y * 3 / TOUCHPAD_HEIGHT;
- if(gx < 0 || gx >= 3 || gy < 0 || gy >= 3)
- return 0; /* something went wrong, these coordinates are useless */
- return button_mapping[gx][gy];
- }
- /* Ignore deadzone function */
- static int find_button(int x, int y)
- {
- /* compute grid coordinate */
- int gx = x * 3 / TOUCHPAD_WIDTH;
- int gy = y * 3 / TOUCHPAD_HEIGHT;
- /* find button ignoring deadzones */
- int btn = find_button_no_deadzone(x, y);
- if(btn == 0)
- return 0;
- /* to see if we are in a deadzone, we try to shift the coordinate
- * and see if we get the same button, however we do not want the
- * deadzone to apply on the borders, only between buttons ! */
- /* right deadzone: only if not in the last column */
- if(gx != 2 && find_button_no_deadzone(x + x_deadzone, y) != btn)
- return 0;
- /* left deadzone: only if not in the first column */
- if(gx != 0 && find_button_no_deadzone(x - x_deadzone, y) != btn)
- return 0;
- /* top deadzone: only if not in the first row */
- if(gy != 2 && find_button_no_deadzone(x, y + y_deadzone) != btn)
- return 0;
- /* bottom deadzone: only if not in the last row */
- if(gy != 0 && find_button_no_deadzone(x, y - y_deadzone) != btn)
- return 0;
- return btn;
- }
- void touchpad_set_deadzone(int deadzone)
- {
- x_deadzone = deadzone * DEADZONE_XMUL;
- y_deadzone = deadzone * DEADZONE_YMUL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement