Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.content.browser; | |
| 6 | |
| 7 import android.view.KeyEvent; | |
| 8 | |
| 9 import org.chromium.content.browser.input.CanonicalAxisIndex; | |
| 10 import org.chromium.content.browser.input.CanonicalButtonIndex; | |
| 11 | |
| 12 /* | |
| 13 * Class to manage mapping information related to each supported gamepad controll er device. | |
| 14 */ | |
| 15 class GamepadMappings { | |
| 16 public static boolean mapToStandardGamepad(float[] mappedAxis, float[] mappe dButtons, | |
| 17 float[] rawAxes, float[] rawButto ns, | |
|
Ted C
2014/04/04 18:52:18
use java indenting
SaurabhK
2014/04/11 14:41:42
On 2014/04/04 18:52:18, Ted C wrote:
Done.
| |
| 18 String deviceName) { | |
| 19 boolean isMapped = true; | |
| 20 if (deviceName.contains("NVIDIA Corporation NVIDIA Controller")) { | |
| 21 mapShieldGamepad(mappedButtons, rawButtons, mappedAxis, rawAxes); | |
| 22 } | |
| 23 else if (deviceName.contains("Microsoft X-Box 360 pad")) { | |
| 24 mapXBox360Gamepad(mappedButtons, rawButtons, mappedAxis, rawAxes); | |
| 25 } | |
| 26 else { | |
|
Ted C
2014/04/04 18:52:18
needs to go on the line above with the }
SaurabhK
2014/04/11 14:41:42
On 2014/04/04 18:52:18, Ted C wrote:
Removed else
| |
| 27 mapUnkownGamepad(mappedButtons, rawButtons, mappedAxis, rawAxes); | |
| 28 isMapped = false; | |
| 29 } | |
| 30 return isMapped; | |
| 31 } | |
| 32 | |
| 33 private static void mapCommonButtons(float[] mappedButtons, float[] rawButto ns) { | |
| 34 mappedButtons[CanonicalButtonIndex.BUTTON_PRIMARY] = rawButtons[KeyEvent .KEYCODE_BUTTON_A]; | |
| 35 mappedButtons[CanonicalButtonIndex.BUTTON_SECONDARY] = | |
| 36 rawButtons[KeyEvent.KEYCODE_BUTTON_B]; | |
|
Ted C
2014/04/04 18:52:18
should be indented 8 from the start of the previou
SaurabhK
2014/04/11 14:41:42
On 2014/04/04 18:52:18, Ted C wrote:
Done.
| |
| 37 mappedButtons[CanonicalButtonIndex.BUTTON_TERTIARY] = | |
| 38 rawButtons[KeyEvent.KEYCODE_BUTTON_X]; | |
| 39 mappedButtons[CanonicalButtonIndex.BUTTON_QUATERNARY] = | |
| 40 rawButtons[KeyEvent.KEYCODE_BUTTON_Y]; | |
| 41 mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_SHOULDER] = | |
| 42 rawButtons[KeyEvent.KEYCODE_BUTTON_L1]; | |
| 43 mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_SHOULDER] = | |
| 44 rawButtons[KeyEvent.KEYCODE_BUTTON_R1]; | |
| 45 mappedButtons[CanonicalButtonIndex.BUTTON_BACK_SELECT] = | |
| 46 rawButtons[KeyEvent.KEYCODE_BUTTON_SELECT]; | |
| 47 mappedButtons[CanonicalButtonIndex.BUTTON_START] = | |
| 48 rawButtons[KeyEvent.KEYCODE_BUTTON_START]; | |
| 49 mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_THUMBSTICK] = | |
| 50 rawButtons[KeyEvent.KEYCODE_BUTTON_THUMBL]; | |
| 51 mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_THUMBSTICK] = | |
| 52 rawButtons[KeyEvent.KEYCODE_BUTTON_THUMBR]; | |
| 53 mappedButtons[CanonicalButtonIndex.BUTTON_META] = rawButtons[KeyEvent.KE YCODE_BUTTON_MODE]; | |
| 54 } | |
| 55 | |
| 56 private static void mapDpadButtonsToAxes(float[] mappedButtons, float[] rawA xes) { | |
| 57 // Negative value indicates dpad up. | |
| 58 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_UP] = negativeAxisValueAs Button(rawAxes[9]); | |
| 59 // Positive axis value indicates dpad down. | |
| 60 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_DOWN] = | |
| 61 positiveAxisValueAsButton(rawAxes[9]); | |
| 62 // Positive axis value indicates dpad right. | |
| 63 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_RIGHT] = | |
| 64 positiveAxisValueAsButton(rawAxes[8]); | |
| 65 // Negative value indicates dpad left. | |
| 66 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_LEFT] = | |
| 67 negativeAxisValueAsButton(rawAxes[8]); | |
| 68 } | |
| 69 | |
| 70 private static void mapAxes(float[] mappedAxis, float[] rawAxes) { | |
| 71 // Standard gamepad can have only four axes. | |
| 72 mappedAxis[CanonicalAxisIndex.AXIS_LEFT_STICK_X] = rawAxes[0]; | |
| 73 mappedAxis[CanonicalAxisIndex.AXIS_LEFT_STICK_Y] = rawAxes[1]; | |
| 74 mappedAxis[CanonicalAxisIndex.AXIS_RIGHT_STICK_X] = rawAxes[4]; | |
| 75 mappedAxis[CanonicalAxisIndex.AXIS_RIGHT_STICK_Y] = rawAxes[5]; | |
| 76 } | |
| 77 | |
| 78 private static float negativeAxisValueAsButton(float input) { | |
| 79 return (input < -0.5f) ? 1.f : 0.f; | |
| 80 } | |
| 81 | |
| 82 private static float positiveAxisValueAsButton(float input) { | |
| 83 return (input > 0.5f) ? 1.f : 0.f; | |
| 84 } | |
| 85 | |
| 86 /** | |
| 87 * Method for mapping Nvidia gamepad axis and button values | |
| 88 * to standard gamepad button and axes values. | |
| 89 */ | |
| 90 private static void mapShieldGamepad(float[] mappedButtons, float[] rawButto ns, | |
| 91 float[] mappedAxis, float[] rawAxes) { | |
| 92 mapCommonButtons(mappedButtons, rawButtons); | |
| 93 | |
| 94 mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_TRIGGER] = rawAxes[2]; // or rawAxes[3]; | |
| 95 mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_TRIGGER] = rawAxes[6]; / / or rawAxes[7]; | |
| 96 | |
| 97 mapDpadButtonsToAxes(mappedButtons, rawAxes); | |
| 98 mapAxes(mappedAxis, rawAxes); | |
| 99 } | |
| 100 | |
| 101 /** | |
| 102 * Method for mapping Microsoft XBox 360 gamepad axis and button values | |
| 103 * to standard gamepad button and axes values. | |
| 104 */ | |
| 105 private static void mapXBox360Gamepad(float[] mappedButtons, float[] rawButt ons, | |
| 106 float[] mappedAxis, float[] rawAxes) { | |
| 107 mapCommonButtons(mappedButtons, rawButtons); | |
| 108 | |
| 109 mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_TRIGGER] = rawAxes[2]; // or rawAxes[3]; | |
| 110 mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_TRIGGER] = rawAxes[6]; / / or rawAxes[7]; | |
| 111 | |
| 112 mapDpadButtonsToAxes(mappedButtons, rawAxes); | |
| 113 mapAxes(mappedAxis, rawAxes); | |
| 114 } | |
| 115 | |
| 116 /** | |
| 117 * Method for mapping Unkown gamepad axis and button values | |
| 118 * to standard gamepad button and axes values. | |
| 119 */ | |
| 120 private static void mapUnkownGamepad(float[] mappedButtons, float[] rawButto ns, | |
| 121 float[] mappedAxis, float[] rawAxes) { | |
| 122 mapCommonButtons(mappedButtons, rawButtons); | |
| 123 | |
| 124 mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_TRIGGER] = | |
| 125 rawButtons[KeyEvent.KEYCODE_BUTTON_L2]; | |
| 126 mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_TRIGGER] = | |
| 127 rawButtons[KeyEvent.KEYCODE_BUTTON_R2]; | |
| 128 | |
| 129 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_UP] = rawButtons[KeyEvent .KEYCODE_DPAD_UP]; | |
| 130 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_DOWN] = | |
| 131 rawButtons[KeyEvent.KEYCODE_DPAD_DOWN]; | |
| 132 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_RIGHT] = | |
| 133 rawButtons[KeyEvent.KEYCODE_DPAD_RIGHT]; | |
| 134 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_LEFT] = | |
| 135 rawButtons[KeyEvent.KEYCODE_DPAD_LEFT]; | |
| 136 | |
| 137 mapAxes(mappedAxis, rawAxes); | |
| 138 } | |
| 139 | |
| 140 } | |
| OLD | NEW |